File: keyboard_arrow_paint.py

package info (click to toggle)
python-blessed 1.25-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,812 kB
  • sloc: python: 14,645; makefile: 13; sh: 7
file content (27 lines) | stat: -rwxr-xr-x 879 bytes parent folder | download
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
#!/usr/bin/env python3
from blessed import Terminal

header_msg = "Press arrow keys (or 'q' to quit): "
term = Terminal()
position = [term.height // 2, term.width // 2]
with term.cbreak(), term.fullscreen(), term.hidden_cursor():
    print(term.home + header_msg + term.clear_eos)

    while True:
        # show arrow-controlled block
        print(term.move_yx(*position) + '█', end='', flush=True)

        # get key,
        key = term.inkey()

        # take action,
        if key == 'q':
            break
        if key.name == 'KEY_UP':
            position[0] = max(0, position[0] - 1)
        elif key.name == 'KEY_LEFT':
            position[1] = max(0, position[1] - 1)
        elif key.name == 'KEY_DOWN':
            position[0] = min(term.height, position[0] + 1)
        elif key.name == 'KEY_RIGHT':
            position[1] = min(term.width, position[1] + 1)