Skip to content

Commit

Permalink
finalize autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSimpleZ committed Mar 24, 2020
1 parent e3eafca commit d221951
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
12 changes: 4 additions & 8 deletions src/frontend/inputfield.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import jslibs / xtermjs

var pty {.importjs.}: JsObject

var expanded = false
var lastCompletion: kstring = ""

proc onkeyupenter(ev: Event, target: VNode) =
pty.writeln(target.text)
target.text = ""
expanded = false
lastCompletion = ""

proc sleep(ms: int): Future[void] =
Expand All @@ -24,18 +22,16 @@ proc autocomplete(target: VNode, s: kstring) {.async, discardable.} =
target.setInputText(s)
await sleep(100)
else:
outputEnabled = false
pty.write(s & "\t")
await sleep(100)
target.setInputText(currentLine)
lastCompletion = currentLine
let backspaceCount = currentLine.len
pty.backspace(backspaceCount)
for i in 0..backspaceCount:
terminal.write('\b')
lastCompletion = currentLine
if lastCompletion != s: await sleep(100)
outputEnabled = true
currentLine = ""
expanded = true
# pty.eraseLine()
# eraseLine()

proc onkeydown(ev: Event, target: VNode) =
let kbev = (KeyboardEvent)ev
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/xterm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ proc onBodyResize() {.exportc.} =
pty.setColumns(newSize.cols)

var currentLine*: kstring = ""
var outputEnabled = true
var outputEnabled* = true
proc xtermWrite(bytes: openarray[byte]) {.exportc.} =
if outputEnabled:
terminal.write(bytes)
Expand Down

0 comments on commit d221951

Please sign in to comment.