summaryrefslogtreecommitdiffstats
path: root/tools/debug_vt100_input.py
blob: d3660b9a3789ec85fa2df1fa75c529563d3a8612 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
"""
Parse vt100 input and print keys.
For testing terminal input.

(This does not use the `Input` implementation, but only the `Vt100Parser`.)
"""
import sys

from prompt_toolkit.input.vt100 import raw_mode
from prompt_toolkit.input.vt100_parser import Vt100Parser
from prompt_toolkit.keys import Keys


def callback(key_press):
    print(key_press)

    if key_press.key == Keys.ControlC:
        sys.exit(0)


def main():
    stream = Vt100Parser(callback)

    with raw_mode(sys.stdin.fileno()):
        while True:
            c = sys.stdin.read(1)
            stream.feed(c)


if __name__ == "__main__":
    main()