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)

26
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 (let
([path ([opened-file
(expand-user-path (open-output-file
(string-append path
program-path #:mode 'text
program-directory #:exists 'can-update)])
program-file))]) (close-output-port opened-file)))
(let
([opened-file
(open-output-file
path
#:mode 'text
#:exists 'can-update)])
(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

112
util.rkt
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,38 +44,34 @@
(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
path args
#:mode 'text path
#:exists 'append))) #:mode 'text
#:exists 'append)))
(define (add-item args) (define (add-item args)
(if (if
@ -72,51 +81,40 @@
(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 (d-hash-ref messages 'item-removed-prefix)
(file->lines path (quote-item-in-list
#:mode 'text (file->string-list path) args)
#:line-mode 'linefeed)]) (d-hash-ref messages 'item-removed-suffix)
(d-hash-ref messages 'item-removed-prefix) (let ([new-list
(quote-item-in-list todo-list args) (remove (list-ref
(d-hash-ref messages 'item-removed-suffix) (file->string-list path)
(let ([new-list (string->number
(remove args))
(list-ref (file->string-list path))])
todo-list (display-to-file
(string->number (string-join new-list "\n" #:after-last "\n")
args)) path
todo-list)]) #:mode 'text
(display-to-file #:exists 'replace)))
(string-join new-list "\n")
path
#:mode 'text
#:exists 'replace))))
(define (remove-item args) (define (remove-item args)
(let ([todo-list (cond
(file->lines [(< (length (file->string-list path)) 1)
path (d-hash-ref messages 'empty-(file->string-list path))]
#:mode 'text [(and
#:line-mode 'linefeed)]) (number? (string->number (vector-ref args 1)))
(cond (< (string->number (vector-ref args 1)) (vector-length args))
[(< (length todo-list) 1) (check-for-folder)
(d-hash-ref messages 'empty-todo-list)] (check-for-file))
[(and (remove-item-from-file (vector-ref args 1))]
(number? (string->number (vector-ref args 1))) [(and (not (check-for-folder)) (not (check-for-file)))
(< (string->number (vector-ref args 1)) (vector-length args)) (begin
(check-for-folder) (d-hash-ref messages 'file-not-found)
(check-for-file)) (d-hash-ref messages 'try-init))]))
(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)])))