master
Josha von Gizycki 5 years ago
parent a25a12598a
commit e8d54c6fd5

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

Loading…
Cancel
Save