]> git.armaanb.net Git - lightcards.git/blob - src/display.py
Switch to curses
[lightcards.git] / src / display.py
1 # Display card output and retreive input
2 # Armaan Bhojwani 2021
3
4 import os
5
6 def disp_card(stdscr, stack, idx, side):
7     stdscr.clear()
8     stdscr.addstr(str(stack[idx][side]))
9
10 def get_key(stdscr, stack):
11     idx = 0
12     side = 0
13     while True:
14         key = stdscr.getkey()
15
16         try:
17             if key == "q" or key == os.linesep:
18                 exit(0)
19             if key == "l":
20                 idx += 1
21                 disp_card(stdscr, stack, idx, 0)
22             if key == "h":
23                 idx -= 1
24                 side = 0
25                 disp_card(stdscr, stack, idx, 0)
26             if key == "k":
27                 if side == 0:
28                     side = 1
29                 else:
30                     side = 0
31                 disp_card(stdscr, stack, idx, side)
32         except Exception:
33             pass