Documentation ¶
Index ¶
- Constants
- Variables
- func ANSIWriter(writer io.Writer) io.Writer
- func TranslateANSI(text string) string
- type TextView
- func (t *TextView) Clear() *TextView
- func (t *TextView) Draw(screen tcell.Screen)
- func (t *TextView) Focus(delegate func(p tview.Primitive))
- func (t *TextView) GetHighlights() (regionIDs []string)
- func (t *TextView) GetRegionText(regionID string) string
- func (t *TextView) GetScrollOffset() (row, column int)
- func (t *TextView) GetText(stripTags bool) string
- func (t *TextView) HasFocus() bool
- func (t *TextView) Highlight(regionIDs ...string) *TextView
- func (t *TextView) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive))
- func (t *TextView) ScrollTo(row, column int) *TextView
- func (t *TextView) ScrollToBeginning() *TextView
- func (t *TextView) ScrollToEnd() *TextView
- func (t *TextView) ScrollToHighlight() *TextView
- func (t *TextView) SetChangedFunc(handler func()) *TextView
- func (t *TextView) SetDoneFunc(handler func(key tcell.Key)) *TextView
- func (t *TextView) SetDynamicColors(dynamic bool) *TextView
- func (t *TextView) SetRegions(regions bool) *TextView
- func (t *TextView) SetScrollable(scrollable bool) *TextView
- func (t *TextView) SetText(text string) *TextView
- func (t *TextView) SetTextAlign(align int) *TextView
- func (t *TextView) SetTextColor(color tcell.Color) *TextView
- func (t *TextView) SetWordWrap(wrapOnWords bool) *TextView
- func (t *TextView) SetWrap(wrap bool) *TextView
- func (t *TextView) Write(p []byte) (n int, err error)
- type UI
- type UIConfig
Constants ¶
const ( AlignLeft = iota AlignCenter AlignRight )
Variables ¶
var (
// TabSize is the number of spaces with which a tab character will be replaced.
TabSize = 4
)
Functions ¶
func ANSIWriter ¶
ANSIWriter returns an io.Writer which translates any ANSI escape codes written to it into tview color tags. Other escape codes don't have an effect and are simply removed. The translated text is written to the provided writer.
func TranslateANSI ¶
TranslateANSI replaces ANSI escape sequences found in the provided string with tview's color tags and returns the resulting string.
Types ¶
type TextView ¶
TextView is a box which displays text. It implements the io.Writer interface so you can stream text to it. This does not trigger a redraw automatically but if a handler is installed via SetChangedFunc(), you can cause it to be redrawn. (See SetChangedFunc() for more details.)
Navigation ¶
If the text view is scrollable (the default), text is kept in a buffer which may be larger than the screen and can be navigated similarly to Vim:
- h, left arrow: Move left.
- l, right arrow: Move right.
- j, down arrow: Move down.
- k, up arrow: Move up.
- g, home: Move to the top.
- G, end: Move to the bottom.
- Ctrl-F, page down: Move down by one page.
- Ctrl-B, page up: Move up by one page.
If the text is not scrollable, any text above the top visible line is discarded.
Use SetInputCapture() to override or modify keyboard input.
Colors ¶
If dynamic colors are enabled via SetDynamicColors(), text color can be changed dynamically by embedding color strings in square brackets. This works the same way as anywhere else. Please see the package documentation for more information.
Regions and Highlights ¶
If regions are enabled via SetRegions(), you can define text regions within the text and assign region IDs to them. Text regions start with region tags. Region tags are square brackets that contain a region ID in double quotes, for example:
We define a ["rg"]region[""] here.
A text region ends with the next region tag. Tags with no region ID ([""]) don't start new regions. They can therefore be used to mark the end of a region. Region IDs must satisfy the following regular expression:
[a-zA-Z0-9_,;: \-\.]+
Regions can be highlighted by calling the Highlight() function with one or more region IDs. This can be used to display search results, for example.
The ScrollToHighlight() function can be used to jump to the currently highlighted region once when the text view is drawn the next time.
See https://github.com/rivo/tview/wiki/TextView for an example.
func (*TextView) GetHighlights ¶
GetHighlights returns the IDs of all currently highlighted regions.
func (*TextView) GetRegionText ¶
GetRegionText returns the text of the region with the given ID. If dynamic colors are enabled, color tags are stripped from the text. Newlines are always returned as '\n' runes.
If the region does not exist or if regions are turned off, an empty string is returned.
func (*TextView) GetScrollOffset ¶
GetScrollOffset returns the number of rows and columns that are skipped at the top left corner when the text view has been scrolled.
func (*TextView) GetText ¶
GetText returns the current text of this text view. If "stripTags" is set to true, any region/color tags are stripped from the text.
func (*TextView) Highlight ¶
Highlight specifies which regions should be highlighted. See class description for details on regions. Empty region strings are ignored.
Text in highlighted regions will be drawn inverted, i.e. with their background and foreground colors swapped.
Calling this function will remove any previous highlights. To remove all highlights, call this function without any arguments.
func (*TextView) InputHandler ¶
InputHandler returns the handler for this primitive.
func (*TextView) ScrollTo ¶
ScrollTo scrolls to the specified row and column (both starting with 0).
func (*TextView) ScrollToBeginning ¶
ScrollToBeginning scrolls to the top left corner of the text if the text view is scrollable.
func (*TextView) ScrollToEnd ¶
ScrollToEnd scrolls to the bottom left corner of the text if the text view is scrollable. Adding new rows to the end of the text view will cause it to scroll with the new data.
func (*TextView) ScrollToHighlight ¶
ScrollToHighlight will cause the visible area to be scrolled so that the highlighted regions appear in the visible area of the text view. This repositioning happens the next time the text view is drawn. It happens only once so you will need to call this function repeatedly to always keep highlighted regions in view.
Nothing happens if there are no highlighted regions or if the text view is not scrollable.
func (*TextView) SetChangedFunc ¶
SetChangedFunc sets a handler function which is called when the text of the text view has changed. This is useful when text is written to this io.Writer in a separate goroutine. This does not automatically cause the screen to be refreshed so you may want to use the "changed" handler to redraw the screen.
Note that to avoid race conditions or deadlocks, there are a few rules you should follow:
- You can call Application.Draw() from this handler.
- You can call TextView.HasFocus() from this handler.
- During the execution of this handler, access to any other variables from this primitive or any other primitive should be queued using Application.QueueUpdate().
See package description for details on dealing with concurrency.
func (*TextView) SetDoneFunc ¶
SetDoneFunc sets a handler which is called when the user presses on the following keys: Escape, Enter, Tab, Backtab. The key is passed to the handler.
func (*TextView) SetDynamicColors ¶
SetDynamicColors sets the flag that allows the text color to be changed dynamically. See class description for details.
func (*TextView) SetRegions ¶
SetRegions sets the flag that allows to define regions in the text. See class description for details.
func (*TextView) SetScrollable ¶
SetScrollable sets the flag that decides whether or not the text view is scrollable. If true, text is kept in a buffer and can be navigated.
func (*TextView) SetText ¶
SetText sets the text of this text view to the provided string. Previously contained text will be removed.
func (*TextView) SetTextAlign ¶
SetTextAlign sets the text alignment within the text view. This must be either AlignLeft, AlignCenter, or AlignRight.
func (*TextView) SetTextColor ¶
SetTextColor sets the initial color of the text (which can be changed dynamically by sending color strings in square brackets to the text view if dynamic colors are enabled).
func (*TextView) SetWordWrap ¶
SetWordWrap sets the flag that, if true and if the "wrap" flag is also true (see SetWrap()), wraps the line at spaces or after punctuation marks. Note that trailing spaces will not be printed.
This flag is ignored if the "wrap" flag is false.
type UI ¶
type UI struct { printer.SimplePrinter // contains filtered or unexported fields }