Beispiel #1
0
from pytermfx import Terminal
import time

t = Terminal()

for i in range(10):
	x, y = t.cursor_get_pos()
	t.cursor_to(x, y + 1)
	t.write(i)
	t.flush()
	time.sleep(0.2)
Beispiel #2
0
            # eval
            if s == "help":
                # show available commands
                t.print("commands: help, ls, cd, pwd, clear, exit")
            elif s == "ls":
                # list directory contents
                files = os.listdir(os.getcwd())
                t.print(*sorted(files), sep=" ")
            elif s == "pwd":
                # print working directory
                t.print(os.getcwd())
            elif s.startswith("cd"):
                # change working directory
                parts = s.split(" ")
                if len(parts) > 1:
                    path = parts[1]
                    os.chdir(path)
            elif s == "clear":
                # clear the screen
                t.clear()
                t.cursor_to(0, 0)
            elif s == "exit":
                # exit program
                break
            else:
                # echo input
                t.style(Style("italic"))
                t.print(s)
                t.style_reset()
Beispiel #3
0
from pytermfx.keys import MouseEvent
from time import clock

t = Terminal()
t.set_cbreak(True)
t.mouse_enable("move")
t.cursor_set_visible(False)
t.writeln("Left+drag to draw, Right+drag to erase.")
t.writeln("Press C to clear, Q to quit.")
t.flush()

try:
	while True:
		c = t.getch()
		if isinstance(c, MouseEvent):
			if c.left:
				t.cursor_to(c.x, c.y)
				t.style(Color.hsl(clock(), 1, 0.7).bg())
				t.write(" ").flush()
			elif c.right:
				t.style_reset()
				t.clear_box(c.x - 3, c.y - 1, 6, 3).flush()
		elif c == "c":
			t.style_reset().clear().flush()
		elif c == "q":
			break
except KeyboardInterrupt:
	pass
finally:
	t.reset()