can now remove items without errors, but have to improve the process of removing and adding items later

main
m455 2018-04-16 09:57:38 -04:00
parent e8c97fdba7
commit 05b03ea28b
2 changed files with 25 additions and 22 deletions

View File

@ -9,8 +9,8 @@
(provide (all-defined-out)) (provide (all-defined-out))
(define (initialize-file) (define (initialize-file)
(display-to-file (display-to-file
"\n" "\n"
path path
#:mode 'text #:mode 'text
#:exists 'replace)) #:exists 'replace))

View File

@ -24,6 +24,9 @@
#:line-mode 'any)]) #:line-mode 'any)])
todo-list)) todo-list))
(define (list-empty? lst)
(empty? (rest (file->string-list lst))))
(define (quote-item-in-list lst args) (define (quote-item-in-list lst args)
(display (display
(string-append (string-append
@ -41,29 +44,32 @@
string-append string-append
(map (map
number->string number->string
(range (length lst))) (rest (range (length lst))))
lst)) (rest lst)))
(define (indent-list) (define (indent-list)
(lambda (lst) (lambda (lst)
(string-append ". " lst))) (string-append ". " lst)))
(define (prettify-list) (define (prettify-list)
(display (display
(string-join (string-join
(number-list (map (indent-list) (file->string-list path))) (number-list (map (indent-list) (file->string-list path)))
"\n" "\n"
#:after-last "\n"))) #:after-last "\n")))
(define (show-list) (define (show-list)
(if (cond
(and [(and
(check-for-folder) (check-for-folder)
(check-for-file)) (check-for-file))
(prettify-list) (if
(begin (list-empty? path)
(d-hash-ref messages 'empty-todo-list)
(prettify-list))]
[else
(d-hash-ref messages 'file-not-found) (d-hash-ref messages 'file-not-found)
(d-hash-ref messages 'try-init)))) (d-hash-ref messages 'try-init)]))
(define (add-item-to-file args) (define (add-item-to-file args)
(let ([args (string-append args "\n")]) (let ([args (string-append args "\n")])
@ -89,8 +95,7 @@
(define (remove-item-from-file args) (define (remove-item-from-file args)
(d-hash-ref messages 'item-removed-prefix) (d-hash-ref messages 'item-removed-prefix)
(quote-item-in-list (quote-item-in-list (file->string-list path) args)
(file->string-list path) args)
(d-hash-ref messages 'item-removed-suffix) (d-hash-ref messages 'item-removed-suffix)
(let ([new-list (let ([new-list
(remove (list-ref (remove (list-ref
@ -106,11 +111,9 @@
(define (remove-item args) (define (remove-item args)
(cond (cond
[(< (length (file->string-list path)) 1) [(list-empty? path)
(d-hash-ref messages 'empty-(file->string-list path))] (d-hash-ref messages 'empty-todo-list)]
[(and [(and
(number? (string->number (vector-ref args 1)))
(< (string->number (vector-ref args 1)) (vector-length args))
(check-for-folder) (check-for-folder)
(check-for-file)) (check-for-file))
(remove-item-from-file (vector-ref args 1))] (remove-item-from-file (vector-ref args 1))]