removed several string-appends that were no longer needed

main
m455 2019-03-12 22:41:18 -04:00
parent 7ebf92132e
commit fb643f7398
4 changed files with 109 additions and 117 deletions

View File

@ -33,8 +33,8 @@
(equal? (vector:vector-member config:remove-command args) 0) (equal? (vector:vector-member config:remove-command args) 0)
(real? (string->number (vector-ref args 1))) (real? (string->number (vector-ref args 1)))
(positive? (string->number (vector-ref args 1))) (positive? (string->number (vector-ref args 1)))
(not (> (string->number (vector-ref args 1)) (length (util:file->string-list config:path)))) (not (> (string->number (vector-ref args 1)) (length (util:file->string-list config:path-to-file))))
(not (< (string->number (vector-ref args 1)) (car (list:range (length (util:file->string-list config:path))))))) (not (< (string->number (vector-ref args 1)) (car (list:range (length (util:file->string-list config:path-to-file)))))))
(util:remove-item args)] (util:remove-item args)]
;; init ;; init

View File

@ -9,7 +9,4 @@
(define list-command "ls") (define list-command "ls")
(define initialize-command "init") (define initialize-command "init")
(define help-command '("-h" "--help")) (define help-command '("-h" "--help"))
(define path (define path-to-file (string-append program-directory program-file))
(string-append
program-directory
program-file))

View File

@ -9,33 +9,29 @@
(provide (all-defined-out)) (provide (all-defined-out))
(define (check-for-file) (define (check-for-file)
(file-exists? config:path)) (file-exists? config:path-to-file))
(define (create-file) (define (create-file)
(let ([opened-file (let ([opened-file
(open-output-file config:path (open-output-file config:path-to-file
#:mode 'text #:mode 'text
#:exists 'truncate)]) #:exists 'truncate)])
(close-output-port opened-file)) (close-output-port opened-file))
(file-or-directory-permissions config:path #o600)) (file-or-directory-permissions config:path-to-file #o600))
(define (check-for-directory) (define (check-for-directory)
(directory-exists? (expand-user-path (directory-exists? config:program-directory))
(string-append
config:program-directory))))
(define (create-directory) (define (create-directory)
(make-directory (expand-user-path (make-directory config:program-directory)
(string-append
config:program-directory)))
(file-or-directory-permissions config:program-directory #o700)) (file-or-directory-permissions config:program-directory #o700))
(define (display-hash-ref hash-list key) (define (display-hash-ref hash-list key)
(display (hash-ref hash-list key))) (display (hash-ref hash-list key)))
;; Just so I don't have to keep typing "#:mode...#:line-mode..." every time ;; Just so I don't have to keep typing "#:mode...#:line-mode..." every time
(define (file->string-list config:path-to-file) (define (file->string-list config:path-to-file-to-file)
(let ([todo-list (file:file->lines config:path-to-file (let ([todo-list (file:file->lines config:path-to-file-to-file
#:mode 'text #:mode 'text
#:line-mode 'any)]) #:line-mode 'any)])
todo-list)) todo-list))
@ -69,7 +65,7 @@
(define (display-prettified-list) (define (display-prettified-list)
(display (display
(string:string-join (string:string-join
(prefix-with-number (file->string-list config:path)) (prefix-with-number (file->string-list config:path-to-file))
"\n" "\n"
#:after-last "\n"))) #:after-last "\n")))
@ -94,7 +90,7 @@
(if (if
;; If file exists, see if it's empty, if so ;; If file exists, see if it's empty, if so
;; tell the user ;; tell the user
(list-empty? config:path) (list-empty? config:path-to-file)
(display-hash-ref messages:messages 'empty-todo-list) (display-hash-ref messages:messages 'empty-todo-list)
;; If file isn't empty, display a pretty list ;; If file isn't empty, display a pretty list
(display-prettified-list))] (display-prettified-list))]
@ -105,10 +101,10 @@
(define (add-item-to-file args) (define (add-item-to-file args)
;; Add item to end of list and write to file ;; Add item to end of list and write to file
(let ([new-list (append-to-end args config:path)]) (let ([new-list (append-to-end args config:path-to-file)])
(file:display-to-file (file:display-to-file
(string:string-join new-list "\n") (string:string-join new-list "\n")
config:path config:path-to-file
#:mode 'text #:mode 'text
#:exists 'truncate) #:exists 'truncate)
(display-item-added args))) (display-item-added args)))
@ -117,25 +113,24 @@
(if (and (if (and
(check-for-directory) (check-for-directory)
(check-for-file)) (check-for-file))
;; The cdr here removes the command string "add" from being added to the file ;; The cdr here prevents the command line argument "add" from being added to the file
(add-item-to-file (string:string-join (cdr (vector->list args)))) (add-item-to-file (string:string-join (cdr (vector->list args))))
(begin (begin
(display-hash-ref messages:messages 'file-not-found) (display-hash-ref messages:messages 'file-not-found)
(display-hash-ref messages:messages 'try-init)))) (display-hash-ref messages:messages 'try-init))))
(define (remove-item-from-file args) (define (remove-item-from-file args)
(let* ([removed-item (get-removed-item config:path args)] (let* ([removed-item (get-removed-item config:path-to-file args)]
[new-list (remove removed-item (file->string-list config:path))]) [new-list (remove removed-item (file->string-list config:path-to-file))])
(file:display-to-file (file:display-to-file
(string:string-join new-list "\n") (string:string-join new-list "\n")
config:path config:path-to-file
#:mode 'text #:mode 'text
#:exists 'truncate) #:exists 'truncate)
(display-item-removed removed-item))) (display-item-removed removed-item)))
(define (remove-item args) (define (remove-item args)
(cond [(list-empty? config:path) (cond [(list-empty? config:path-to-file)
(display-hash-ref messages:messages 'empty-todo-list)] (display-hash-ref messages:messages 'empty-todo-list)]
[(and [(and
(check-for-directory) (check-for-directory)