1
0
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:
Eze Olea Figueroa 2024-11-12 21:12:37 +01:00 committed by GitHub
commit 5d4a7a4572
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 41 additions and 1 deletions

View File

@ -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)

View File

@ -0,0 +1 @@
![Screenshot](screenshot.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

22
demos/searchModal/main.go Normal file
View 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)
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -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