File: initial_input_with_cursor.py

package info (click to toggle)
python-curtsies 0.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 420 kB
  • sloc: python: 4,021; sh: 6; makefile: 5
file content (21 lines) | stat: -rw-r--r-- 646 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import time

from curtsies import *

def main():
    """Ideally we shouldn't lose the first second of events"""
    with Input() as input_generator:
        def extra_bytes_callback(string):
            print('got extra bytes', repr(string))
            print('type:', type(string))
            input_generator.unget_bytes(string)
        time.sleep(1)
        with CursorAwareWindow(extra_bytes_callback=extra_bytes_callback) as window:
            window.get_cursor_position()
            for e in input_generator:
                print(repr(e))
                if e == '<ESC>':
                    break

if __name__ == '__main__':
    main()