diff --git a/README.md b/README.md index c89d042..c01f1c7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,66 @@ -# Widgets for Terminal GUIs +# Rich Interactive Widgets for Terminal UIs -Based on [github.com/gdamore/tcell](https://github.com/gdamore/tcell). +[![Godoc Reference](https://img.shields.io/badge/godoc-reference-blue.svg)](https://godoc.org/github.com/rivo/tview) +[![Go Report](https://img.shields.io/badge/go%20report-A%2B-brightgreen.svg)](https://goreportcard.com/report/github.com/rivo/tview) -Work in progress. +This Go package provides commonly needed components for terminal based user interfaces. + +![Screenshot](screenshot.jpg) + +Among these components are: + +- __Input forms__ (include __input fields__, __drop-down selections__, __checkboxes__, and __buttons__) +- Navigatable multi-color __text views__ +- Sophisticated navigatable __table views__ +- Selectable __lists__ +- __Flexbox__ and __page layouts__ +- Modal __message windows__ +- An __application__ wrapper + +They come with lots of customization options and can be easily extended to fit your needs. + +## Installation + +```bash +go get github.com/rivo/tview +``` + +## Hello World + +This basic example creates a box titled "Hello, World!" and displays it in your terminal: + +```go +package main + +import ( + "github.com/rivo/tview" +) + +func main() { + box := tview.NewBox().SetBorder(true).SetTitle("Hello, world!") + if err := tview.NewApplication().SetRoot(box, true).Run(); err != nil { + panic(err) + } +} +``` + +Check out the [GitHub Wiki](https://github.com/rivo/tview/wiki) for more examples along with screenshots. Or try the examples in the "demos" subdirectory. + +For a presentation highlighting this package, compile and run the program found in the "demos/presentation" subdirectory. + +## Documentation + +Refer to https://godoc.org/github.com/rivo/tview for the package's documentation. + +## Dependencies + +This package is based on [github.com/gdamore/tcell](https://github.com/gdamore/tcell). + +## Your Feedback + +Add your issue here on GitHub. Feel free to get in touch if you have any questions. + +## Releases + +- v0.1 (2018-01-06) + - First Release diff --git a/box.go b/box.go index a6dc013..7069ed7 100644 --- a/box.go +++ b/box.go @@ -34,7 +34,7 @@ type Box struct { titleAlign int // Provides a way to find out if this box has focus. We always go through - // this interface because it may be overriden by implementing classes. + // this interface because it may be overridden by implementing classes. focus Focusable // Whether or not this box has focus. diff --git a/demos/presentation/form.go b/demos/presentation/form.go index 59d5abb..d16aa21 100644 --- a/demos/presentation/form.go +++ b/demos/presentation/form.go @@ -24,7 +24,6 @@ const form = `[green]package[white] main [yellow]AddButton[white]([red]"Cancel"[white], [yellow]func[white]() { [blue]/* Cancel */[white] }) tview.[yellow]NewApplication[white](). [yellow]SetRoot[white](form, true). - [yellow]SetFocus[white](form). [yellow]Run[white]() }` diff --git a/demos/presentation/inputfield.go b/demos/presentation/inputfield.go index b5e19c5..9700041 100644 --- a/demos/presentation/inputfield.go +++ b/demos/presentation/inputfield.go @@ -26,7 +26,6 @@ const inputField = `[green]package[white] main }) tview.[yellow]NewApplication[white](). [yellow]SetRoot[white](input, true). - [yellow]SetFocus[white](input). [yellow]Run[white]() }` diff --git a/demos/presentation/table.go b/demos/presentation/table.go index 0081cee..77b5b5d 100644 --- a/demos/presentation/table.go +++ b/demos/presentation/table.go @@ -81,7 +81,6 @@ const tableBasic = `[green]func[white] [yellow]main[white]() { } tview.[yellow]NewApplication[white](). [yellow]SetRoot[white](table, true). - [yellow]SetFocus[white](table). [yellow]Run[white]() }` @@ -114,7 +113,6 @@ const tableSeparator = `[green]func[white] [yellow]main[white]() { } tview.[yellow]NewApplication[white](). [yellow]SetRoot[white](table, true). - [yellow]SetFocus[white](table). [yellow]Run[white]() }` @@ -147,7 +145,6 @@ const tableBorders = `[green]func[white] [yellow]main[white]() { } tview.[yellow]NewApplication[white](). [yellow]SetRoot[white](table, true). - [yellow]SetFocus[white](table). [yellow]Run[white]() }` @@ -181,7 +178,6 @@ const tableSelectRow = `[green]func[white] [yellow]main[white]() { } tview.[yellow]NewApplication[white](). [yellow]SetRoot[white](table, true). - [yellow]SetFocus[white](table). [yellow]Run[white]() }` @@ -215,7 +211,6 @@ const tableSelectColumn = `[green]func[white] [yellow]main[white]() { } tview.[yellow]NewApplication[white](). [yellow]SetRoot[white](table, true). - [yellow]SetFocus[white](table). [yellow]Run[white]() }` @@ -249,7 +244,6 @@ const tableSelectCell = `[green]func[white] [yellow]main[white]() { } tview.[yellow]NewApplication[white](). [yellow]SetRoot[white](table, true). - [yellow]SetFocus[white](table). [yellow]Run[white]() }` diff --git a/demos/presentation/textview.go b/demos/presentation/textview.go index 5f554e9..8c81c28 100644 --- a/demos/presentation/textview.go +++ b/demos/presentation/textview.go @@ -26,7 +26,6 @@ const textView1 = `[green]func[white] [yellow]main[white]() { }() tview.[yellow]NewApplication[white](). [yellow]SetRoot[white](textView, true). - [yellow]SetFocus[white](textView). [yellow]Run[white]() }` @@ -96,7 +95,6 @@ const textView2 = `[green]package[white] main fmt.[yellow]Fprint[white](["7"]textView[""], content) tview.[yellow]NewApplication[white](). [yellow]SetRoot[white](["8"]textView[""], true). - [yellow]SetFocus[white](["9"]textView[""]). [yellow]Run[white]() }` @@ -129,14 +127,14 @@ func TextView2(nextSlide func()) (title string, content tview.Primitive) { case tcell.KeyTab: if hasHighlights { current, _ := strconv.Atoi(highlights[0]) - next := (current + 1) % 10 + next := (current + 1) % 9 textView.Highlight(strconv.Itoa(next)). ScrollToHighlight() } case tcell.KeyBacktab: if hasHighlights { current, _ := strconv.Atoi(highlights[0]) - next := (current - 1 + 10) % 10 + next := (current - 1 + 9) % 9 textView.Highlight(strconv.Itoa(next)). ScrollToHighlight() } diff --git a/screenshot.jpg b/screenshot.jpg new file mode 100644 index 0000000..b35daab Binary files /dev/null and b/screenshot.jpg differ diff --git a/table.go b/table.go index 94a9328..bbb583a 100644 --- a/table.go +++ b/table.go @@ -44,7 +44,7 @@ func (c *TableCell) GetLastPosition() (x, y, width int) { // dynamically to the table and changed any time. // // The most compact display of a table is without borders. Each row will then -// occupy one row on screen and columns are seperated by the rune defined via +// occupy one row on screen and columns are separated by the rune defined via // SetSeparator() (a space character by default). // // When borders are turned on (via SetBorders()), each table cell is surrounded diff --git a/util.go b/util.go index c2a6dc7..90a927e 100644 --- a/util.go +++ b/util.go @@ -87,8 +87,8 @@ func init() { } // Print prints text onto the screen into the given box at (x,y,maxWidth,1), -// no exceeding that box. "align" is one of AlignLeft, AlignCenter, or -// AlignRight. The screen's background color will be maintained. +// not exceeding that box. "align" is one of AlignLeft, AlignCenter, or +// AlignRight. The screen's background color will not be changed. // // Returns the number of actual runes printed. func Print(screen tcell.Screen, text string, x, y, maxWidth, align int, color tcell.Color) int {