]> git.armaanb.net Git - lightcards.git/blob - lightcards/display.py
Add setup.py, and make into actual Python module
[lightcards.git] / lightcards / display.py
1 # Display card output and retreive input
2 # Armaan Bhojwani 2021
3
4 import os
5
6 class Status():
7     index = 0
8     side = 0
9
10     def forward(self, stack):
11         if not self.index == len(stack) - 1:
12             self.index += 1
13
14     def back(self):
15         if not self.index < 1:
16             self.index -= 1
17
18     def flip(self):
19         if self.side == 0:
20             self.side = 1
21         else:
22             self.side = 0
23
24     def setSide(self, inp):
25         self.side = inp
26
27     def getSide(self):
28         return self.side
29
30     def getIdx(self):
31         return self.index
32
33
34 def disp_card(stdscr, stack, obj):
35     stdscr.clear()
36     stdscr.addstr(str(stack[obj.getIdx()][obj.getSide()]))
37
38 def get_key(stdscr, stack):
39     idx = Status()
40     disp_card(stdscr, stack, idx)
41
42     while True:
43         key = stdscr.getkey()
44         try:
45             if key == "q" or key == os.linesep:
46                 exit(0)
47             if key == "j":
48                 idx.forward(stack)
49                 idx.setSide(0)
50                 disp_card(stdscr, stack, idx)
51             if key == "k":
52                 idx.back()
53                 idx.setSide(0)
54                 disp_card(stdscr, stack, idx)
55             if key == "l" or key == "h":
56                 idx.flip()
57                 disp_card(stdscr, stack, idx)
58         except Exception:
59             pass