master
Josha von Gizycki 5 years ago
parent a25a12598a
commit e8d54c6fd5

@ -29,7 +29,7 @@
(def dorodata "dorodata") (def dorodata "dorodata")
(defn help [] (defn help []
(print "add, rm, mod, help, quit, [enter]")) (print "add, rm, prio, help, quit, [enter]"))
(defn readline [] (defn readline []
(let [line (file/read stdin :line)] (let [line (file/read stdin :line)]
@ -71,7 +71,8 @@
(reduce (fn [acc entry] (reduce (fn [acc entry]
(string acc (string acc
"id:" (entry :id) "\n" "id:" (entry :id) "\n"
"title:" (entry :title) "\n")) "title:" (entry :title) "\n"
"prio:" (entry :prio) "\n"))
"" ""
entries)) entries))
@ -81,9 +82,9 @@
(file/flush f) (file/flush f)
(file/close f))) (file/close f)))
(defn request-val [label] (defn request-val [label &opt if-nil]
(print label ":") (print label ":")
(readline)) (or (readline) if-nil))
(defn new-id [] (defn new-id []
(inc (or (max ;(map (fn [e] (inc (or (max ;(map (fn [e]
@ -95,12 +96,13 @@
(defn add [] (defn add []
(-> (load-entries) (-> (load-entries)
(array/push {:id (new-id) (array/push {:id (new-id)
:title (request-val "Title")}) :title (request-val "Title")
:prio "5"})
save-entries)) save-entries))
(defn col-length [entries col] (defn col-length [entries col]
(or (max ;(map (fn [entry] (or (max ;(map (fn [entry]
(length (entry col))) (length (get entry col "")))
entries)) entries))
0)) 0))
@ -116,32 +118,42 @@
(length "Id")) (length "Id"))
len-title (max (col-length entries :title) len-title (max (col-length entries :title)
(length "Title")) (length "Title"))
len-prio (max (col-length entries :prio)
(length "Prio"))
spaces (fn [l m] (string/repeat " " (max 0 (- m l))))] spaces (fn [l m] (string/repeat " " (max 0 (- m l))))]
(print (vt100-codes :underlined) (print (vt100-codes :underlined)
"Id" (spaces 2 len-id) "Id" (spaces 2 len-id)
" " " "
"Prio" (spaces 4 len-prio)
" "
"Title" (spaces 5 len-title) "Title" (spaces 5 len-title)
(vt100-codes :clear)) (vt100-codes :clear))
(var ix 0) (var ix 0)
(loop [entry :in entries (loop [entry :in entries
:let [id (entry :id) :let [id (string (entry :id))
title (entry :title)]] title (string (entry :title))
prio (string (entry :prio))]]
(print (if (odd? ix) (print (if (odd? ix)
(vt100-codes :lightgray) (vt100-codes :lightgray)
(vt100-codes :bold)) (vt100-codes :bold))
id (spaces (length id) len-id) id (spaces (length id) len-id)
" " " "
prio (spaces (length prio) len-prio)
" "
title (spaces (length title) len-title) title (spaces (length title) len-title)
(vt100-codes :clear)) (vt100-codes :clear))
(set ix (inc ix)))) (set ix (inc ix))))
(print)) (print))
(defn id->entry [id]
(->> (load-entries)
(filter (fn [e]
(= id (e :id))))
first))
(defn rm [] (defn rm []
(let [id (request-val "Id") (let [id (request-val "Id")
to-delete (->> (load-entries) to-delete (id->entry id)
(filter (fn [e]
(= id (e :id))))
first)
confirm (fn [] confirm (fn []
(not= "n" (request-val (not= "n" (request-val
(string "Confirm deletion of " (string "Confirm deletion of "
@ -153,10 +165,21 @@
(filter (fn [e] (not= id (e :id)))) (filter (fn [e] (not= id (e :id))))
(save-entries))))) (save-entries)))))
(defn prio []
(let [m-entry (put (id->entry (request-val "Id"))
:prio (request-val "Prio" "5"))]
(when m-entry
(save-entries
(map (fn [e]
(if (= (e :id) (m-entry :id))
m-entry
e))
(load-entries))))))
(def structure (def structure
{"add" add {"add" add
"rm" rm "rm" rm
"mod" (fn [] (print "mod")) "prio" prio
"help" help "help" help
"" overview "" overview
"quit" quit}) "quit" quit})

Loading…
Cancel
Save