You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
2.9 KiB
111 lines
2.9 KiB
(def logo
|
|
`
|
|
▓█████▄ ▒█████ ██▀███ ▒█████
|
|
▒██▀ ██▌▒██▒ ██▒▓██ ▒ ██▒▒██▒ ██▒
|
|
░██ █▌▒██░ ██▒▓██ ░▄█ ▒▒██░ ██▒
|
|
░▓█▄ ▌▒██ ██░▒██▀▀█▄ ▒██ ██░
|
|
░▒████▓ ░ ████▓▒░░██▓ ▒██▒░ ████▓▒░
|
|
▒▒▓ ▒ ░ ▒░▒░▒░ ░ ▒▓ ░▒▓░░ ▒░▒░▒░
|
|
░ ▒ ▒ ░ ▒ ▒░ ░▒ ░ ▒░ ░ ▒ ▒░
|
|
░ ░ ░ ░ ░ ░ ▒ ░░ ░ ░ ░ ░ ▒
|
|
░ ░ ░ ░ ░ ░
|
|
░
|
|
`)
|
|
|
|
(def bye
|
|
`
|
|
▄▄▄▄ ▓██ ██▓▓█████
|
|
▓█████▄▒██ ██▒▓█ ▀
|
|
▒██▒ ▄██▒██ ██░▒███
|
|
▒██░█▀ ░ ▐██▓░▒▓█ ▄
|
|
░▓█ ▀█▓░ ██▒▓░░▒████▒
|
|
░▒▓███▀▒ ██▒▒▒ ░░ ▒░ ░
|
|
▒░▒ ░▓██ ░▒░ ░ ░ ░
|
|
░ ░▒ ▒ ░░ ░
|
|
░ ░ ░ ░ ░
|
|
░░ ░
|
|
`)
|
|
|
|
(def dorodata "dorodata")
|
|
|
|
(defn help []
|
|
(print "add, rm, mod, help, quit, [enter]"))
|
|
|
|
(defn readline []
|
|
(let [line (file/read stdin :line)]
|
|
(if (nil? line)
|
|
nil
|
|
(string/trimr line))))
|
|
|
|
(defn quit []
|
|
(print bye)
|
|
(os/exit 0))
|
|
|
|
(defn lines->entries [lines]
|
|
(var entries @[])
|
|
(loop [line :in lines]
|
|
(let [[key content] (string/split ":" line)
|
|
kwkey (keyword key)]
|
|
(when (or (= "id" key)
|
|
(nil? (array/peek entries)))
|
|
(array/push entries @{}))
|
|
(set ((array/peek entries) kwkey)
|
|
content)))
|
|
entries)
|
|
|
|
(defn ensure-dorodata []
|
|
(-> (file/open dorodata :w)
|
|
(file/flush)
|
|
(file/close)))
|
|
|
|
(defn load-entries []
|
|
(let [f (file/open dorodata :r)
|
|
content (file/read f :all)]
|
|
(file/close f)
|
|
(->> content
|
|
(string/split "\n")
|
|
lines->entries)))
|
|
|
|
(defn entries->string [entries]
|
|
(reduce (fn [acc entry]
|
|
(string acc
|
|
"id:" (entry :id) "\n"
|
|
"title:" (entry :title) "\n"))
|
|
""
|
|
entries))
|
|
|
|
(defn save-entries [entries]
|
|
(let [f (file/open dorodata :w)]
|
|
(file/write f (entries->string entries))
|
|
(file/flush f)
|
|
(file/close f)))
|
|
|
|
(defn request-val [label]
|
|
(print label)
|
|
(readline))
|
|
|
|
(defn new-id []
|
|
(inc (max ;(map (fn [e] (scan-number (e :id)))
|
|
(load-entries)))))
|
|
|
|
(defn add []
|
|
(-> (load-entries)
|
|
(array/push {:id (new-id)
|
|
:title (request-val "Title")})
|
|
save-entries))
|
|
|
|
(def structure
|
|
{"add" add
|
|
"rm" (fn [] (print "rm"))
|
|
"mod" (fn [] (print "mod"))
|
|
"help" help
|
|
"" (fn [] (print "overview"))
|
|
"quit" quit})
|
|
|
|
(defn main [& args]
|
|
(ensure-dorodata)
|
|
(print logo)
|
|
(help)
|
|
(while true
|
|
((get structure (readline) help))))
|