diff --git a/io.rkt b/io.rkt index b3c0509..63afefb 100644 --- a/io.rkt +++ b/io.rkt @@ -1,6 +1,7 @@ #lang racket/base -(require "config.rkt") +(require racket/file + "config.rkt") (provide (all-defined-out)) diff --git a/messages.rkt b/messages.rkt index 2198be7..cb38df9 100644 --- a/messages.rkt +++ b/messages.rkt @@ -32,7 +32,7 @@ "\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" @@ -40,6 +40,9 @@ "\x09Example: " "rodo rm 1\n") + 'empty-todo-list + "Error> There is nothing in your list yet\n" + 'show-usage (string-append "> For usage type " @@ -119,6 +122,9 @@ 'choose-y/n "> Error: Please choose y or n\n" + 'not-in-list + "> Error: Item does not exist\n" + 'item-added-prefix "> Added " diff --git a/util.rkt b/util.rkt index ec031f9..7dcf0d3 100644 --- a/util.rkt +++ b/util.rkt @@ -100,12 +100,23 @@ #:exists 'replace)))) (define (remove-item args) - (if - (and - (number? (string->number (vector-ref args 1))) - (check-for-folder) - (check-for-file)) - (remove-item-from-file (vector-ref args 1)) - (begin - (d-hash-ref messages 'file-not-found) - (d-hash-ref messages 'try-init)))) + (let ([todo-list + (file->lines + path + #:mode 'text + #:line-mode 'linefeed)]) + (cond + [(< (length todo-list) 1) + (d-hash-ref messages 'empty-todo-list)] + [(and + (number? (string->number (vector-ref args 1))) + (< (string->number (vector-ref args 1)) (vector-length args)) + (check-for-folder) + (check-for-file)) + (remove-item-from-file (vector-ref args 1))] + [(and (not (check-for-folder)) (not (check-for-file))) + (begin + (d-hash-ref messages 'file-not-found) + (d-hash-ref messages 'try-init))] + [(>= (string->number (vector-ref args 1)) (vector-length args)) + (d-hash-ref messages 'not-in-list)])))