aboutsummaryrefslogtreecommitdiff
path: root/cipher/viewer.neb
diff options
context:
space:
mode:
Diffstat (limited to 'cipher/viewer.neb')
-rw-r--r--cipher/viewer.neb76
1 files changed, 76 insertions, 0 deletions
diff --git a/cipher/viewer.neb b/cipher/viewer.neb
new file mode 100644
index 0000000..ae99f29
--- /dev/null
+++ b/cipher/viewer.neb
@@ -0,0 +1,76 @@
+;(func ascii-grey (inp)
+; (print (concat "\033[31;1;4m" inp "\033[0m"))
+; (concat "\033[90m" inp "\033[0m"))
+
+(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_)
+ (ascii-gray _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")
+ (with-write "progress.txt"
+ (write (concat cipher (newline)) _file_)
+ (for-each codex
+ (write (concat (first _item_) " " (first (rest _item_)) (newline)) _file_)))
+ (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 (input "? ")) " "))
+ (branch
+ ((eq? "quit" (first inp)) (exit))
+ ((eq? "save" (first inp)) (save-and-exit cipher cur))
+ ((> (list-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)))