moved feedback messages till after add and remove are done. now shows which item was removed

main
m455 2018-04-26 00:24:35 -04:00
parent fe35b97834
commit d9aea661a1
1 changed files with 30 additions and 42 deletions

View File

@ -27,26 +27,16 @@
(define (list-empty? lst) (define (list-empty? lst)
(empty? (rest (file->string-list lst)))) (empty? (rest (file->string-list lst))))
(define (quote-item-in-list lst args) (define (get-removed-item lst args)
(cond (list-ref lst (string->number args)))
[(number? args)
(define (quote-item args)
(display (display
(string-append (string-append "\"" args "\"")))
"\""
(list-ref lst (string->number args))
"\""))]
[(string? args)
(display
(string-append
"\""
args
"\""))]))
(define (number-list lst) (define (number-list lst)
(map (map string-append
string-append (map number->string
(map
number->string
(rest (range (length lst)))) (rest (range (length lst))))
(rest lst))) (rest lst)))
@ -75,20 +65,18 @@
(d-hash-ref messages 'try-init)])) (d-hash-ref messages 'try-init)]))
(define (add-item-to-file args) (define (add-item-to-file args)
(begin
(d-hash-ref messages 'item-added-prefix)
(quote-item-in-list (file->string-list path) args)
(d-hash-ref messages 'item-added-suffix))
(let ([new-list (let ([new-list
(reverse (reverse
(append (list args) (append (list args)
(reverse (reverse (file->string-list path))))])
(file->string-list path))))])
(display-to-file (display-to-file
(string-join new-list "\n" #:after-last "\n") (string-join new-list "\n" #:after-last "\n")
path path
#:mode 'text #:mode 'text
#:exists 'replace))) #:exists 'replace)
(d-hash-ref messages 'item-added-prefix)
(quote-item args)
(d-hash-ref messages 'item-added-suffix)))
(define (add-item args) (define (add-item args)
(if (if
@ -101,20 +89,20 @@
(d-hash-ref messages 'try-init)))) (d-hash-ref messages 'try-init))))
(define (remove-item-from-file args) (define (remove-item-from-file args)
(d-hash-ref messages 'item-removed-prefix) (let ([removed-item
(quote-item-in-list (file->string-list path) args) (get-removed-item (file->string-list path) args)])
(d-hash-ref messages 'item-removed-suffix)
(let ([new-list (let ([new-list
(remove (list-ref (remove
(file->string-list path) (list-ref (file->string-list path) (string->number args))
(string->number
args))
(file->string-list path))]) (file->string-list path))])
(display-to-file (display-to-file
(string-join new-list "\n" #:after-last "\n") (string-join new-list "\n" #:after-last "\n")
path path
#:mode 'text #:mode 'text
#:exists 'replace))) #:exists 'replace))
(d-hash-ref messages 'item-removed-prefix)
(quote-item removed-item)
(d-hash-ref messages 'item-removed-suffix)))
(define (remove-item args) (define (remove-item args)
(cond (cond