Skip to content

Instantly share code, notes, and snippets.

@ba0f3
Created December 4, 2019 08:10
Show Gist options
  • Save ba0f3/8c3823c694b9b4925c69ac295bb5d1d4 to your computer and use it in GitHub Desktop.
Save ba0f3/8c3823c694b9b4925c69ac295bb5d1d4 to your computer and use it in GitHub Desktop.
import prompt, unicode, terminal
proc autoComplete(line: seq[Rune], cursorpos: int): seq[string] {.gcsafe.} =
if line.len == 0:
return @[]
if $line == "hi":
result = @["Hello", "Xin chao", "Bonjour"]
else:
result = @["Chuc mung"]
for i in 0..<result.len:
var s = result[i]
result[i] = s[cursorpos..<s.len]
var p = Prompt.init(autoComplete = autoComplete)
p.setIndicator("Nim> ")
p.setStatusbar(@[("aa", "bb"), ("Date", "2019-12-04")])
p.showPrompt()
while true:
var text = p.readLine()
if text == "q":
p.hidePrompt()
break
p.writeLine(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment