Implemented encrypt/decrypt and password.
h3rald h3rald@h3rald.com
Sun, 18 Sep 2016 12:26:28 +0200
3 files changed,
22 insertions(+),
7 deletions(-)
M
core/linedit.nim
→
core/linedit.nim
@@ -322,7 +322,7 @@
proc lineText*(ed: LineEditor): string = return ed.line.text -proc initEditor*(mode = mdInsert, historySize = 256, historyFile: string): LineEditor = +proc initEditor*(mode = mdInsert, historySize = 256, historyFile: string = nil): LineEditor = termSetup() result.mode = mode result.history = historyInit(historySize, historyFile)@@ -422,7 +422,7 @@ KEYSEQS["insert"] = @[27, 91, 50, 126]
KEYSEQS["delete"] = @[27, 91, 51, 126] -proc readLine*(ed: var LineEditor, prompt=""): string = +proc readLine*(ed: var LineEditor, prompt="", hidechars = false): string = stdout.write(prompt) ed.line = Line(text: "", position: 0) var c = -1 # Used to manage completions@@ -441,7 +441,12 @@ return ed.line.text
elif c1 in {8, 127}: KEYMAP["backspace"](ed) elif c1 in PRINTABLE: - ed.printChar(c1) + if hidechars: + putchar('*'.ord) + ed.line.text &= c1.chr + ed.line.position.inc + else: + ed.printChar(c1) elif c1 == 9: # TAB c = ed.completeLine() elif c1 in ESCAPES:@@ -481,6 +486,9 @@ elif c4 == 126 and c3 == 51:
KEYMAP["delete"](ed) elif KEYMAP.hasKey(KEYNAMES[c1]): KEYMAP[KEYNAMES[c1]](ed) + +proc password*(ed: var LineEditor, prompt=""): string = + return ed.readLine(prompt, true) when isMainModule: proc testChar() =
M
lib/min_io.nim
→
lib/min_io.nim
@@ -1,5 +1,6 @@
import os, strutils import + ../core/linedit, ../core/types, ../core/parser, ../core/interpreter,@@ -18,7 +19,7 @@ .symbol("put") do (i: In):
let a = i.peek echo $$a - .symbol("tab-print") do (i: In): + .symbol("column-print") do (i: In): var n, q: MinValue i.reqIntAndQuotation n, q var c = 0@@ -30,7 +31,11 @@ echo ""
echo "" .symbol("get") do (i: In): - i.push newVal(stdin.readLine()) + i.push stdin.readLine().newVal + + .symbol("password") do (i: In): + var ed = initEditor() + i.push ed.password("Enter Password: ").newVal .symbol("print") do (i: In): let a = i.peek@@ -53,5 +58,5 @@ var f:File
discard f.open(a.strVal, fmAppend) f.write(b.strVal) f.close() - + .finalize()
M
prelude.min
→
prelude.min
@@ -62,8 +62,10 @@ ; Other
(print pop) :print! (dprint pop) :dprint! (put pop) :put! -(:ms :q :check (check) (ms sleep q) while) :interval (call pop) :call! +(:ms :q :check (check) (ms sleep q) while) :interval +(password aes encode) :encrypt +(decode password aes) :decrypt ; Load all stored symbols