2
0
mirror of https://github.com/rivo/tview.git synced 2024-11-07 03:20:39 +00:00

Final preparations for the first official release.

This commit is contained in:
Oliver 2018-01-06 22:49:12 +01:00
parent 36cca0dedc
commit c989300073
9 changed files with 70 additions and 19 deletions

View File

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

2
box.go
View File

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

View File

@ -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]()
}`

View File

@ -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]()
}`

View File

@ -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]()
}`

View File

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

BIN
screenshot.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 KiB

View File

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

View File

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