diff --git a/README.md b/README.md index 3022012..344f135 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/demos/searchModal/README.md b/demos/searchModal/README.md new file mode 100644 index 0000000..4a14e6c --- /dev/null +++ b/demos/searchModal/README.md @@ -0,0 +1 @@ +![Screenshot](screenshot.png) diff --git a/demos/searchModal/centered.png b/demos/searchModal/centered.png new file mode 100644 index 0000000..7511a05 Binary files /dev/null and b/demos/searchModal/centered.png differ diff --git a/demos/searchModal/main.go b/demos/searchModal/main.go new file mode 100644 index 0000000..344a612 --- /dev/null +++ b/demos/searchModal/main.go @@ -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) + } +} diff --git a/demos/searchModal/screenshot.png b/demos/searchModal/screenshot.png new file mode 100644 index 0000000..dcb7c8e Binary files /dev/null and b/demos/searchModal/screenshot.png differ diff --git a/modal.go b/modal.go index d12eb91..b146a67 100644 --- a/modal.go +++ b/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