示例#1
0
            except:
                pass
            t.write(word).style_reset()

    def autocomplete(word):
        d = os.listdir(os.getcwd())
        matches = [w for w in d if w.startswith(word)]
        return matches[0] if len(matches) > 0 else None

    with t.managed():
        t.print("REPL demo -- a really dumb shell")
        t.print("Filenames in CWD are autocompleted.")
        while True:
            # render prompt
            t.style(NamedColor("yellow"))
            t.write("dumbsh> ")
            t.style_reset().flush()

            # read
            s = read_line(t, update, autocomplete)

            # 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
示例#2
0
from pytermfx import Terminal, Style
import sys

t = Terminal()
black = Style.none
white = Style("reverse")

i = 0
for line in sys.stdin:
    for char in line:
        i += 1
        if i % 2 == 0:
            t.style(black)
        else:
            t.style(white)
        t.write(char)
    t.flush()
示例#3
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)
示例#4
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()