| 1 | // Demo code for the InputField primitive. |
| 2 | package main |
| 3 | |
| 4 | import ( |
| 5 | "github.com/gdamore/tcell/v2" |
| 6 | "github.com/rivo/tview" |
| 7 | ) |
| 8 | |
| 9 | func main() { |
| 10 | app := tview.NewApplication() |
| 11 | inputField := tview.NewInputField(). |
| 12 | SetLabel("Enter a number: "). |
| 13 | SetPlaceholder("E.g. 1234"). |
| 14 | SetFieldWidth(10). |
| 15 | SetAcceptanceFunc(tview.InputFieldInteger). |
| 16 | SetDoneFunc(func(key tcell.Key) { |
| 17 | app.Stop() |
| 18 | }) |
| 19 | if err := app.SetRoot(inputField, true).EnableMouse(true).EnablePaste(true).Run(); err != nil { |
| 20 | panic(err) |
| 21 | } |
| 22 | } |