Esempio n. 1
0
def cursor_winch():
    """
    Reports (signals) change in window dimensions; reports change in position
    of cursor
    """
    global rows, columns  # instead of closure for Python 2 compatibility
    print('this should be just off-screen')
    w = CursorAwareWindow(sys.stdout,
                          sys.stdin,
                          keep_last_line=False,
                          hide_cursor=False)

    def sigwinch_handler(signum, frame):
        global rows, columns
        dy = w.get_cursor_vertical_diff()
        old_rows, old_columns = rows, columns
        rows, columns = w.height, w.width
        print('sigwinch! Changed from {!r} to {!r}'.format(
            (old_rows, old_columns), (rows, columns)))
        print('cursor moved %d lines down' % dy)
        w.write(w.t.move_up)
        w.write(w.t.move_up)

    signal.signal(signal.SIGWINCH, sigwinch_handler)
    with w:
        for e in input.Input():
            rows, columns = w.height, w.width
            a = [
                fmtstr(((f'.{rows}x{columns}.') * rows)[:columns])
                for row in range(rows)
            ]
            w.render_to_terminal(a)
            if e == '<ESC>':
                break
def fullscreen_winch_with_input():
    """
    Monitors user input as well as screen size and acknowledges changes to both.
    """
    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)

                if e == u'<ESC>':
                    break
Esempio n. 3
0
def cursor_winch():
    global rows, columns
    print('this should be just off-screen')
    w = CursorAwareWindow(sys.stdout, sys.stdin, keep_last_line=True, hide_cursor=False)
    def sigwinch_handler(signum, frame):
        global rows, columns
        dy = w.get_cursor_vertical_diff()
        old_rows, old_columns = rows, columns
        rows, columns = w.height, w.width
        print('sigwinch! Changed from %r to %r' % ((old_rows, old_columns), (rows, columns)))
        print('cursor moved %d lines down' % dy)
        w.write(w.t.move_up)
        w.write(w.t.move_up)
    signal.signal(signal.SIGWINCH, sigwinch_handler)
    with w:
        for e in input.Input():
            rows, columns = w.height, w.width
            a = [fmtstr((('.%sx%s.' % (rows, columns)) * rows)[:columns]) for row in range(rows)]
            w.render_to_terminal(a)
Esempio n. 4
0
def array_size_test(window):
    """Tests arrays one row too small or too large"""
    with window as w:
        print(
            'a displays a screen worth of input, s one line less, and d one line more'
        )
        with input.Input(sys.stdin) as input_generator:
            while True:
                c = input_generator.next()
                rows, columns = w.height, w.width
                if c == "":
                    sys.exit()  # same as raise SystemExit()
                elif c == "h":
                    a = w.array_from_text("a for small array")
                elif c == "a":
                    a = [fmtstr(c * columns) for _ in range(rows)]
                elif c == "s":
                    a = [fmtstr(c * columns) for _ in range(rows - 1)]
                elif c == "d":
                    a = [fmtstr(c * columns) for _ in range(rows + 1)]
                elif c == "f":
                    a = [fmtstr(c * columns) for _ in range(rows - 2)]
                elif c == "q":
                    a = [fmtstr(c * columns) for _ in range(1)]
                elif c == "w":
                    a = [fmtstr(c * columns) for _ in range(1)]
                elif c == "e":
                    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 == u'<ESC>':  # allows exit without keyboard interrupt
                    break
                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)