from pytermfx import Terminal, Color, Style from pytermfx.keys import MouseEvent from time import clock BASE_SIZE = 4 MAX_SIZE = BASE_SIZE * 3 old_x = 0 old_y = 0 t = Terminal() t.set_cbreak(True) t.mouse_enable("move") t.cursor_set_visible(False) t.clear().flush() try: while True: t.style(Style.none) t.cursor_to(0,0) t.writeln("Hover over terminal") t.writeln("Press Q to quit") t.flush() c = t.getch() if isinstance(c, MouseEvent): if c.down: size = BASE_SIZE * 3 elif c.left or c.right: size = BASE_SIZE * 2 else: size = BASE_SIZE
# 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()
from pytermfx import Terminal, Color from pytermfx.tools import TerminalApp from random import random, randint, choice from time import sleep MAX_STEPS = 800 N = 5 TURN_CHANCE = 0.08 CHARS = list("║═╚╝╔╗") # CHARS = list("│─╰╯╭╮") t = Terminal() t.cursor_set_visible(False) t.add_resize_handler(lambda: t.clear().flush()) i = MAX_STEPS pipes = [] # choose a connector to use for a given direction def connector(vx0, vy0, vx1, vy1): if vx0 < vx1: if vy0 < vy1: return CHARS[4] return CHARS[2] elif vy0 < vy1: return CHARS[5] return CHARS[3] class Pipe: def __init__(self, x, y, color):