-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
137 lines (122 loc) · 4.9 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
from rich.console import Console
from rich.table import Table
import os
from time import sleep
from pynput.keyboard import Listener
console = Console()
TODO_items = []
DONE_items = []
cursor_position = {"first_column": True, "position": 0}
def add_todo_item(title: str) -> None:
TODO_items.append(title)
def add_done_item(title: str) -> None:
DONE_items.append(title)
def update() -> None:
os.system("clear")
table = Table(title="Todo App")
table.add_column("TODO", justify="center", style="cyan", no_wrap=True)
table.add_column("DONE", justify="center", style="cyan", no_wrap=True)
bigger_number = len(TODO_items) if len(TODO_items) > len(DONE_items) else len(DONE_items)
for i in range(0, bigger_number):
if(cursor_position["first_column"] == True):
if(cursor_position["position"] == i):
try:
table.add_row(f"[bold blue] [ ] {TODO_items[i]}", f"[X] {DONE_items[i]}")
except:
table.add_row(f"[bold blue] [ ] {TODO_items[i]}", "")
continue
else:
if(cursor_position["position"] == i):
try:
table.add_row(f"[ ] {TODO_items[i]}", f"[bold blue] [X] {DONE_items[i]}")
except:
table.add_row("", f"[bold blue] [X] {DONE_items[i]}")
continue
try:
table.add_row(f"[ ] {TODO_items[i]}", f"[X] {DONE_items[i]}")
except:
if(len(TODO_items) > len(DONE_items)):
table.add_row(f"[ ] {TODO_items[i]}", "")
else:
table.add_row("", f"[X] {DONE_items[i]}")
console.print(table)
def move_to_done(title: str) -> None:
TODO_items.remove(title)
DONE_items.append(title)
def move_to_todo(title: str) -> None:
DONE_items.remove(title)
TODO_items.append(title)
def remove_from_todo(title: str) -> None:
TODO_items.remove(title)
def remove_from_done(title: str) -> None:
DONE_items.remove(title)
add_todo_item("Prove that 2+2")
add_done_item("Meth")
add_done_item("buy milk")
update()
# I use colemak.
def on_press(key):
if key.char == "i":
# TODO change 0 if needed
if(cursor_position["position"] != 0):
cursor_position["position"] -= 1
update()
if key.char == "k":
if(cursor_position["first_column"]):
if(cursor_position["position"] != len(TODO_items) - 1):
cursor_position["position"] += 1
else:
if(cursor_position["position"] != len(DONE_items) - 1):
cursor_position["position"] += 1
update()
if key.char == "l":
cursor_position["first_column"] = False
if(cursor_position["position"] > len(DONE_items) - 1):
cursor_position["position"] = len(DONE_items) - 1
update()
if key.char == "j":
cursor_position["first_column"] = True
if(cursor_position["position"] > len(TODO_items) - 1):
cursor_position["position"] = len(TODO_items) - 1
update()
if key.char == "f":
if(cursor_position["first_column"] == True):
move_to_done(TODO_items[cursor_position["position"]])
if(cursor_position["position"] > len(TODO_items) - 1):
if(TODO_items != []):
cursor_position["position"] = len(TODO_items) - 1
else:
cursor_position["first_column"] = False
cursor_position["position"] = 0
update()
else:
move_to_todo(DONE_items[cursor_position["position"]])
if(cursor_position["position"] > len(DONE_items) - 1):
if(DONE_items != []):
cursor_position["position"] = len(DONE_items) - 1
else:
cursor_position["first_column"] = True
cursor_position["position"] = 0
update()
if key.char == "s":
# if(cursor_position["first_column"]):
# remove_from_todo(TODO_items[cursor_position["position"]])
# if(cursor_position["position"] > len(TODO_items) - 1):
# if(TODO_items != []):
# cursor_position["position"] = len(TODO_items) - 1
# else:
# cursor_position["first_column"] = False
# cursor_position["position"] = 0
# update()
# if(cursor_position["first_column"] == False):
# remove_from_todo(DONE_items[cursor_position["position"]])
# if(cursor_position["position"] > len(DONE_items) - 1):
# if(DONE_items != []):
# cursor_position["position"] = len(DONE_items) - 1
# else:
# cursor_position["first_column"] = True
# cursor_position["position"] = 0
# update()
pass
with Listener(on_press=on_press) as listener:
listener.join()