jaar23 / tui_widget

terminal ui widget based on illwill
14 stars 1 forks source link

Clear an inputbox on enter #1

Closed casey-SK closed 7 months ago

casey-SK commented 7 months ago

Hello, I am just playing around with this library, I have the following tui, where line 12 seems to create unexpected behaviour. The entire program becomes unusable with inputBox.value("") included. otherwise the program runs as expected.

import tui_widget
import illwill, options

var inputBox = newInputBox(1, 1, consoleWidth(), 3, "message", bgColor=bgBlue)
var display = newDisplay(1, 4, consoleWidth(), 16, "board", statusbar=false) 

let enterEv: EnterEventProcedure = proc(arg: string) =
  display.add(inputBox.value & "\n")
  inputBox.value("") # clear the inputBox 
  display.render()
  inputBox.render()

inputBox.onEnter= enterEv

var app = newTerminalApp(title="tui widget")

app.addWidget(inputBox)
app.addWidget(display)
app.run()

Thanks, Casey

casey-SK commented 7 months ago

Turns out it was the cursor. Fixed

import tui_widget
import illwill, options

var inputBox = newInputBox(1, 1, consoleWidth(), 3, "message", bgColor=bgBlack)
var display = newDisplay(1, 4, consoleWidth(), consoleHeight(), "board", statusbar=false) 

var app = newTerminalApp(title="tui widget")

let enterEv: EnterEventProcedure = proc(arg: string) =
  display.add(inputBox.value & "\n")
  display.render()
  inputBox.value("")
  inputBox.resetCursor()

inputBox.onEnter= enterEv

app.addWidget(inputBox)
app.addWidget(display)
app.run()
jaar23 commented 7 months ago

hi @casey-SK , thanks for trying out the library. It is still under development and testing locally to do resetCursor() on value changes. Like what you experience, is due the cursor has not been updated after a new value assigned to the widget. The event API and value function will change, it may look something like this after the update.

let enterEv: EnterEventProcedure = proc(arg: string) =
  display.add(inputBox.value & "\n")
  inputBox.value("") # or inputBox.value = ""

thank you.