moved feedback messages till after add and remove are done. now shows which item was removed
parent
fe35b97834
commit
d9aea661a1
52
util.rkt
52
util.rkt
|
@ -27,26 +27,16 @@
|
|||
(define (list-empty? lst)
|
||||
(empty? (rest (file->string-list lst))))
|
||||
|
||||
(define (quote-item-in-list lst args)
|
||||
(cond
|
||||
[(number? args)
|
||||
(define (get-removed-item lst args)
|
||||
(list-ref lst (string->number args)))
|
||||
|
||||
(define (quote-item args)
|
||||
(display
|
||||
(string-append
|
||||
"\""
|
||||
(list-ref lst (string->number args))
|
||||
"\""))]
|
||||
[(string? args)
|
||||
(display
|
||||
(string-append
|
||||
"\""
|
||||
args
|
||||
"\""))]))
|
||||
(string-append "\"" args "\"")))
|
||||
|
||||
(define (number-list lst)
|
||||
(map
|
||||
string-append
|
||||
(map
|
||||
number->string
|
||||
(map string-append
|
||||
(map number->string
|
||||
(rest (range (length lst))))
|
||||
(rest lst)))
|
||||
|
||||
|
@ -75,20 +65,18 @@
|
|||
(d-hash-ref messages 'try-init)]))
|
||||
|
||||
(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
|
||||
(reverse
|
||||
(append (list args)
|
||||
(reverse
|
||||
(file->string-list path))))])
|
||||
(reverse (file->string-list path))))])
|
||||
(display-to-file
|
||||
(string-join new-list "\n" #:after-last "\n")
|
||||
path
|
||||
#: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)
|
||||
(if
|
||||
|
@ -101,20 +89,20 @@
|
|||
(d-hash-ref messages 'try-init))))
|
||||
|
||||
(define (remove-item-from-file args)
|
||||
(d-hash-ref messages 'item-removed-prefix)
|
||||
(quote-item-in-list (file->string-list path) args)
|
||||
(d-hash-ref messages 'item-removed-suffix)
|
||||
(let ([removed-item
|
||||
(get-removed-item (file->string-list path) args)])
|
||||
(let ([new-list
|
||||
(remove (list-ref
|
||||
(file->string-list path)
|
||||
(string->number
|
||||
args))
|
||||
(remove
|
||||
(list-ref (file->string-list path) (string->number args))
|
||||
(file->string-list path))])
|
||||
(display-to-file
|
||||
(string-join new-list "\n" #:after-last "\n")
|
||||
path
|
||||
#: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)
|
||||
(cond
|
||||
|
|
Loading…
Reference in New Issue