Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ For a presentation highlighting this package, compile and run the program found
- [MySQL database to Golang struct](https://github.com/xxjwxc/gormt)
- [Cryptowatch Go SDK](https://github.com/y3sh/cw-sdk-go)
- [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)

Expand Down
1 change: 1 addition & 0 deletions demos/searchModal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
![Screenshot](screenshot.png)
Binary file added demos/searchModal/centered.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions demos/searchModal/main.go
Original file line number Diff line number Diff line change
@@ -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 added demos/searchModal/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 17 additions & 1 deletion modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,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 {
Expand Down Expand Up @@ -163,8 +174,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
Expand Down