From: Armaan Bhojwani Date: Sat, 30 Jan 2021 22:12:57 +0000 (-0500) Subject: Add status class X-Git-Tag: v0.1.0~21 X-Git-Url: https://git.armaanb.net/?p=lightcards.git;a=commitdiff_plain;h=5962eee67b6585fb1fc3d3ce02aad24166edf12f Add status class --- diff --git a/src/display.py b/src/display.py index 0ed7863..988270b 100755 --- a/src/display.py +++ b/src/display.py @@ -3,31 +3,57 @@ import os -def disp_card(stdscr, stack, idx, side): +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 + + +def disp_card(stdscr, stack, obj): stdscr.clear() - stdscr.addstr(str(stack[idx][side])) + stdscr.addstr(str(stack[obj.getIdx()][obj.getSide()])) def get_key(stdscr, stack): - idx = 0 - side = 0 + idx = Status() + disp_card(stdscr, stack, idx) + while True: key = stdscr.getkey() - try: if key == "q" or key == os.linesep: exit(0) - if key == "l": - idx += 1 - disp_card(stdscr, stack, idx, 0) - if key == "h": - idx -= 1 - side = 0 - disp_card(stdscr, stack, idx, 0) + if key == "j": + idx.forward(stack) + idx.setSide(0) + disp_card(stdscr, stack, idx) if key == "k": - if side == 0: - side = 1 - else: - side = 0 - disp_card(stdscr, stack, idx, side) + idx.back() + idx.setSide(0) + disp_card(stdscr, stack, idx) + if key == "l" or key == "h": + idx.flip() + disp_card(stdscr, stack, idx) except Exception: pass