-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodo.ldpl
251 lines (236 loc) · 5.96 KB
/
todo.ldpl
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
USING PACKAGE std-list
DATA:
todo.File is text
todo.List is text list
VERSION is text
PROCEDURE:
store "1.0.1" in VERSION
execute "echo $TODO" and store output in todo.File
trim todo.File in todo.File
if todo.File is equal to "" then
store "~/.todo" in todo.File
end if
sub todo.Load
local data:
content is text
lines is text list
procedure:
load file todo.File in content
split content by "\n" in todo.List
end sub
sub todo.Save
local data:
file is text
line is text
cmd is text
out is text
procedure:
for each line in todo.List do
trim line in line
if line is equal to "" then
continue
end if
in out join out line "\n"
repeat
write out to file todo.File
append crlf to file todo.File
end sub
# todo -add "do something"
sub cmd.Add
local data:
argc is number
i is number
todo is text
procedure:
get length of argv in argc
if argc is less than 2 then
display "-> nothing to add" crlf
return
end if
call todo.Load
store 1 in i
while i is less than argc do
in todo join todo " " argv:i
in i solve i + 1
repeat
trim todo in todo
push todo to todo.List
call todo.Save
display "-> added \"" todo "\"" crlf
end sub
# todo -check
sub cmd.Check
local data:
num is number
count is number
argc is number
prefix is text
todo is text
i is number
procedure:
get length of argv in argc
if argc is less than 2 then
display "-> give me a # to check off" crlf
return
end if
call todo.Load
get length of todo.List in count
store 1 in i
while i is less than argc do
store argv:i in num
if num is greater than or equal to count or num is less than 1 then
display "-> can't find todo #" num crlf
return
end if
in num solve num - 1
store todo.List:num in todo
get length of todo in count
substring todo from 0 length 2 in prefix
if prefix is equal to "X " then
substring todo from 2 length count in todo
else
in todo join "X " todo
end if
store todo in todo.List:num
in i solve i + 1
repeat
call todo.Save
call cmd.List
end sub
# todo -clear
sub cmd.Clear
local data:
todo is text
todos is text list
prefix is text
procedure:
call todo.Load
for each todo in todo.List do
substring todo from 0 length 2 in prefix
if prefix is not equal to "X " then
push todo to todos
end if
repeat
copy todos to todo.List
call todo.Save
call cmd.List
end sub
# todo -edit
sub cmd.Edit
local data:
cmd is text
procedure:
in cmd join "$EDITOR" " " todo.File
display "-> " cmd crlf
execute cmd
end sub
# todo -help
sub cmd.Help
display "Usage:" crlf crlf
display "\ttodo <COMMAND>" crlf crlf
display "Commands:" crlf crlf
display "\t-add \"todo\"" "\t" "add todo item" crlf
display "\t-check <ID>" "\t" "check off one or more todo items" crlf
display "\t-clear" "\t\t" "clear checked todos" crlf
display "\t-list" "\t\t" "list todos" crlf
display "\t-version" "\t" "show version" crlf
display crlf
end sub
# todo -list
sub cmd.List
local data:
todo is text
i is number
prefix is text
prefix2 is text
spacer is text
end is number
first is number
header is number
procedure:
call todo.Load
store 1 in first
for each todo in todo.List do
store 0 in header
trim todo in todo
if todo is equal to "" then
continue
end if
get character at 0 from todo in prefix
substring todo from 0 length 3 in prefix2
if prefix is equal to "#" or prefix2 is equal to "X #" then
store 1 in header
if first is not equal to 1 then
display crlf
end if
end if
in i solve i + 1
substring todo from 0 length 2 in prefix
get length of todo in end
if prefix is equal to "X " then
store "\e[90mX" in spacer
substring todo from 2 length end in todo
else
store "\e[0m " in spacer
end if
if i is less than 10 then
in spacer join spacer " "
end if
if header is equal to 1 then
display spacer
if i is greater than or equal to 10 then
display " "
end if
display " "
if prefix is equal to "X " then
display "\e[90m"
else
display "\e[93m"
end if
display todo "\e[0m\n"
else
display spacer " " i ". " todo "\n"
end if
store 0 in first
repeat
if i is equal to 0 then
display "-> no todos in " todo.File crlf
end if
end sub
# todo -version
sub cmd.Version
display "ldpl-todo v" VERSION crlf
end sub
sub Main
local data:
size is number
cmd is text
prefix is text
procedure:
get length of argv in size
if size is greater than 0 then
store argv:0 in cmd
get character at 0 from cmd in prefix # support --flags too
if prefix is equal to "-" then
replace "--" from cmd with "-" in cmd
end if
end if
if cmd is equal to "-add" or cmd is equal to "-a" then
call cmd.Add
else if cmd is equal to "-check" or cmd is equal to "-c" then
call cmd.Check
else if cmd is equal to "-clear" or cmd is equal to "-d" then
call cmd.Clear
else if cmd is equal to "-edit" or cmd is equal to "-e" then
call cmd.Edit
else if cmd is equal to "-list" or cmd is equal to "-l" then
call cmd.List
else if cmd is equal to "-help" or cmd is equal to "-h" then
call cmd.Help
else if cmd is equal to "-version" or cmd is equal to "-v" then
call cmd.Version
else
call cmd.Help
end if
end sub
call Main