How to use the curtsies.FullscreenWindow function in curtsies

To help you get started, we’ve selected a few curtsies examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bpython / curtsies / examples / demo_window.py View on Github external
a = [fmtstr(c*columns) for _ in range(1)]
                elif c == "c":
                    w.write(w.t.move(w.t.height-1, 0))
                    w.scroll_down()
                elif isinstance(c, events.WindowChangeEvent):
                    a = w.array_from_text("window just changed to %d rows and %d columns" % (c.rows, c.columns))
                elif c == '\x0c': # ctrl-L
                    [w.write('\n') for _ in range(rows)]
                    continue
                else:
                    a = w.array_from_text("unknown command")
                w.render_to_terminal(a)

if __name__ == '__main__':
    logging.basicConfig(filename='display.log',level=logging.DEBUG)
    array_size_test(FullscreenWindow(sys.stdout))
github bpython / curtsies / examples / quickstart.py View on Github external
from __future__ import unicode_literals # convenient for Python 2
import random

from curtsies import FullscreenWindow, Input, FSArray
from curtsies.fmtfuncs import red, bold, green, on_blue, yellow

print(yellow('this prints normally, not to the alternate screen'))
with FullscreenWindow() as window:
    with Input() as input_generator:
        msg = red(on_blue(bold('Press escape to exit')))
        a = FSArray(window.height, window.width)
        a[0:1, 0:msg.width] = [msg]
        window.render_to_terminal(a)
        for c in input_generator:
            if c == '':
                break
            elif c == '':
                a = FSArray(window.height, window.width)
            else:
                s = repr(c)
                row = random.choice(range(window.height))
                column = random.choice(range(window.width-len(s)))
                color = random.choice([red, green, on_blue, yellow])
                a[row, column:column+len(s)] = [color(s)]
github bpython / curtsies / examples / demo_fullscreen_with_input.py View on Github external
def fullscreen_winch_with_input():
    print('this should be just off-screen')
    w = FullscreenWindow(sys.stdout)
    def sigwinch_handler(signum, frame):
        print('sigwinch! Changed from %r to %r' % ((rows, columns), (w.height, w.width)))
    signal.signal(signal.SIGWINCH, sigwinch_handler)
    with w:
        with Cbreak(sys.stdin):
            for e in input.Input():
                rows, columns = w.height, w.width
                a = [fmtstr((('.%sx%s.%r.' % (rows, columns, e)) * rows)[:columns]) for row in range(rows)]
                w.render_to_terminal(a)
github bpython / curtsies / examples / gameexample.py View on Github external
def main():
    with FullscreenWindow(sys.stdout) as window:
        with Input(sys.stdin) as input_generator:
            world = World(width=window.width, height=window.height)
            window.render_to_terminal(world.get_array())
            for c in input_generator:
                msg = world.process_event(c)
                if msg:
                    break
                window.render_to_terminal(world.get_array())
    print(msg)
github recursecenter / terminal_snake / snake.py View on Github external
def main():
    counter = FrameCounter()
    with FullscreenWindow() as window:
        print('Press escape to exit')
        game = SnakeGame(window.height, window.width)
        with Input() as input_generator:
            c = None
            last_c = ''
            for framenum in itertools.count(0):
                t0 = time.time()
                while True:
                    t = time.time()
                    temp_c = input_generator.send(max(0, t - (t0 + time_per_frame)))                    
                    if temp_c is not None:
                        c = temp_c
                    if c is None:
                        pass
                    elif c == '':
                        return
github bpython / curtsies / examples / tttplaybitboard.py View on Github external
try:
        if len(argv) == 1:
            pass
        elif len(argv) == 2:
            faceoff[1] = pool[argv[1]]
        elif len(argv) == 3:
            faceoff = [pool[argv[1]], pool[argv[2]]]
        else:
            raise KeyError
    except KeyError:
        print("Usage: %s [player] [player]" % argv[0])
        print("where a player is one of:", ', '.join(sorted(pool)))
        return 1
    else:
        with Input() as i:
            with FullscreenWindow() as w:
                tictactoe(w, i, *faceoff)
        return 0
github ianmiell / shutit / shutit_global.py View on Github external
def refresh_window(self):
		self.window               = curtsies.FullscreenWindow(hide_cursor=True)
		self.wheight              = self.window.height
		self.wwidth               = self.window.width
		self.screen_arr           = None
		# Divide the screen up into two, to keep it simple for now
		self.wheight_top_end      = int(self.wheight / 2)
		self.wheight_bottom_start = int(self.wheight / 2)
		self.wwidth_left_end      = int(self.wwidth / 2)
		self.wwidth_right_start   = int(self.wwidth / 2)
		assert self.wheight >= 24, 'Terminal not tall enough: ' + str(self.wheight) + ' < 24'
		assert self.wwidth >= 80, 'Terminal not wide enough: ' + str(self.wwidth) + ' < 80'
github bpython / curtsies / examples / chat.py View on Github external
def main(host, port):
    client = socket.socket()
    client.connect((host, port))
    client.setblocking(False)

    conn = Connection(client)
    keypresses = []

    with FullscreenWindow() as window:
        with Input() as input_generator:
            while True:
                a = FSArray(10, 80)
                in_text = ''.join(keypresses)[:80]
                a[9:10, 0:len(in_text)] = [red(in_text)]
                for i, line in zip(reversed(range(2,7)), reversed(conn.render())):
                    a[i:i+1, 0:len(line)] = [line]
                text = 'connected to %s:%d' % (host if len(host) < 50 else host[:50]+'...', port)
                a[0:1, 0:len(text)] = [blue(text)]

                window.render_to_terminal(a)
                ready_to_read, _, _ = select.select([conn, input_generator], [], [])
                for r in ready_to_read:
                    if r is conn:
                        r.on_read()
                    else:
github bpython / curtsies / examples / realtime.py View on Github external
def main():
    counter = FrameCounter()
    with FullscreenWindow() as window:
        print('Press escape to exit')
        with Input() as input_generator:
            a = FSArray(window.height, window.width)
            c = None
            for framenum in itertools.count(0):
                t0 = time.time()
                while True:
                    t = time.time()

                    temp_c = input_generator.send(max(0, t - (t0 + time_per_frame)))
                    if temp_c is not None:
                        c = temp_c

                    if c is None:
                        pass
                    elif c == '':