mirror of
https://github.com/rivo/tview.git
synced 2025-04-26 13:49:06 +08:00
Merge da88cafbf93fb3ed10c78ac6d3df22d7982790ed into c76f7879f592d17e9e68a1d795a85faae6cb7414
This commit is contained in:
commit
5d4a7a4572
@ -84,6 +84,7 @@ For a presentation highlighting this package, compile and run the program found
|
||||
- [The personal information dashboard for your terminal. ](https://github.com/wtfutil/wtf)
|
||||
- [MySQL database to Golang struct](https://github.com/xxjwxc/gormt)
|
||||
- [Discord, TUI and SIXEL.](https://gitlab.com/diamondburned/6cord)
|
||||
- [A terminal based blogs reader](https://github.com/ezeoleaf/tblogs)
|
||||
- [A CLI Audio Player](https://www.github.com/dhulihan/grump)
|
||||
- [GLab, a GitLab CLI tool](https://gitlab.com/profclems/glab)
|
||||
- [Browse your AWS ECS Clusters in the Terminal](https://github.com/swartzrock/ecsview)
|
||||
|
1
demos/searchModal/README.md
Normal file
1
demos/searchModal/README.md
Normal file
@ -0,0 +1 @@
|
||||

|
BIN
demos/searchModal/centered.png
Normal file
BIN
demos/searchModal/centered.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 74 KiB |
22
demos/searchModal/main.go
Normal file
22
demos/searchModal/main.go
Normal file
@ -0,0 +1,22 @@
|
||||
// Demo code for the Modal primitive.
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/rivo/tview"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := tview.NewApplication()
|
||||
modal := tview.NewModal().
|
||||
SetText("Search a list").
|
||||
AddInputText([]string{"Input text:"}).
|
||||
AddButtons([]string{"Search", "Clear"}).
|
||||
SetDoneFunc(func(buttonIndex int, buttonLabel string) {
|
||||
if buttonLabel == "Clear" {
|
||||
app.Stop()
|
||||
}
|
||||
})
|
||||
if err := app.SetRoot(modal, false).EnableMouse(true).Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
BIN
demos/searchModal/screenshot.png
Normal file
BIN
demos/searchModal/screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
18
modal.go
18
modal.go
@ -105,6 +105,17 @@ func (m *Modal) SetText(text string) *Modal {
|
||||
return m
|
||||
}
|
||||
|
||||
// AddInputText adds Input Fields to the window, which are later on identified by their labels.
|
||||
// a "done" handler so the window can be closed again.
|
||||
func (m *Modal) AddInputText(labels []string) *Modal {
|
||||
for index, label := range labels {
|
||||
func(i int, l string) {
|
||||
m.form.AddInputField(label, "", 20, nil, nil)
|
||||
}(index, label)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// AddButtons adds buttons to the window. There must be at least one button and
|
||||
// a "done" handler so the window can be closed again.
|
||||
func (m *Modal) AddButtons(labels []string) *Modal {
|
||||
@ -174,8 +185,13 @@ func (m *Modal) Draw(screen tcell.Screen) {
|
||||
m.frame.AddText(line, true, AlignCenter, m.textColor)
|
||||
}
|
||||
|
||||
lengthForm := 0
|
||||
if len(m.form.items) > 0 {
|
||||
lengthForm += len(m.form.items) + 1
|
||||
}
|
||||
|
||||
// Set the modal's position and size.
|
||||
height := len(lines) + 6
|
||||
height := len(lines) + 6 + lengthForm
|
||||
width += 4
|
||||
x := (screenWidth - width) / 2
|
||||
y := (screenHeight - height) / 2
|
||||
|
Loading…
x
Reference in New Issue
Block a user