...
1 package main
2
3 import (
4 "github.com/gdamore/tcell/v2"
5 "github.com/rivo/tview"
6 )
7
8 const inputField = `[green]package[white] main
9
10 [green]import[white] (
11 [red]"strconv"[white]
12
13 [red]"github.com/gdamore/tcell/v2"[white]
14 [red]"github.com/rivo/tview"[white]
15 )
16
17 [green]func[white] [yellow]main[white]() {
18 input := tview.[yellow]NewInputField[white]().
19 [yellow]SetLabel[white]([red]"Enter a number: "[white]).
20 [yellow]SetAcceptanceFunc[white](
21 tview.InputFieldInteger,
22 ).[yellow]SetDoneFunc[white]([yellow]func[white](key tcell.Key) {
23 text := input.[yellow]GetText[white]()
24 n, _ := strconv.[yellow]Atoi[white](text)
25 [blue]// We have a number.[white]
26 })
27 tview.[yellow]NewApplication[white]().
28 [yellow]SetRoot[white](input, true).
29 [yellow]Run[white]()
30 }`
31
32
33 func InputField(nextSlide func()) (title string, content tview.Primitive) {
34 input := tview.NewInputField().
35 SetLabel("Enter a number: ").
36 SetAcceptanceFunc(tview.InputFieldInteger).SetDoneFunc(func(key tcell.Key) {
37 nextSlide()
38 })
39 return "Input", Code(input, 30, 1, inputField)
40 }
41
View as plain text