Created
August 31, 2018 02:54
-
-
Save treeform/516726cae2b7ffbd7a0aaa757595ac65 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import streams | |
| when hostOS == "windows": | |
| proc wgetch(): char {. header: "<conio.h>", importc: "getch" .} | |
| proc wgetche(): char {. header: "<conio.h>", importc: "getche" .} | |
| # stdout.write("\e[2J") # clear screen | |
| const promt = "quicki >>> " | |
| stdout.write(promt) | |
| var line = "" | |
| while true: | |
| var input = wgetche() | |
| # edit commands | |
| if input == '\8': | |
| if line.len > 0: | |
| line.setLen(line.len - 1) | |
| elif input == '\r': | |
| stdout.write("\e[J") # clar everything after cursor | |
| quit() | |
| else: | |
| line.add input | |
| stdout.write("\e[J") # clar everything after cursor | |
| stdout.write("\n") | |
| for i, c in line: | |
| stdout.write(c & " " & $ord(c) & " -- option [" & $i & "]\n") | |
| # move up | |
| for i in 0..line.len: | |
| stdout.write("\e[1A") | |
| # move left | |
| for i in 0..(promt.len + line.len - 1): | |
| stdout.write("\e[C") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment