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 " crlf crlf display "Commands:" crlf crlf display "\t-add \"todo\"" "\t" "add todo item" crlf display "\t-check " "\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