forked from tslocum/cview
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.2 KiB
40 lines
1.2 KiB
package main |
|
|
|
import ( |
|
"github.com/gdamore/tcell" |
|
"git.sr.ht/~tslocum/cview" |
|
) |
|
|
|
const inputField = `[green]package[white] main |
|
|
|
[green]import[white] ( |
|
[red]"strconv"[white] |
|
|
|
[red]"github.com/gdamore/tcell"[white] |
|
[red]"git.sr.ht/~tslocum/cview"[white] |
|
) |
|
|
|
[green]func[white] [yellow]main[white]() { |
|
input := cview.[yellow]NewInputField[white](). |
|
[yellow]SetLabel[white]([red]"Enter a number: "[white]). |
|
[yellow]SetAcceptanceFunc[white]( |
|
cview.InputFieldInteger, |
|
).[yellow]SetDoneFunc[white]([yellow]func[white](key tcell.Key) { |
|
text := input.[yellow]GetText[white]() |
|
n, _ := strconv.[yellow]Atoi[white](text) |
|
[blue]// We have a number.[white] |
|
}) |
|
cview.[yellow]NewApplication[white](). |
|
[yellow]SetRoot[white](input, true). |
|
[yellow]Run[white]() |
|
}` |
|
|
|
// InputField demonstrates the InputField. |
|
func InputField(nextSlide func()) (title string, content cview.Primitive) { |
|
input := cview.NewInputField(). |
|
SetLabel("Enter a number: "). |
|
SetAcceptanceFunc(cview.InputFieldInteger).SetDoneFunc(func(key tcell.Key) { |
|
nextSlide() |
|
}) |
|
return "Input", Code(input, 30, 1, inputField) |
|
}
|
|
|