(use-as "../libs/ansi.neb" ansi) (func keys (assoc) (map first assoc)) (func get (assoc key) (def ret "_") (for-each assoc (if (eq? (first _item_) key) (redef ret (first (rest _item_))))) ret) (func de-cipher (cipher codex) (def out "") (for-each (split cipher) (redef out (concat out (if (in? _item_ (keys codex)) (get codex _item_) (ansi/faint _item_))))) out) (func print-codex (codex) (for-each codex (print (concat (first _item_) " => " (first (rest _item_)))))) (func save-and-exit (cipher codex) (print "in save-and-exit") (def prog (open-write "progress.txt")) (write (concat cipher "\n") prog) (for-each codex (write (concat (first _item_) " " (first (rest _item_)) "\n") prog)) (exit)) (func loop (cipher codex) (def cur codex) (while #true (clear) (print (de-cipher cipher cur)) (print "") (print-codex cur) (print "") (def inp (split (strip (read-line "? ")) " ")) (branch ((eq? "quit" (first inp)) (exit)) ((eq? "save" (first inp)) (save-and-exit cipher cur)) ((> (length inp) 2) (exit)) ((and (empty? (rest inp)) (in? (first inp) (keys cur))) (redef cur (remove cur (first inp)))) ((in? (first inp) (keys codex)) (redef cur (append (remove cur (first inp)) inp))) ((empty? (rest inp)) #true) (#true (redef cur (append cur inp)))))) (func split-space (str) (split str " ")) (func main (args) (if (empty? args) (block (print "expecting a cypher!") (exit))) (def lines (map strip (read-lines (first args)))) (def codex (map split-space (rest lines))) (loop (first lines) codex)) (main (rest (argv)))