most things work now?

main
m455 2018-04-13 01:02:48 -04:00
parent 6125f0e114
commit 711cd96ddb
4 changed files with 92 additions and 34 deletions

View File

@ -32,5 +32,10 @@
(equal? (vector-member initialize-command args) 0))
(initialize)]
[(and
(equal? args-length 1)
(member (vector-ref args 0) help-command))
(d-hash-ref messages 'show-help)]
[else
(d-hash-ref messages 'show-usage)])))

View File

@ -6,7 +6,14 @@
(define program-directory ".rodo/")
(define program-path "~/")
(define program-file "todo-list")
(define path
(expand-user-path
(string-append
program-path
program-directory
program-file)))
(define remove-command "rm")
(define add-command "add")
(define list-command "ls")
(define initialize-command "init")
(define help-command '("-h" "--help"))

View File

@ -6,6 +6,40 @@
(define messages
(hash
'show-help
(string-append
"* " initialize-command ": "
"initialize a file in "
program-path
program-directory
program-file
"\n"
"\x09Example: "
"rodo init\n\n"
"* " list-command ": "
"lists items on the list"
"\n"
"\x09Example: "
"rodo rm 1\n\n"
"* " add-command ": "
"adds an item to the list"
"\n"
"\x09Note: For multi-word items you will need to\n"
"\x09surround your item in double quotes as so:\n"
"\x09rodo add \"go to the bank\"\n"
"\x09Example: "
"rodo add bread\n\n"
"* " remove-command ": "
"removes an item from the list\n"
"\x09Note: You may have to run `rodo ls` to see which\n"
"\x09number corresponds to which item to remove it.\n"
"\x09Example: "
"rodo rm 1\n")
'show-usage
(string-append
"> For usage type "

View File

@ -15,6 +15,14 @@
(define (d-vector-ref args key)
(display (vector-ref args key)))
(define (quote-item-in-list lst args)
(display
(string-append
"\""
(list-ref lst
(string->number args))
"\"")))
(define (make-numbered lst)
(map
string-append
@ -28,13 +36,6 @@
(string-append ". " lst)))
(define (show-list-from-file)
(let
([path
(expand-user-path
(string-append
program-path
program-directory
program-file))])
(let
([todo-list
(file->lines path
@ -44,7 +45,7 @@
(string-join
(make-numbered (map (add-spaces) todo-list))
"\n"
#:after-last "\n")))))
#:after-last "\n"))))
(define (show-list)
(if
@ -56,19 +57,12 @@
(d-hash-ref messages 'file-not-found)
(d-hash-ref messages 'try-init))))
(define (add-item-to-file item)
(let ([item (string-append item "\n")])
(let
([path
(expand-user-path
(string-append
program-path
program-directory
program-file))])
(display-to-file item
(define (add-item-to-file args)
(let ([args (string-append args "\n")])
(display-to-file args
path
#:mode 'text
#:exists 'append))))
#:exists 'append)))
(define (add-item args)
(if
@ -84,16 +78,34 @@
(d-hash-ref messages 'file-not-found)
(d-hash-ref messages 'try-init))))
(define (remove-item-from-file args)
(let ([todo-list
(file->lines path
#:mode 'text
#:line-mode 'linefeed)])
(d-hash-ref messages 'item-removed-prefix)
(quote-item-in-list todo-list args)
(d-hash-ref messages 'item-removed-suffix)
(let ([new-list
(remove
(list-ref
todo-list
(string->number
args))
todo-list)])
(display-to-file
(string-append (string-join new-list "\n") "\n")
path
#:mode 'text
#:exists 'replace))))
(define (remove-item args)
(if
(and
(number? (string->number (vector-ref args 1)))
(check-for-folder)
(check-for-file))
(begin
;; TODO (remove-item-from-file (vector-ref args 1))
(d-hash-ref messages 'item-removed-prefix)
(d-vector-ref args 1)
(d-hash-ref messages 'item-removed-suffix))
(remove-item-from-file (vector-ref args 1))
(begin
(d-hash-ref messages 'file-not-found)
(d-hash-ref messages 'try-init))))