Ejemplo n.º 1
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.")
Ejemplo n.º 2
0
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 

			t.style(Style.none)
			t.clear_box(old_x - MAX_SIZE // 2, old_y - MAX_SIZE // 4, MAX_SIZE, MAX_SIZE // 2)
			
Ejemplo n.º 3
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()
Ejemplo n.º 4
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()