Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import curses, json
- def main():
- boards = {}
- cur_board = ""
- stdscr = curses.initscr()
- seq = 0
- rows, cols = stdscr.getmaxyx()
- init_text = "To-Do TUI App(Made for GHW 2024: Career)"
- stdscr.addstr(0, int(cols/2)-len(init_text), init_text)
- stdscr.getch(rows-1, 0)
- stdscr.refresh()
- while 1:
- stdscr.clear()
- stdscr.addstr(0, 0, "Select a board:")
- i = 0
- for x in boards.keys():
- stdscr.addstr(i+1, 0, x)
- i += 1
- text = stdscr.getstr(rows-1, 0).decode()
- txt = text.split(" ")
- prompt = txt.pop(0)
- if prompt in boards.keys():
- cur_board = text
- stdscr.clear()
- stdscr.refresh()
- while True:
- stdscr.clear()
- for i in range(len(boards[cur_board])):
- stdscr.addstr(i, 0, f"{i+1}. {boards[cur_board][i]}")
- text = stdscr.getstr(rows-1, 0).decode()
- if text != "":
- text = text.split(" ")
- prompt = text.pop(0)
- if prompt.lower() == "add":
- txt = " ".join(text)
- boards[cur_board].append(txt)
- if prompt.lower() == "rem":
- boards[cur_board].pop(int(text[0])-1)
- if prompt.lower() == "save":
- save_data(text[0], boards)
- if prompt.lower() == "exit" or prompt.lower() == "quit":
- cur_board = text
- stdscr.clear()
- stdscr.refresh()
- break
- stdscr.refresh()
- elif prompt.lower() == "create":
- boards[txt[0]] = []
- elif prompt.lower() == "rem":
- boards.pop(txt[0])
- elif prompt.lower() == "load":
- boards = load_data(txt[0])
- elif prompt.lower() == "exit" or prompt.lower() == "quit":
- break
- elif prompt.lower() == "save":
- save_data(text[0], boards)
- stdscr.refresh()
- curses.endwin()
- return 0
- def save_data(filename, data):
- with open(filename, "w+") as f:
- f.write(json.dumps(data))
- def load_data(filename):
- with open(filename, "r+") as f:
- return json.loads(f.read())
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment