示例#1
0
from pytermfx import Terminal, NamedColor
from pytermfx.tools import draw_progress
from time import sleep

t = Terminal()


def main():
    example_1()
    t.writeln()
    example_2()
    t.writeln()
    example_3()
    t.writeln()
    t.flush()


def example_1():
    color = NamedColor("green")
    progress = 0
    while progress < 1:
        progress += 0.0237
        draw_progress(t,
                      progress,
                      color=color,
                      bar_left=30,
                      label="Spooling up progress bars...")
        sleep(1 / 10)


def example_2():
示例#2
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=", ")
示例#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
def main():
    t = Terminal()
    t.cursor_set_visible(False)

    # the beautiful art
    art = [
        "DDDDDDDDDVVVVVV        VVVVDDDDDDDDDD   ",
        "DDDDDDDDDDDVVVVV      VVVVVDDDDDDDDDDDD ",
        "        DDDD VVVV    VVVV           DDDD",
        "DDD      DDD  VVVV  VVVV    DDD      DDD",
        "DDD     DDDD   VVVVVVVV     DDD     DDDD",
        "DDDDDDDDDDD     VVVVVV      DDDDDDDDDDD ",
        "DDDDDDDDD        VVVV       DDDDDDDDD   ",
        "                  VV                    "
    ]
    aw = len(art[0])
    ah = len(art)
    pos = [t.w / 2, t.h / 2]
    vel = [1.12 / 2, 0.67 / 2]

    t.style(Color.hex(0x0000FF))
    t.style(Color.hex(0x000000).bg())
    t.style(Style("bold"))
    t.flush()

    def changecol():
        colors = (Color.hex(0x0000FF), Color.hex(0xFFFF00),
                  Color.hex(0x7700FF), Color.hex(0xFF0077),
                  Color.hex(0xFF7700))
        t.style(random.choice(colors))

    def update():
        t.clear_box(pos[0] - aw / 2, pos[1] - ah / 2, aw, ah)

        # integrate velocity
        pos[0] += vel[0]
        pos[1] += vel[1]

        # ugly bounce physics
        if pos[0] < aw / 2:
            pos[0] = aw / 2
            vel[0] = -vel[0]
            changecol()
        if pos[1] < ah / 2 + 1:
            pos[1] = ah / 2 + 1
            vel[1] = -vel[1]
            changecol()
        if pos[0] > t.w - 1 - aw / 2:
            pos[0] = t.w - 1 - aw / 2
            vel[0] = -vel[0]
            changecol()
        if pos[1] > t.h - 1 - ah / 2:
            pos[1] = t.h - 1 - ah / 2
            vel[1] = -vel[1]
            changecol()

        # update console
        draw_art(t, art, pos[0], pos[1])
        t.flush()

    def on_input(c):
        if c == "q":
            app.stop()

    app = TerminalApp(t, 60, update=update, on_input=on_input)
    app.start()
示例#5
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()
示例#6
0
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 
示例#7
0
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):
示例#8
0
from pytermfx import Terminal, Color
import sys

t = Terminal()

i = 0
PERIOD = 500
for line in sys.stdin:
    for char in line:
        i += 1
        t.style(Color.hsl(i / PERIOD, 1.0, 0.6))
        t.write(char)
    t.flush()
示例#9
0
from pytermfx import Terminal

t = Terminal()
t.set_cbreak(True)
t.mouse_enable("move")

try:
    while True:
        c = t.getch()
        t.writeln(repr(c)).flush()
except KeyboardInterrupt:
    pass
finally:
    t.reset()
示例#10
0
from pytermfx import Terminal, Color, ColorMode
from pytermfx.keys import MouseEvent
from pytermfx.tools import TerminalApp
from math import sqrt, sin
from random import random

t = Terminal()
t.set_color_mode(ColorMode.MODE_256)
t.set_cbreak(True)
t.cursor_set_visible(False)
t.mouse_enable("move")
radius = 5 
flow = 0.5
buffer = None
damage = None
mouse = None

def clip(x, lo, hi):
    return max(lo, min(hi, x))

def resize():
	global buffer, damage, t
	buffer = [0 for i in range(t.w * t.h)]
	damage = [True for i in range(t.w * t.h)]
	t.style(Color.hex(0).bg()).clear_box(0, 0, t.w, t.h)
	t.flush()
t.add_resize_handler(resize)
resize()

def spray(cur_x, cur_y, intensity):
	global buffer, damage
示例#11
0
def main():
    t = Terminal()

    def update(s):
        t.style_reset()
        t.clear_line()
        fmt = ""
        try:
            col, fmt = parse_color(s)
            t.style(Color.rgb(col[0], col[1], col[2]).bg())
            t.write(" " * SWATCH_WIDTH)
            t.style_reset()
            t.write(" ")
        except ColorParseError:
            t.write(">" * SWATCH_WIDTH, " ")
        finally:
            t.cursor_save()
            t.style(Color.hex(0x909090))
            t.cursor_move(0, 1).clear_to_end().write(fmt)
            t.cursor_restore().style_reset()
            t.write(s)

    with t.managed():
        t.set_cbreak(True)

        # make space
        t.writeln()
        t.cursor_move(0, -1).flush()

        try:
            # read and parse color
            col_str = read_line(t, update)
            col, fmt = parse_color(col_str)

            t.writeln().writeln()

            # write converted colors
            formats = (("RGBA", format_rgba(col)), ("RGBA (hex)",
                                                    format_hex_rgba(col)),
                       ("RGB (hex)", format_hex_rgb(col)))
            format_name_width = max((len(f[0]) for f in formats)) + 2
            for name, value in formats:
                padding = format_name_width - (len(name) + 1)
                t.style(Color.hex(0x909090)).write(name, ":", " " * padding)
                t.style_reset().writeln(value)
            t.flush()
        except ColorParseError:
            t.writeln().writeln()
            t.writeln("Not a color.")
示例#12
0
from pytermfx import Terminal, Color, Style
from pytermfx.tools import TerminalApp
from pytermfx.keys import MouseEvent
import random
import math

mouse_x = 0
mouse_y = 0
mouse_px = 0
mouse_py = 0
particles = []
t = Terminal()
t.cursor_set_visible(False)
t.set_cbreak(True)
t.mouse_enable("move")
t.style(Color.hex(0)).clear()


class Particle:
    def __init__(self, x, y, vx=0, vy=0):
        self.x = x
        self.y = y
        self.vx = vx
        self.vy = vy

    def update(self):
        self.x += self.vx
        self.y += self.vy
        self.vy += 0.1

示例#13
0
from pytermfx import Terminal, Color
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()
示例#14
0
from pytermfx import Terminal
import pytermfx.md as md
import sys

t = Terminal()

md.render(t, sys.stdin.readlines())
t.flush()
示例#15
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()
示例#16
0
from pytermfx import Terminal, NamedColor, Style
from pytermfx.tools import read_line
import os

if __name__ == "__main__":
    t = Terminal()

    def update(s):
        for i, word in enumerate(s.split(" ")):
            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()
示例#17
0
from pytermfx import Terminal, Color, NamedColor, Style
from pytermfx.tools import TerminalApp

t = Terminal()
t.cursor_set_visible(False)
MAX = 100
STEP = 2
scale = 0.05
off_x = 0
off_y = 0


def mandelbrot(i, j, maxiter):
    real = i
    imag = j
    for n in range(maxiter):
        real2 = real * real
        imag2 = imag * imag
        if real2 + imag2 > 4.0:
            return n
        imag = 2 * real * imag + j
        real = real2 - imag2 + i
    return 0


def color(f):
    return Color.hsl(f / MAX, 1.0, 0.5).bg()


def update():
    # draw mandelbrot