]> git.armaanb.net Git - lightcards.git/blob - lightcards/display.py
Update status bar
[lightcards.git] / lightcards / display.py
1 # Display card output and retreive input
2 # Armaan Bhojwani 2021
3
4 import curses
5 import os
6
7 from .deck import Status
8
9
10 def disp_card(stdscr, stack, headers, obj):
11     stdscr.clear()
12     side_title = headers[obj.getSide()]
13     stdscr.addstr(side_title + "\n")
14     for i in range(len(side_title)):
15         stdscr.addstr("=")
16     stdscr.addstr("\n" + str(stack[obj.getIdx()][obj.getSide()]))
17
18     (mlines, mcols) = stdscr.getmaxyx()
19     try:
20         stdscr.insstr(mlines - 1, 1,
21                       "[" +
22                       stack[obj.getIdx()].getStar() +
23                       "] [" +
24                       str(round(obj.getIdx() / (len(stack) - 1) * 100)).zfill(3) +
25                       "% (" +
26                       str(obj.getIdx() + 1) +
27                       "/" +
28                       str(len(stack)) +
29                       ")]" +
30                       " [" +
31                       headers[obj.getSide()] +
32                       "]")
33     except Exception:
34         pass
35
36
37 def get_key(stdscr, stack, headers):
38     idx = Status()
39     curses.curs_set(0)
40     disp_card(stdscr, stack, headers, idx)
41
42     while True:
43         key = stdscr.getkey()
44         try:
45             if key == "q" or key == os.linesep:
46                 exit(0)
47             elif key in ["l", "KEY_LEFT"]:
48                 idx.forward(stack)
49                 idx.setSide(0)
50                 disp_card(stdscr, stack, headers, idx)
51             elif key in ["h", "KEY_RIGHT"]:
52                 idx.back()
53                 idx.setSide(0)
54                 disp_card(stdscr, stack, headers,  idx)
55             elif key in ["j", "k", "KEY_UP", "KEY_DOWN"]:
56                 idx.flip()
57                 disp_card(stdscr, stack, headers, idx)
58             elif key in ["i", "/"]:
59                 stack[idx.getIdx()].toggleStar()
60                 disp_card(stdscr, stack, headers, idx)
61         except Exception:
62             pass