updated via script

main
m455 2018-04-15 00:15:10 -04:00
parent 5b7338e4fa
commit e8c97fdba7
5 changed files with 79 additions and 84 deletions

View File

@ -1,19 +1,19 @@
#lang racket/base #lang racket/base
(require racket/file)
(provide (all-defined-out)) (provide (all-defined-out))
(define program-name "rodo") (define program-name "rodo")
(define program-directory ".rodo/") (define program-directory ".rodo/")
(define program-path "~/") (define program-path "~/")
(define program-file "todo-list") (define program-file "todo-list")
(define remove-command "rm")
(define add-command "add")
(define list-command "ls")
(define initialize-command "init")
(define help-command '("-h" "--help"))
(define path (define path
(expand-user-path (expand-user-path
(string-append (string-append
program-path program-path
program-directory program-directory
program-file))) 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

@ -1,12 +1,20 @@
#lang racket/base #lang racket/base
(require "config.rkt" (require racket/file
"config.rkt"
"util.rkt" "util.rkt"
"messages.rkt" "messages.rkt"
"io.rkt") "io.rkt")
(provide (all-defined-out)) (provide (all-defined-out))
(define (initialize-file)
(display-to-file
"\n"
path
#:mode 'text
#:exists 'replace))
(define (init-prompt hash-list key) (define (init-prompt hash-list key)
(d-hash-ref hash-list key) (d-hash-ref hash-list key)
(display "> ") (display "> ")
@ -18,6 +26,7 @@
(d-hash-ref messages 'creating-file) (d-hash-ref messages 'creating-file)
(create-folder) (create-folder)
(create-file) (create-file)
(initialize-file)
(if (if
(and (and
(check-for-folder) (check-for-folder)

16
io.rkt
View File

@ -6,28 +6,16 @@
(provide (all-defined-out)) (provide (all-defined-out))
(define (check-for-file) (define (check-for-file)
(file-exists? (file-exists? path))
(expand-user-path
(string-append
program-path
program-directory
program-file))))
(define (create-file) (define (create-file)
(let
([path
(expand-user-path
(string-append
program-path
program-directory
program-file))])
(let (let
([opened-file ([opened-file
(open-output-file (open-output-file
path path
#:mode 'text #:mode 'text
#:exists 'can-update)]) #:exists 'can-update)])
(close-output-port opened-file)))) (close-output-port opened-file)))
(define (check-for-folder) (define (check-for-folder)
(directory-exists? (directory-exists?

View File

@ -40,7 +40,7 @@
"\x09number corresponds to which item to remove it.\n") "\x09number corresponds to which item to remove it.\n")
'empty-todo-list 'empty-todo-list
"Error> There is nothing in your list yet\n" "Error > There is nothing in your list \n"
'show-usage 'show-usage
(string-append (string-append

View File

@ -15,15 +15,28 @@
(define (d-vector-ref args key) (define (d-vector-ref args key)
(display (vector-ref args key))) (display (vector-ref args key)))
(define (file->string-list path-to-file)
(let
([todo-list
(file->lines
path-to-file
#:mode 'text
#:line-mode 'any)])
todo-list))
(define (quote-item-in-list lst args) (define (quote-item-in-list lst args)
(display (display
(string-append (string-append
"\"" "\""
(list-ref lst (list-ref lst (string->number args))
(string->number args))
"\""))) "\"")))
(define (make-numbered lst) (define (quote-item-in-vector args)
(display
(string-append
"\"" args "\"")))
(define (number-list lst)
(map (map
string-append string-append
(map (map
@ -31,35 +44,31 @@
(range (length lst))) (range (length lst)))
lst)) lst))
(define (add-spaces) (define (indent-list)
(lambda (lst) (lambda (lst)
(string-append ". " lst))) (string-append ". " lst)))
(define (show-list-from-file) (define (prettify-list)
(let
([todo-list
(file->lines path
#:mode 'text
#:line-mode 'linefeed)])
(display (display
(string-join (string-join
(make-numbered (map (add-spaces) todo-list)) (number-list (map (indent-list) (file->string-list path)))
"\n" "\n"
#:after-last "\n")))) #:after-last "\n")))
(define (show-list) (define (show-list)
(if (if
(and (and
(check-for-folder) (check-for-folder)
(check-for-file)) (check-for-file))
(show-list-from-file) (prettify-list)
(begin (begin
(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")])
(display-to-file args (display-to-file
args
path path
#:mode 'text #:mode 'text
#:exists 'append))) #:exists 'append)))
@ -72,42 +81,33 @@
(begin (begin
(add-item-to-file (vector-ref args 1)) (add-item-to-file (vector-ref args 1))
(d-hash-ref messages 'item-added-prefix) (d-hash-ref messages 'item-added-prefix)
(d-vector-ref args 1) (quote-item-in-vector (vector-ref args 1))
(d-hash-ref messages 'item-added-suffix)) (d-hash-ref messages 'item-added-suffix))
(begin (begin
(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 (remove-item-from-file args) (define (remove-item-from-file args)
(let ([todo-list
(file->lines path
#:mode 'text
#:line-mode 'linefeed)])
(d-hash-ref messages 'item-removed-prefix) (d-hash-ref messages 'item-removed-prefix)
(quote-item-in-list todo-list args) (quote-item-in-list
(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 (remove (list-ref
(list-ref (file->string-list path)
todo-list
(string->number (string->number
args)) args))
todo-list)]) (file->string-list path))])
(display-to-file (display-to-file
(string-join new-list "\n") (string-join new-list "\n" #:after-last "\n")
path path
#:mode 'text #:mode 'text
#:exists 'replace)))) #:exists 'replace)))
(define (remove-item args) (define (remove-item args)
(let ([todo-list
(file->lines
path
#:mode 'text
#:line-mode 'linefeed)])
(cond (cond
[(< (length todo-list) 1) [(< (length (file->string-list path)) 1)
(d-hash-ref messages 'empty-todo-list)] (d-hash-ref messages 'empty-(file->string-list path))]
[(and [(and
(number? (string->number (vector-ref args 1))) (number? (string->number (vector-ref args 1)))
(< (string->number (vector-ref args 1)) (vector-length args)) (< (string->number (vector-ref args 1)) (vector-length args))
@ -117,6 +117,4 @@
[(and (not (check-for-folder)) (not (check-for-file))) [(and (not (check-for-folder)) (not (check-for-file)))
(begin (begin
(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))]))
[(>= (string->number (vector-ref args 1)) (vector-length args))
(d-hash-ref messages 'not-in-list)])))