2018-01-03 20:13:32 +00:00
|
|
|
// Demo code for the InputField primitive.
|
2017-12-27 15:05:00 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-04-03 15:11:20 +00:00
|
|
|
"code.rocketnine.space/tslocum/cview"
|
2020-08-30 15:36:03 +00:00
|
|
|
"github.com/gdamore/tcell/v2"
|
2017-12-27 15:05:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2019-12-30 23:12:17 +00:00
|
|
|
app := cview.NewApplication()
|
2020-10-07 23:34:21 +00:00
|
|
|
app.EnableMouse(true)
|
|
|
|
|
|
|
|
inputField := cview.NewInputField()
|
|
|
|
inputField.SetLabel("Enter a number: ")
|
|
|
|
inputField.SetPlaceholder("E.g. 1234")
|
|
|
|
inputField.SetFieldWidth(10)
|
|
|
|
inputField.SetAcceptanceFunc(cview.InputFieldInteger)
|
|
|
|
inputField.SetDoneFunc(func(key tcell.Key) {
|
|
|
|
app.Stop()
|
|
|
|
})
|
|
|
|
|
|
|
|
app.SetRoot(inputField, true)
|
|
|
|
if err := app.Run(); err != nil {
|
2017-12-27 15:05:00 +00:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|