# Display card output and retreive input
# Armaan Bhojwani 2021
+import curses
import os
-class Status():
- index = 0
- side = 0
-
- def forward(self, stack):
- if not self.index == len(stack) - 1:
- self.index += 1
-
- def back(self):
- if not self.index < 1:
- self.index -= 1
-
- def flip(self):
- if self.side == 0:
- self.side = 1
- else:
- self.side = 0
-
- def setSide(self, inp):
- self.side = inp
-
- def getSide(self):
- return self.side
-
- def getIdx(self):
- return self.index
+from .deck import Status
def disp_card(stdscr, stack, headers, obj):
stdscr.addstr("=")
stdscr.addstr("\n" + str(stack[obj.getIdx()][obj.getSide()]))
+ (mlines, mcols) = stdscr.getmaxyx()
+ mlines -= 1
+ mcols -= 5
+
+ try:
+ stdscr.insch(mlines, mcols, str(obj.getIdx() + 1))
+ stdscr.insch(mlines, mcols+1, '-')
+ if obj.getSide() == 0:
+ stdscr.insch(mlines, mcols+2, '1')
+ else:
+ stdscr.insch(mlines, mcols+2, '2')
+ stdscr.insch(mlines, mcols+3, '/')
+ stdscr.insch(mlines, mcols+4, str(len(stack)))
+ stdscr.insstr(mlines, 1, stack[obj.getIdx()].getStar())
+ except Exception:
+ pass
+
+
def get_key(stdscr, stack, headers):
idx = Status()
+ curses.curs_set(0)
disp_card(stdscr, stack, headers, idx)
while True:
try:
if key == "q" or key == os.linesep:
exit(0)
- if key == "j":
+ elif key in ["l", "KEY_LEFT"]:
idx.forward(stack)
idx.setSide(0)
disp_card(stdscr, stack, headers, idx)
- if key == "k":
+ elif key in ["h", "KEY_RIGHT"]:
idx.back()
idx.setSide(0)
disp_card(stdscr, stack, headers, idx)
- if key == "l" or key == "h":
+ elif key in ["j", "k", "KEY_UP", "KEY_DOWN"]:
idx.flip()
disp_card(stdscr, stack, headers, idx)
+ elif key in ["i", "/"]:
+ stack[idx.getIdx()].toggleStar()
+ disp_card(stdscr, stack, headers, idx)
except Exception:
pass