Categorygithub.com/rivo/tview
modulepackage
0.0.0-20241227133733-17b7edb88c57
Repository: https://github.com/rivo/tview.git
Documentation: pkg.go.dev

# README

Rich Interactive Widgets for Terminal UIs

PkgGoDev Go Report

This Go package provides commonly used components for terminal based user interfaces.

Screenshot

Among these components are:

  • Input forms (including text input, selections, checkboxes, and buttons)
  • Navigable multi-color text views
  • Editable multi-line text areas
  • Sophisticated navigable table views
  • Flexible tree views
  • Selectable lists
  • Images
  • Grid, 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.

Usage

To add this package to your project:

go get github.com/rivo/tview@master

Hello World

This basic example creates a box titled "Hello, World!" and displays it in your terminal:

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

Projects using tview

Documentation

Refer to https://pkg.go.dev/github.com/rivo/tview for the package's documentation. Also check out the Wiki.

Dependencies

This package is based on github.com/gdamore/tcell (and its dependencies) as well as on github.com/rivo/uniseg.

Sponsor this Project

Become a Sponsor on GitHub to further this project!

Versioning and Backwards-Compatibility

I try really hard to keep this project backwards compatible. Your software should not break when you upgrade tview. But this also means that some of its shortcomings that were present in the initial versions will remain. In addition, at least for the time being, you won't find any version tags in this repo. The newest version should be the one to upgrade to. It has all the bugfixes and latest features. Having said that, backwards compatibility may still break when:

  • a new version of an imported package (most likely tcell) changes in such a way that forces me to make changes in tview as well,
  • I fix something that I consider a bug, rather than a feature, something that does not work as originally intended,
  • I make changes to "internal" interfaces such as Primitive. You shouldn't need these interfaces unless you're writing your own primitives for tview. (Yes, I realize these are public interfaces. This has advantages as well as disadvantages. For the time being, it is what it is.)

Your Feedback

Add your issue here on GitHub. Feel free to get in touch if you have any questions.

Code of Conduct

We follow Golang's Code of Conduct which you can find here.

# Packages

# Functions

ANSIWriter returns an io.Writer which translates any ANSI escape codes written to it into tview style tags.
Escape escapes the given text such that color and/or region tags are not recognized and substituted by the print functions of this package.
NewApplication creates and returns a new application.
NewBox returns a Box without a border.
NewButton returns a new input field.
NewCheckbox returns a new input field.
NewDropDown returns a new drop-down.
NewFlex returns a new flexbox layout container with no primitives and its direction set to FlexColumn.
NewForm returns a new form.
NewFrame returns a new frame around the given primitive.
NewGrid returns a new grid-based layout container with no initial primitives.
NewImage returns a new image widget with an empty image (use [Image.SetImage] to specify the image to be displayed).
NewInputField returns a new input field.
NewList returns a new list.
NewModal returns a new modal message window.
NewPages returns a new Pages object.
NewTable returns a new table.
NewTableCell returns a new table cell with sensible defaults.
NewTextArea returns a new text area.
NewTextView returns a new text view.
NewTreeNode returns a new tree node.
NewTreeView returns a new tree view.
Print prints text onto the screen into the given box at (x,y,maxWidth,1), not exceeding that box.
PrintJoinedSemigraphics prints a semigraphics rune into the screen at the given position with the given style, joining it with any existing semigraphics rune.At this point, only regular single line borders are supported.
PrintSimple prints white text to the screen at the given position.
TaggedStringWidth returns the width of the given string needed to print it on screen.
TranslateANSI replaces ANSI escape sequences found in the provided string with tview's style tags and returns the resulting string.
Unescape unescapes text previously escaped with [Escape].
WordWrap splits a text such that each resulting line does not exceed the given screen width.

# Constants

Text alignment within a box.
Text alignment within a box.
Text alignment within a box.
Text alignment within a box.
Text alignment within a box.
The user selected an autocomplete entry by clicking the mouse button on it.
The user selected an autocomplete entry using the enter key.
The user navigated the autocomplete list (using the errow keys).
The user selected an autocomplete entry using the tab key.
▓.
█.
▋.
▌.
▏.
▎.
▉.
▍.
▊.
░.
▅.
▄.
▁.
▂.
▇.
▃.
▆.
▒.
▖.
▗.
▘.
▙.
▚.
▛.
▜.
▝.
▞.
▟.
▐.
▕.
▀.
▔.
╦.
╗.
╔.
═.
╩.
╝.
╚.
║.
╬.
╣.
╠.
╥.
╖.
╓.
┰.
┒.
┧.
┎.
┟.
╁.
┯.
┑.
┨.
┍.
┡.
╇.
╤.
╕.
╒.
╍.
╏.
╻.
┳.
┓.
┏.
━.
╸.
╾.
┉.
┋.
╺.
┅.
┇.
╹.
┻.
┛.
╿.
┗.
┃.
╋.
┫.
┣.
╅.
┭.
┵.
┽.
┲.
┺.
╊.
╃.
╮.
╭.
╯.
╰.
╳.
╲.
╱.
╌.
╎.
╷.
┬.
┐.
┌.
─.
╴.
╼.
┈.
┊.
╶.
┄.
┆.
╵.
╽.
┴.
┘.
└.
│.
┼.
┤.
├.
╆.
┮.
┶.
┾.
┱.
┹.
╉.
╄.
╨.
╜.
╙.
╀.
┸.
┦.
┚.
┞.
┖.
╈.
┷.
┪.
┙.
┢.
┕.
╧.
╛.
╘.
╫.
╢.
╟.
╂.
┨.
┠.
┿.
┥.
┝.
╪.
╡.
╞.
Floyd-Steinberg dithering (the default).
No dithering.
One item per column.
As defined in CSS, items distributed within a column.
One item per row.
As defined in CSS, items distributed along a row.
The following special value will not be provided as a mouse action but indicate that an overridden mouse event was consumed.
Available mouse actions.
Available mouse actions.
Available mouse actions.
Available mouse actions.
Available mouse actions.
Available mouse actions.
Available mouse actions.
Available mouse actions.
Available mouse actions.
Available mouse actions.
Available mouse actions.
Available mouse actions.
Available mouse actions.
Available mouse actions.
Available mouse actions.
Available mouse actions.
Available mouse actions.
….
The number of colors supported by true color terminals (R*G*B = 256*256*256).

# Variables

Borders defines various borders used when primitives are drawn.
DefaultFormFieldHeight is the default field height of multi-line form elements whose field height is flexible (0).
DefaultFormFieldWidth is the default field screen width of form elements whose field width is flexible (0).
DoubleClickInterval specifies the maximum time between clicks to register a double click rather than click.
InputFieldFloat accepts floating-point numbers.
InputFieldInteger accepts integers.
InputFieldMaxLength returns an input field accept handler which accepts input strings up to a given length.
NewLine is the string sequence to be inserted when hitting the Enter key in a TextArea.
SemigraphicJoints is a map for joining semigraphic (or otherwise) runes.
Styles defines the theme for applications.
TabSize is the number of spaces with which a tab character will be replaced.

# Structs

Application represents the top node of an application.
Box implements the Primitive interface with an empty background and optional elements such as a border and a title.
Button is labeled box that triggers an action when selected.
Checkbox implements a simple box for boolean values which can be checked and unchecked.
DropDown implements a selection widget whose options become visible in a drop-down list when activated.
Flex is a basic implementation of the Flexbox layout.
Form allows you to combine multiple one-line form elements into a vertical or horizontal layout.
Frame is a wrapper which adds space around another primitive.
Grid is an implementation of a grid-based layout.
Image implements a widget that displays one image.
InputField is a one-line box into which the user can enter text.
List displays rows of items, each of which can be selected.
Modal is a centered message window used to inform the user or prompt them for an immediate decision.
Pages is a container for other primitives laid out on top of each other, overlapping or not.
Table visualizes two-dimensional data consisting of rows and columns.
TableCell represents one cell inside a Table.
TableContentReadOnly is an empty struct which implements the write operations of the TableContent interface.
TextArea implements a simple text editor for multi-line text.
TextView is a component to display read-only text.
TextViewWriter is a writer that can be used to write to and clear a TextView in batches, i.e.
Theme defines the colors used when primitives are initialized.
TreeNode represents one node in a tree view.
TreeView displays tree structures.

# Interfaces

FormItem is the interface all form items must implement to be able to be included in a form.
Primitive is the top-most interface for all graphical primitives.
TableContent defines a Table's data.

# Type aliases

MouseAction indicates one of the actions the mouse is logically doing.