Exemple #1
0
from pytermfx import Terminal

if __name__ == "__main__":
    t = Terminal()
    t.set_cbreak(True)
    t.mouse_enable("move")

    with t.managed():
        while True:
            s = t.getch_raw()
            codes = [ord(c) for c in s]
            t.print(*codes, sep=", ")
Exemple #2
0
            if i > 0:
                t.write(" ")
            try:
                int(word)
                t.style(NamedColor("red"))
            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":
Exemple #3
0
from pytermfx import Terminal, Color

t = Terminal()
t.clear()
adaptor_name = type(t.adaptor).__name__
t.print("Terminal (", adaptor_name, ") ", t.w, "x", t.h, sep="")
t.style(Color.hex(0xFF51C0))
t.print("Hello world in red!")
t.reset()