bonk/scrolldown.py

81 lines
1.5 KiB
Python
Raw Permalink Normal View History

#!/usr/bin/python3
# -*- coding: utf-8 -*-
""" Ein hilfloser Versuch, Tasteneingaben abzufragen. Man kann auch in Python C schreiben. Ein Thread wär evtl besser. """
import os, sys, termios, tty, time
esc = chr(27)
bracket = chr(91)
c_up = chr(65)
c_down = chr(66)
c_right = chr(67)
c_left = chr(68)
x, xold, y, yold = 15, 15, 15, 15
clear = "'\x1b[2J\x1b[H"
replstring = " "
def curpos(x, y):
print("\033[%d;%dH" % (y, x), end="", flush=True)
def cursoroff():
sys.stdout.write("\033[?25l")
def cursoron():
sys.stdout.write("\033[?25h")
termsize_xy = os.get_terminal_size()
frame = 0
xmax = termsize_xy[0] - frame
ymax = termsize_xy[1] - frame
ymin = 1 + frame
xmin = 1 + frame
street = "# #"
pi=3.1416
deg2rad=pi/180
print(clear)
cursoroff()
taste = ""
while taste != "q":
# taste = ""
# while taste == "":
taste = getkey()
if taste == esc:
taste = getkey()
if taste == bracket:
taste = getkey()
yold = y
xold = x
if taste == c_right:
if x < xmax and y < ymax:
x += 1
elif taste == c_left:
if x > xmin:
x -= 1
curpos(xold, yold)
print(replstring, end="")
curpos(x, y)
print(car, end="")
curpos(1, 1)
print("x = ", x, " \ny = ", y, " ")
curpos(1, 3)
print("xold = ", xold, " \nyold = ", yold, " ")
curpos(ymax, 10)
print (street)
cursoron()
sys.exit("Schulz nun.")