2019-12-30 23:12:17 +00:00
|
|
|
package cview
|
2017-12-21 17:08:53 +00:00
|
|
|
|
|
|
|
import (
|
2017-12-23 23:08:52 +00:00
|
|
|
"bytes"
|
2017-12-21 17:08:53 +00:00
|
|
|
"regexp"
|
|
|
|
"sync"
|
2020-10-06 01:12:29 +00:00
|
|
|
"unicode"
|
2017-12-21 17:08:53 +00:00
|
|
|
"unicode/utf8"
|
|
|
|
|
2020-08-30 15:36:03 +00:00
|
|
|
"github.com/gdamore/tcell/v2"
|
2020-03-25 14:32:57 +00:00
|
|
|
"github.com/lucasb-eyer/go-colorful"
|
|
|
|
"github.com/mattn/go-runewidth"
|
2019-10-17 10:07:41 +00:00
|
|
|
"github.com/rivo/uniseg"
|
2017-12-21 17:08:53 +00:00
|
|
|
)
|
|
|
|
|
2019-02-11 16:01:48 +00:00
|
|
|
var (
|
2019-02-13 19:23:52 +00:00
|
|
|
// TabSize is the number of spaces with which a tab character will be replaced.
|
2019-02-11 16:01:48 +00:00
|
|
|
TabSize = 4
|
|
|
|
)
|
2018-01-12 12:25:30 +00:00
|
|
|
|
2021-06-05 17:24:43 +00:00
|
|
|
var (
|
|
|
|
openColorRegex = regexp.MustCompile(`\[([a-zA-Z]*|#[0-9a-zA-Z]*)$`)
|
|
|
|
openRegionRegex = regexp.MustCompile(`\["[a-zA-Z0-9_,;: \-\.]*"?$`)
|
|
|
|
)
|
|
|
|
|
2017-12-21 17:08:53 +00:00
|
|
|
// textViewIndex contains information about each line displayed in the text
|
|
|
|
// view.
|
|
|
|
type textViewIndex struct {
|
2018-04-13 22:05:25 +00:00
|
|
|
Line int // The index into the "buffer" variable.
|
2020-10-04 19:44:26 +00:00
|
|
|
Pos int // The index into the "buffer" line ([]byte position).
|
2018-04-13 22:05:25 +00:00
|
|
|
NextPos int // The (byte) index of the next character in this buffer line.
|
|
|
|
Width int // The screen width of this line.
|
|
|
|
ForegroundColor string // The starting foreground color ("" = don't change, "-" = reset).
|
|
|
|
BackgroundColor string // The starting background color ("" = don't change, "-" = reset).
|
|
|
|
Attributes string // The starting attributes ("" = don't change, "-" = reset).
|
2020-10-06 20:11:45 +00:00
|
|
|
Region []byte // The starting region ID.
|
2017-12-21 17:08:53 +00:00
|
|
|
}
|
|
|
|
|
2020-03-29 19:43:46 +00:00
|
|
|
// textViewRegion contains information about a region.
|
|
|
|
type textViewRegion struct {
|
|
|
|
// The region ID.
|
2020-10-06 20:11:45 +00:00
|
|
|
ID []byte
|
2020-03-29 19:43:46 +00:00
|
|
|
|
|
|
|
// The starting and end screen position of the region as determined the last
|
|
|
|
// time Draw() was called. A negative value indicates out-of-rect positions.
|
|
|
|
FromX, FromY, ToX, ToY int
|
|
|
|
}
|
|
|
|
|
2017-12-23 23:08:52 +00:00
|
|
|
// 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
|
2018-10-28 12:42:49 +00:00
|
|
|
// redrawn. (See SetChangedFunc() for more details.)
|
2017-12-23 23:08:52 +00:00
|
|
|
//
|
|
|
|
// Navigation
|
2017-12-21 17:08:53 +00:00
|
|
|
//
|
2017-12-23 23:08:52 +00:00
|
|
|
// 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.
|
2017-12-26 00:07:30 +00:00
|
|
|
// - g, home: Move to the top.
|
|
|
|
// - G, end: Move to the bottom.
|
2017-12-23 23:08:52 +00:00
|
|
|
// - Ctrl-F, page down: Move down by one page.
|
|
|
|
// - Ctrl-B, page up: Move up by one page.
|
2017-12-21 17:08:53 +00:00
|
|
|
//
|
2017-12-29 17:45:52 +00:00
|
|
|
// If the text is not scrollable, any text above the top visible line is
|
|
|
|
// discarded.
|
2017-12-21 17:08:53 +00:00
|
|
|
//
|
2018-01-17 16:13:36 +00:00
|
|
|
// Use SetInputCapture() to override or modify keyboard input.
|
2017-12-23 23:08:52 +00:00
|
|
|
//
|
|
|
|
// Colors
|
2017-12-21 17:08:53 +00:00
|
|
|
//
|
2017-12-23 23:08:52 +00:00
|
|
|
// If dynamic colors are enabled via SetDynamicColors(), text color can be
|
2018-01-17 16:13:36 +00:00
|
|
|
// 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.
|
2017-12-23 23:08:52 +00:00
|
|
|
//
|
|
|
|
// 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.
|
2017-12-21 17:08:53 +00:00
|
|
|
type TextView struct {
|
|
|
|
*Box
|
|
|
|
|
|
|
|
// The text buffer.
|
2020-10-04 19:44:26 +00:00
|
|
|
buffer [][]byte
|
2017-12-21 17:08:53 +00:00
|
|
|
|
2017-12-23 23:08:52 +00:00
|
|
|
// The last bytes that have been received but are not part of the buffer yet.
|
|
|
|
recentBytes []byte
|
|
|
|
|
2020-10-21 17:26:30 +00:00
|
|
|
// The last width and height of the text view.
|
|
|
|
lastWidth, lastHeight int
|
|
|
|
|
2017-12-21 17:08:53 +00:00
|
|
|
// The processed line index. This is nil if the buffer has changed and needs
|
|
|
|
// to be re-indexed.
|
|
|
|
index []*textViewIndex
|
|
|
|
|
2020-10-21 17:26:30 +00:00
|
|
|
// The width of the text view buffer index.
|
|
|
|
indexWidth int
|
|
|
|
|
2020-09-04 02:23:56 +00:00
|
|
|
// If set to true, the buffer will be reindexed each time it is modified.
|
|
|
|
reindex bool
|
|
|
|
|
2021-07-05 19:52:52 +00:00
|
|
|
// The horizontal text alignment, one of AlignLeft, AlignCenter, or AlignRight.
|
2018-01-13 13:16:49 +00:00
|
|
|
align int
|
|
|
|
|
2021-07-05 19:52:52 +00:00
|
|
|
// The vertical text alignment, one of AlignTop, AlignMiddle, or AlignBottom.
|
|
|
|
valign VerticalAlignment
|
|
|
|
|
2020-03-29 19:43:46 +00:00
|
|
|
// Information about visible regions as of the last call to Draw().
|
|
|
|
regionInfos []*textViewRegion
|
|
|
|
|
2017-12-23 23:08:52 +00:00
|
|
|
// Indices into the "index" slice which correspond to the first line of the
|
|
|
|
// first highlight and the last line of the last highlight. This is calculated
|
|
|
|
// during re-indexing. Set to -1 if there is no current highlight.
|
|
|
|
fromHighlight, toHighlight int
|
|
|
|
|
2018-06-20 08:06:05 +00:00
|
|
|
// The screen space column of the highlight in its first line. Set to -1 if
|
|
|
|
// there is no current highlight.
|
|
|
|
posHighlight int
|
|
|
|
|
2017-12-23 23:08:52 +00:00
|
|
|
// A set of region IDs that are currently highlighted.
|
|
|
|
highlights map[string]struct{}
|
|
|
|
|
2018-01-13 13:16:49 +00:00
|
|
|
// The screen width of the longest line in the index (not the buffer).
|
2017-12-29 17:45:52 +00:00
|
|
|
longestLine int
|
|
|
|
|
2017-12-21 17:08:53 +00:00
|
|
|
// The index of the first line shown in the text view.
|
|
|
|
lineOffset int
|
|
|
|
|
2020-05-15 21:56:19 +00:00
|
|
|
// The maximum number of newlines the text view will hold (0 = unlimited).
|
2020-05-15 16:52:20 +00:00
|
|
|
maxLines int
|
|
|
|
|
2017-12-21 17:08:53 +00:00
|
|
|
// If set to true, the text view will always remain at the end of the content.
|
|
|
|
trackEnd bool
|
|
|
|
|
|
|
|
// The number of characters to be skipped on each line (not in wrap mode).
|
|
|
|
columnOffset int
|
|
|
|
|
|
|
|
// The height of the content the last time the text view was drawn.
|
|
|
|
pageSize int
|
|
|
|
|
|
|
|
// If set to true, the text view will keep a buffer of text which can be
|
|
|
|
// navigated when the text is longer than what fits into the box.
|
|
|
|
scrollable bool
|
|
|
|
|
2020-09-23 01:43:19 +00:00
|
|
|
// Visibility of the scroll bar.
|
|
|
|
scrollBarVisibility ScrollBarVisibility
|
|
|
|
|
|
|
|
// The scroll bar color.
|
|
|
|
scrollBarColor tcell.Color
|
|
|
|
|
2017-12-21 17:08:53 +00:00
|
|
|
// If set to true, lines that are longer than the available width are wrapped
|
|
|
|
// onto the next line. If set to false, any characters beyond the available
|
|
|
|
// width are discarded.
|
|
|
|
wrap bool
|
|
|
|
|
2020-11-03 18:29:07 +00:00
|
|
|
// The maximum line width when wrapping (0 = use TextView width).
|
|
|
|
wrapWidth int
|
|
|
|
|
2018-01-13 13:16:49 +00:00
|
|
|
// If set to true and if wrap is also true, lines are split at spaces or
|
|
|
|
// after punctuation characters.
|
|
|
|
wordWrap bool
|
|
|
|
|
2017-12-21 17:08:53 +00:00
|
|
|
// The (starting) color of the text.
|
|
|
|
textColor tcell.Color
|
|
|
|
|
2021-05-31 01:17:17 +00:00
|
|
|
// The foreground color of highlighted text.
|
|
|
|
highlightForeground tcell.Color
|
|
|
|
|
|
|
|
// The background color of highlighted text.
|
|
|
|
highlightBackground tcell.Color
|
|
|
|
|
2017-12-21 17:08:53 +00:00
|
|
|
// If set to true, the text color can be changed dynamically by piping color
|
|
|
|
// strings in square brackets to the text view.
|
|
|
|
dynamicColors bool
|
|
|
|
|
2017-12-23 23:08:52 +00:00
|
|
|
// If set to true, region tags can be used to define regions.
|
|
|
|
regions bool
|
|
|
|
|
|
|
|
// A temporary flag which, when true, will automatically bring the current
|
|
|
|
// highlight(s) into the visible screen.
|
|
|
|
scrollToHighlights bool
|
|
|
|
|
2020-03-29 19:43:46 +00:00
|
|
|
// If true, setting new highlights will be a XOR instead of an overwrite
|
|
|
|
// operation.
|
|
|
|
toggleHighlights bool
|
|
|
|
|
2017-12-21 17:08:53 +00:00
|
|
|
// An optional function which is called when the content of the text view has
|
|
|
|
// changed.
|
|
|
|
changed func()
|
|
|
|
|
|
|
|
// An optional function which is called when the user presses one of the
|
|
|
|
// following keys: Escape, Enter, Tab, Backtab.
|
|
|
|
done func(tcell.Key)
|
2020-03-26 15:54:12 +00:00
|
|
|
|
2020-03-29 19:43:46 +00:00
|
|
|
// An optional function which is called when one or more regions were
|
|
|
|
// highlighted.
|
|
|
|
highlighted func(added, removed, remaining []string)
|
|
|
|
|
2020-03-26 15:54:12 +00:00
|
|
|
sync.RWMutex
|
2017-12-21 17:08:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewTextView returns a new text view.
|
|
|
|
func NewTextView() *TextView {
|
|
|
|
return &TextView{
|
2020-10-21 16:36:23 +00:00
|
|
|
Box: NewBox(),
|
|
|
|
highlights: make(map[string]struct{}),
|
|
|
|
lineOffset: -1,
|
|
|
|
reindex: true,
|
|
|
|
scrollable: true,
|
|
|
|
scrollBarVisibility: ScrollBarAuto,
|
|
|
|
scrollBarColor: Styles.ScrollBarColor,
|
|
|
|
align: AlignLeft,
|
2021-07-05 19:52:52 +00:00
|
|
|
valign: AlignTop,
|
2020-10-21 16:36:23 +00:00
|
|
|
wrap: true,
|
|
|
|
textColor: Styles.PrimaryTextColor,
|
2021-05-31 01:17:17 +00:00
|
|
|
highlightForeground: Styles.PrimitiveBackgroundColor,
|
|
|
|
highlightBackground: Styles.PrimaryTextColor,
|
2017-12-21 17:08:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetScrollable sets the flag that decides whether or not the text view is
|
2019-10-18 11:56:45 +00:00
|
|
|
// scrollable. If true, text is kept in a buffer and can be navigated. If false,
|
|
|
|
// the last line will always be visible.
|
2020-10-07 23:34:21 +00:00
|
|
|
func (t *TextView) SetScrollable(scrollable bool) {
|
2020-03-25 14:32:57 +00:00
|
|
|
t.Lock()
|
|
|
|
defer t.Unlock()
|
|
|
|
|
2017-12-21 17:08:53 +00:00
|
|
|
t.scrollable = scrollable
|
2017-12-30 21:09:36 +00:00
|
|
|
if !scrollable {
|
|
|
|
t.trackEnd = true
|
|
|
|
}
|
2017-12-21 17:08:53 +00:00
|
|
|
}
|
|
|
|
|
2020-09-23 01:43:19 +00:00
|
|
|
// SetScrollBarVisibility specifies the display of the scroll bar.
|
2020-10-07 23:34:21 +00:00
|
|
|
func (t *TextView) SetScrollBarVisibility(visibility ScrollBarVisibility) {
|
2020-09-23 01:43:19 +00:00
|
|
|
t.Lock()
|
|
|
|
defer t.Unlock()
|
|
|
|
|
|
|
|
t.scrollBarVisibility = visibility
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetScrollBarColor sets the color of the scroll bar.
|
2020-10-07 23:34:21 +00:00
|
|
|
func (t *TextView) SetScrollBarColor(color tcell.Color) {
|
2020-09-23 01:43:19 +00:00
|
|
|
t.Lock()
|
|
|
|
defer t.Unlock()
|
|
|
|
|
|
|
|
t.scrollBarColor = color
|
|
|
|
}
|
|
|
|
|
2017-12-21 17:08:53 +00:00
|
|
|
// SetWrap sets the flag that, if true, leads to lines that are longer than the
|
|
|
|
// available width being wrapped onto the next line. If false, any characters
|
|
|
|
// beyond the available width are not displayed.
|
2020-10-07 23:34:21 +00:00
|
|
|
func (t *TextView) SetWrap(wrap bool) {
|
2020-03-25 14:32:57 +00:00
|
|
|
t.Lock()
|
|
|
|
defer t.Unlock()
|
|
|
|
|
2017-12-21 17:08:53 +00:00
|
|
|
if t.wrap != wrap {
|
|
|
|
t.index = nil
|
|
|
|
}
|
|
|
|
t.wrap = wrap
|
|
|
|
}
|
|
|
|
|
2018-01-13 13:16:49 +00:00
|
|
|
// 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.
|
2020-10-07 23:34:21 +00:00
|
|
|
func (t *TextView) SetWordWrap(wrapOnWords bool) {
|
2020-03-25 14:32:57 +00:00
|
|
|
t.Lock()
|
|
|
|
defer t.Unlock()
|
|
|
|
|
2018-01-13 13:16:49 +00:00
|
|
|
if t.wordWrap != wrapOnWords {
|
|
|
|
t.index = nil
|
|
|
|
}
|
|
|
|
t.wordWrap = wrapOnWords
|
|
|
|
}
|
|
|
|
|
2021-07-05 19:52:52 +00:00
|
|
|
// SetTextAlign sets the horizontal alignment of the text. This must be either
|
|
|
|
// AlignLeft, AlignCenter, or AlignRight.
|
2020-10-07 23:34:21 +00:00
|
|
|
func (t *TextView) SetTextAlign(align int) {
|
2020-03-25 14:32:57 +00:00
|
|
|
t.Lock()
|
|
|
|
defer t.Unlock()
|
|
|
|
|
2018-01-13 13:16:49 +00:00
|
|
|
if t.align != align {
|
|
|
|
t.index = nil
|
|
|
|
}
|
|
|
|
t.align = align
|
|
|
|
}
|
|
|
|
|
2021-07-05 19:52:52 +00:00
|
|
|
// SetVerticalAlign sets the vertical alignment of the text. This must be
|
|
|
|
// either AlignTop, AlignMiddle, or AlignBottom.
|
|
|
|
func (t *TextView) SetVerticalAlign(valign VerticalAlignment) {
|
|
|
|
t.Lock()
|
|
|
|
defer t.Unlock()
|
|
|
|
|
|
|
|
if t.valign != valign {
|
|
|
|
t.index = nil
|
|
|
|
}
|
|
|
|
t.valign = valign
|
|
|
|
}
|
|
|
|
|
2017-12-21 17:08:53 +00:00
|
|
|
// 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).
|
2020-10-07 23:34:21 +00:00
|
|
|
func (t *TextView) SetTextColor(color tcell.Color) {
|
2020-03-25 14:32:57 +00:00
|
|
|
t.Lock()
|
|
|
|
defer t.Unlock()
|
|
|
|
|
2017-12-21 17:08:53 +00:00
|
|
|
t.textColor = color
|
|
|
|
}
|
|
|
|
|
2021-05-31 01:17:17 +00:00
|
|
|
// SetHighlightForegroundColor sets the foreground color of highlighted text.
|
|
|
|
func (t *TextView) SetHighlightForegroundColor(color tcell.Color) {
|
|
|
|
t.Lock()
|
|
|
|
defer t.Unlock()
|
|
|
|
|
|
|
|
t.highlightForeground = color
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetHighlightBackgroundColor sets the foreground color of highlighted text.
|
|
|
|
func (t *TextView) SetHighlightBackgroundColor(color tcell.Color) {
|
|
|
|
t.Lock()
|
|
|
|
defer t.Unlock()
|
|
|
|
|
|
|
|
t.highlightBackground = color
|
|
|
|
}
|
|
|
|
|
2020-10-04 20:03:28 +00:00
|
|
|
// SetBytes sets the text of this text view to the provided byte slice.
|
|
|
|
// Previously contained text will be removed.
|
2020-10-07 23:34:21 +00:00
|
|
|
func (t *TextView) SetBytes(text []byte) {
|
2020-03-26 15:54:12 +00:00
|
|
|
t.Lock()
|
|
|
|
defer t.Unlock()
|
|
|
|
|
|
|
|
t.clear()
|
2020-10-04 20:03:28 +00:00
|
|
|
t.write(text)
|
2018-02-20 10:19:30 +00:00
|
|
|
}
|
|
|
|
|
2020-10-04 20:03:28 +00:00
|
|
|
// SetText sets the text of this text view to the provided string. Previously
|
|
|
|
// contained text will be removed.
|
2020-10-07 23:34:21 +00:00
|
|
|
func (t *TextView) SetText(text string) {
|
|
|
|
t.SetBytes([]byte(text))
|
2020-10-04 20:03:28 +00:00
|
|
|
}
|
|
|
|
|
2020-10-04 19:54:31 +00:00
|
|
|
// GetBytes returns the current text of this text view. If "stripTags" is set
|
2019-02-13 15:36:28 +00:00
|
|
|
// to true, any region/color tags are stripped from the text.
|
2020-10-04 19:54:31 +00:00
|
|
|
func (t *TextView) GetBytes(stripTags bool) []byte {
|
2020-03-25 14:32:57 +00:00
|
|
|
t.RLock()
|
|
|
|
defer t.RUnlock()
|
|
|
|
|
2019-02-13 15:36:28 +00:00
|
|
|
if !stripTags {
|
2020-10-04 19:44:26 +00:00
|
|
|
if len(t.recentBytes) > 0 {
|
|
|
|
return bytes.Join(append(t.buffer, t.recentBytes), []byte("\n"))
|
2019-02-13 15:36:28 +00:00
|
|
|
}
|
2020-10-04 19:44:26 +00:00
|
|
|
return bytes.Join(t.buffer, []byte("\n"))
|
2019-02-13 15:36:28 +00:00
|
|
|
}
|
|
|
|
|
2020-10-04 19:44:26 +00:00
|
|
|
buffer := bytes.Join(t.buffer, []byte("\n"))
|
2020-10-19 16:55:07 +00:00
|
|
|
return StripTags(buffer, t.dynamicColors, t.regions)
|
2019-02-13 15:36:28 +00:00
|
|
|
}
|
|
|
|
|
2020-10-04 19:54:31 +00:00
|
|
|
// 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 (t *TextView) GetText(stripTags bool) string {
|
|
|
|
return string(t.GetBytes(stripTags))
|
|
|
|
}
|
|
|
|
|
2021-03-27 21:36:53 +00:00
|
|
|
// GetBufferSize returns the number of lines and the length of the longest line
|
|
|
|
// in the text buffer. The screen size of the widget is available via GetRect.
|
|
|
|
func (t *TextView) GetBufferSize() (rows int, maxLen int) {
|
|
|
|
t.RLock()
|
|
|
|
defer t.RUnlock()
|
|
|
|
|
2021-04-02 00:35:06 +00:00
|
|
|
return len(t.buffer), t.longestLine
|
2021-03-27 21:36:53 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 17:08:53 +00:00
|
|
|
// SetDynamicColors sets the flag that allows the text color to be changed
|
2017-12-23 23:08:52 +00:00
|
|
|
// dynamically. See class description for details.
|
2020-10-07 23:34:21 +00:00
|
|
|
func (t *TextView) SetDynamicColors(dynamic bool) {
|
2020-03-25 14:32:57 +00:00
|
|
|
t.Lock()
|
|
|
|
defer t.Unlock()
|
|
|
|
|
2017-12-21 17:08:53 +00:00
|
|
|
if t.dynamicColors != dynamic {
|
|
|
|
t.index = nil
|
|
|
|
}
|
|
|
|
t.dynamicColors = dynamic
|
|
|
|
}
|
|
|
|
|
2017-12-23 23:08:52 +00:00
|
|
|
// SetRegions sets the flag that allows to define regions in the text. See class
|
|
|
|
// description for details.
|
2020-10-07 23:34:21 +00:00
|
|
|
func (t *TextView) SetRegions(regions bool) {
|
2020-03-25 14:32:57 +00:00
|
|
|
t.Lock()
|
|
|
|
defer t.Unlock()
|
|
|
|
|
2018-01-13 13:16:49 +00:00
|
|
|
if t.regions != regions {
|
|
|
|
t.index = nil
|
|
|
|
}
|
2017-12-23 23:08:52 +00:00
|
|
|
t.regions = regions
|
|
|
|
}
|
|
|
|
|
2017-12-21 17:08:53 +00:00
|
|
|
// SetChangedFunc sets a handler function which is called when the text of the
|
2018-10-28 12:42:49 +00:00
|
|
|
// text view has changed. This is useful when text is written to this io.Writer
|
2019-11-27 17:27:26 +00:00
|
|
|
// in a separate goroutine. Doing so does not automatically cause the screen to
|
|
|
|
// be refreshed so you may want to use the "changed" handler to redraw the
|
|
|
|
// screen.
|
2018-10-28 12:42:49 +00:00
|
|
|
//
|
|
|
|
// 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.
|
2020-10-07 23:34:21 +00:00
|
|
|
func (t *TextView) SetChangedFunc(handler func()) {
|
2020-03-25 14:32:57 +00:00
|
|
|
t.Lock()
|
|
|
|
defer t.Unlock()
|
|
|
|
|
2017-12-21 17:08:53 +00:00
|
|
|
t.changed = handler
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2020-10-07 23:34:21 +00:00
|
|
|
func (t *TextView) SetDoneFunc(handler func(key tcell.Key)) {
|
2020-03-25 14:32:57 +00:00
|
|
|
t.Lock()
|
|
|
|
defer t.Unlock()
|
|
|
|
|
2017-12-21 17:08:53 +00:00
|
|
|
t.done = handler
|
|
|
|
}
|
|
|
|
|
2020-03-29 19:43:46 +00:00
|
|
|
// SetHighlightedFunc sets a handler which is called when the list of currently
|
|
|
|
// highlighted regions change. It receives a list of region IDs which were newly
|
|
|
|
// highlighted, those that are not highlighted anymore, and those that remain
|
|
|
|
// highlighted.
|
|
|
|
//
|
|
|
|
// Note that because regions are only determined during drawing, this function
|
|
|
|
// can only fire for regions that have existed during the last call to Draw().
|
2020-10-07 23:34:21 +00:00
|
|
|
func (t *TextView) SetHighlightedFunc(handler func(added, removed, remaining []string)) {
|
2020-03-29 19:43:46 +00:00
|
|
|
t.highlighted = handler
|
|
|
|
}
|
|
|
|
|
2020-05-15 16:52:20 +00:00
|
|
|
func (t *TextView) clipBuffer() {
|
2020-05-15 21:56:19 +00:00
|
|
|
if t.maxLines <= 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
lenbuf := len(t.buffer)
|
|
|
|
if lenbuf > t.maxLines {
|
|
|
|
t.buffer = t.buffer[lenbuf-t.maxLines:]
|
2020-05-15 16:52:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 21:56:19 +00:00
|
|
|
// SetMaxLines sets the maximum number of newlines the text view will hold
|
|
|
|
// before discarding older data from the buffer.
|
2020-10-07 23:34:21 +00:00
|
|
|
func (t *TextView) SetMaxLines(maxLines int) {
|
2020-05-15 16:52:20 +00:00
|
|
|
t.maxLines = maxLines
|
|
|
|
t.clipBuffer()
|
|
|
|
}
|
|
|
|
|
2018-05-28 19:27:25 +00:00
|
|
|
// ScrollTo scrolls to the specified row and column (both starting with 0).
|
2020-10-07 23:34:21 +00:00
|
|
|
func (t *TextView) ScrollTo(row, column int) {
|
2020-03-25 14:32:57 +00:00
|
|
|
t.Lock()
|
|
|
|
defer t.Unlock()
|
|
|
|
|
2018-05-28 19:27:25 +00:00
|
|
|
if !t.scrollable {
|
2020-10-07 23:34:21 +00:00
|
|
|
return
|
2018-05-28 19:27:25 +00:00
|
|
|
}
|
|
|
|
t.lineOffset = row
|
|
|
|
t.columnOffset = column
|
2019-05-14 15:07:36 +00:00
|
|
|
t.trackEnd = false
|
2018-05-28 19:27:25 +00:00
|
|
|
}
|
|
|
|
|
2018-01-14 12:35:57 +00:00
|
|
|
// ScrollToBeginning scrolls to the top left corner of the text if the text view
|
|
|
|
// is scrollable.
|
2020-10-07 23:34:21 +00:00
|
|
|
func (t *TextView) ScrollToBeginning() {
|
2020-03-25 14:32:57 +00:00
|
|
|
t.Lock()
|
|
|
|
defer t.Unlock()
|
|
|
|
|
2018-01-14 12:35:57 +00:00
|
|
|
if !t.scrollable {
|
2020-10-07 23:34:21 +00:00
|
|
|
return
|
2018-01-14 12:35:57 +00:00
|
|
|
}
|
2018-01-14 10:36:27 +00:00
|
|
|
t.trackEnd = false
|
|
|
|
t.lineOffset = 0
|
|
|
|
t.columnOffset = 0
|
|
|
|
}
|
|
|
|
|
2018-01-14 12:35:57 +00:00
|
|
|
// 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.
|
2020-10-07 23:34:21 +00:00
|
|
|
func (t *TextView) ScrollToEnd() {
|
2020-03-25 14:32:57 +00:00
|
|
|
t.Lock()
|
|
|
|
defer t.Unlock()
|
|
|
|
|
2018-01-14 12:35:57 +00:00
|
|
|
if !t.scrollable {
|
2020-10-07 23:34:21 +00:00
|
|
|
return
|
2018-01-14 12:35:57 +00:00
|
|
|
}
|
2018-01-14 10:36:27 +00:00
|
|
|
t.trackEnd = true
|
|
|
|
t.columnOffset = 0
|
|
|
|
}
|
|
|
|
|
2018-07-28 19:30:50 +00:00
|
|
|
// GetScrollOffset returns the number of rows and columns that are skipped at
|
|
|
|
// the top left corner when the text view has been scrolled.
|
|
|
|
func (t *TextView) GetScrollOffset() (row, column int) {
|
2020-03-25 14:32:57 +00:00
|
|
|
t.RLock()
|
|
|
|
defer t.RUnlock()
|
|
|
|
|
2018-07-28 19:30:50 +00:00
|
|
|
return t.lineOffset, t.columnOffset
|
|
|
|
}
|
|
|
|
|
2017-12-21 17:08:53 +00:00
|
|
|
// Clear removes all text from the buffer.
|
2020-10-07 23:34:21 +00:00
|
|
|
func (t *TextView) Clear() {
|
2020-03-25 14:32:57 +00:00
|
|
|
t.Lock()
|
|
|
|
defer t.Unlock()
|
|
|
|
|
2020-10-07 23:34:21 +00:00
|
|
|
t.clear()
|
2020-03-26 15:54:12 +00:00
|
|
|
}
|
|
|
|
|
2020-10-07 23:34:21 +00:00
|
|
|
func (t *TextView) clear() {
|
2017-12-21 17:08:53 +00:00
|
|
|
t.buffer = nil
|
|
|
|
t.recentBytes = nil
|
2020-09-04 02:23:56 +00:00
|
|
|
if t.reindex {
|
|
|
|
t.index = nil
|
|
|
|
}
|
2017-12-21 17:08:53 +00:00
|
|
|
}
|
|
|
|
|
2020-03-29 19:43:46 +00:00
|
|
|
// Highlight specifies which regions should be highlighted. If highlight
|
|
|
|
// toggling is set to true (see SetToggleHighlights()), the highlight of the
|
|
|
|
// provided regions is toggled (highlighted regions are un-highlighted and vice
|
|
|
|
// versa). If toggling is set to false, the provided regions are highlighted and
|
|
|
|
// all other regions will not be highlighted (you may also provide nil to turn
|
|
|
|
// off all highlights).
|
|
|
|
//
|
|
|
|
// For more information on regions, see class description. Empty region strings
|
|
|
|
// are ignored.
|
2017-12-23 23:08:52 +00:00
|
|
|
//
|
|
|
|
// Text in highlighted regions will be drawn inverted, i.e. with their
|
|
|
|
// background and foreground colors swapped.
|
2020-10-07 23:34:21 +00:00
|
|
|
func (t *TextView) Highlight(regionIDs ...string) {
|
2020-03-25 14:32:57 +00:00
|
|
|
t.Lock()
|
|
|
|
|
2020-03-29 19:43:46 +00:00
|
|
|
// Toggle highlights.
|
|
|
|
if t.toggleHighlights {
|
|
|
|
var newIDs []string
|
|
|
|
HighlightLoop:
|
|
|
|
for regionID := range t.highlights {
|
|
|
|
for _, id := range regionIDs {
|
|
|
|
if regionID == id {
|
|
|
|
continue HighlightLoop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
newIDs = append(newIDs, regionID)
|
|
|
|
}
|
|
|
|
for _, regionID := range regionIDs {
|
|
|
|
if _, ok := t.highlights[regionID]; !ok {
|
|
|
|
newIDs = append(newIDs, regionID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
regionIDs = newIDs
|
|
|
|
} // Now we have a list of region IDs that end up being highlighted.
|
|
|
|
|
|
|
|
// Determine added and removed regions.
|
|
|
|
var added, removed, remaining []string
|
|
|
|
if t.highlighted != nil {
|
|
|
|
for _, regionID := range regionIDs {
|
|
|
|
if _, ok := t.highlights[regionID]; ok {
|
|
|
|
remaining = append(remaining, regionID)
|
|
|
|
delete(t.highlights, regionID)
|
|
|
|
} else {
|
|
|
|
added = append(added, regionID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for regionID := range t.highlights {
|
|
|
|
removed = append(removed, regionID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make new selection.
|
2017-12-23 23:08:52 +00:00
|
|
|
t.highlights = make(map[string]struct{})
|
|
|
|
for _, id := range regionIDs {
|
|
|
|
if id == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
t.highlights[id] = struct{}{}
|
|
|
|
}
|
2018-01-13 13:16:49 +00:00
|
|
|
t.index = nil
|
2020-03-29 19:43:46 +00:00
|
|
|
|
|
|
|
// Notify.
|
2020-10-11 19:07:30 +00:00
|
|
|
if t.highlighted != nil && (len(added) > 0 || len(removed) > 0) {
|
2020-04-01 15:59:06 +00:00
|
|
|
t.Unlock()
|
2020-03-29 19:43:46 +00:00
|
|
|
t.highlighted(added, removed, remaining)
|
2020-04-01 15:59:06 +00:00
|
|
|
} else {
|
|
|
|
t.Unlock()
|
2020-03-29 19:43:46 +00:00
|
|
|
}
|
2017-12-23 23:08:52 +00:00
|
|
|
}
|
|
|
|
|
2017-12-27 15:04:21 +00:00
|
|
|
// GetHighlights returns the IDs of all currently highlighted regions.
|
|
|
|
func (t *TextView) GetHighlights() (regionIDs []string) {
|
2020-03-25 14:32:57 +00:00
|
|
|
t.RLock()
|
|
|
|
defer t.RUnlock()
|
|
|
|
|
2017-12-27 15:04:21 +00:00
|
|
|
for id := range t.highlights {
|
|
|
|
regionIDs = append(regionIDs, id)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-03-29 19:43:46 +00:00
|
|
|
// SetToggleHighlights sets a flag to determine how regions are highlighted.
|
|
|
|
// When set to true, the Highlight() function (or a mouse click) will toggle the
|
|
|
|
// provided/selected regions. When set to false, Highlight() (or a mouse click)
|
|
|
|
// will simply highlight the provided regions.
|
2020-10-07 23:34:21 +00:00
|
|
|
func (t *TextView) SetToggleHighlights(toggle bool) {
|
2020-03-29 19:43:46 +00:00
|
|
|
t.toggleHighlights = toggle
|
|
|
|
}
|
|
|
|
|
2017-12-23 23:08:52 +00:00
|
|
|
// 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.
|
2020-10-07 23:34:21 +00:00
|
|
|
func (t *TextView) ScrollToHighlight() {
|
2020-03-25 14:32:57 +00:00
|
|
|
t.Lock()
|
|
|
|
defer t.Unlock()
|
|
|
|
|
2017-12-23 23:08:52 +00:00
|
|
|
if len(t.highlights) == 0 || !t.scrollable || !t.regions {
|
2020-10-07 23:34:21 +00:00
|
|
|
return
|
2017-12-23 23:08:52 +00:00
|
|
|
}
|
|
|
|
t.index = nil
|
|
|
|
t.scrollToHighlights = true
|
|
|
|
t.trackEnd = false
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 (t *TextView) GetRegionText(regionID string) string {
|
2020-03-25 14:32:57 +00:00
|
|
|
t.RLock()
|
|
|
|
defer t.RUnlock()
|
|
|
|
|
2020-10-04 19:44:26 +00:00
|
|
|
if !t.regions || len(regionID) == 0 {
|
2017-12-23 23:08:52 +00:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
buffer bytes.Buffer
|
|
|
|
currentRegionID string
|
|
|
|
)
|
|
|
|
|
|
|
|
for _, str := range t.buffer {
|
|
|
|
// Find all color tags in this line.
|
|
|
|
var colorTagIndices [][]int
|
|
|
|
if t.dynamicColors {
|
2020-10-04 19:44:26 +00:00
|
|
|
colorTagIndices = colorPattern.FindAllIndex(str, -1)
|
2017-12-23 23:08:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Find all regions in this line.
|
|
|
|
var (
|
|
|
|
regionIndices [][]int
|
2020-10-04 19:44:26 +00:00
|
|
|
regions [][][]byte
|
2017-12-23 23:08:52 +00:00
|
|
|
)
|
|
|
|
if t.regions {
|
2020-10-04 19:44:26 +00:00
|
|
|
regionIndices = regionPattern.FindAllIndex(str, -1)
|
|
|
|
regions = regionPattern.FindAllSubmatch(str, -1)
|
2017-12-23 23:08:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Analyze this line.
|
|
|
|
var currentTag, currentRegion int
|
|
|
|
for pos, ch := range str {
|
|
|
|
// Skip any color tags.
|
|
|
|
if currentTag < len(colorTagIndices) && pos >= colorTagIndices[currentTag][0] && pos < colorTagIndices[currentTag][1] {
|
|
|
|
if pos == colorTagIndices[currentTag][1]-1 {
|
|
|
|
currentTag++
|
|
|
|
}
|
2020-07-12 11:34:19 +00:00
|
|
|
if colorTagIndices[currentTag][1]-colorTagIndices[currentTag][0] > 2 {
|
|
|
|
continue
|
|
|
|
}
|
2017-12-23 23:08:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Skip any regions.
|
|
|
|
if currentRegion < len(regionIndices) && pos >= regionIndices[currentRegion][0] && pos < regionIndices[currentRegion][1] {
|
|
|
|
if pos == regionIndices[currentRegion][1]-1 {
|
|
|
|
if currentRegionID == regionID {
|
|
|
|
// This is the end of the requested region. We're done.
|
|
|
|
return buffer.String()
|
|
|
|
}
|
2020-10-04 19:44:26 +00:00
|
|
|
currentRegionID = string(regions[currentRegion][1])
|
2017-12-23 23:08:52 +00:00
|
|
|
currentRegion++
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add this rune.
|
|
|
|
if currentRegionID == regionID {
|
2020-10-04 19:44:26 +00:00
|
|
|
buffer.WriteByte(ch)
|
2017-12-23 23:08:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add newline.
|
|
|
|
if currentRegionID == regionID {
|
|
|
|
buffer.WriteRune('\n')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-17 09:09:09 +00:00
|
|
|
return escapePattern.ReplaceAllString(buffer.String(), `[$1$2]`)
|
2017-12-23 23:08:52 +00:00
|
|
|
}
|
|
|
|
|
2018-10-28 12:42:49 +00:00
|
|
|
// Focus is called when this primitive receives focus.
|
|
|
|
func (t *TextView) Focus(delegate func(p Primitive)) {
|
|
|
|
t.Lock()
|
|
|
|
defer t.Unlock()
|
2020-03-25 14:32:57 +00:00
|
|
|
|
|
|
|
// Implemented here with locking because this is used by layout primitives.
|
2018-10-28 12:42:49 +00:00
|
|
|
t.hasFocus = true
|
|
|
|
}
|
|
|
|
|
|
|
|
// HasFocus returns whether or not this primitive has focus.
|
|
|
|
func (t *TextView) HasFocus() bool {
|
2020-03-25 14:32:57 +00:00
|
|
|
t.RLock()
|
|
|
|
defer t.RUnlock()
|
|
|
|
|
2018-10-28 12:42:49 +00:00
|
|
|
// Implemented here with locking because this may be used in the "changed"
|
|
|
|
// callback.
|
|
|
|
return t.hasFocus
|
|
|
|
}
|
|
|
|
|
2018-01-13 13:16:49 +00:00
|
|
|
// Write lets us implement the io.Writer interface. Tab characters will be
|
|
|
|
// replaced with TabSize space characters. A "\n" or "\r\n" will be interpreted
|
|
|
|
// as a new line.
|
2017-12-21 17:08:53 +00:00
|
|
|
func (t *TextView) Write(p []byte) (n int, err error) {
|
2018-10-28 12:42:49 +00:00
|
|
|
t.Lock()
|
|
|
|
changed := t.changed
|
|
|
|
if changed != nil {
|
2020-03-25 14:32:57 +00:00
|
|
|
// Notify at the end.
|
|
|
|
defer changed()
|
2017-12-21 17:08:53 +00:00
|
|
|
}
|
|
|
|
defer t.Unlock()
|
|
|
|
|
2020-03-26 15:54:12 +00:00
|
|
|
return t.write(p)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TextView) write(p []byte) (n int, err error) {
|
2017-12-21 17:08:53 +00:00
|
|
|
// Copy data over.
|
|
|
|
newBytes := append(t.recentBytes, p...)
|
|
|
|
t.recentBytes = nil
|
|
|
|
|
|
|
|
// If we have a trailing invalid UTF-8 byte, we'll wait.
|
|
|
|
if r, _ := utf8.DecodeLastRune(p); r == utf8.RuneError {
|
|
|
|
t.recentBytes = newBytes
|
|
|
|
return len(p), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have a trailing open dynamic color, exclude it.
|
|
|
|
if t.dynamicColors {
|
2019-02-11 16:01:48 +00:00
|
|
|
location := openColorRegex.FindIndex(newBytes)
|
2017-12-21 17:08:53 +00:00
|
|
|
if location != nil {
|
|
|
|
t.recentBytes = newBytes[location[0]:]
|
|
|
|
newBytes = newBytes[:location[0]]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-13 13:16:49 +00:00
|
|
|
// If we have a trailing open region, exclude it.
|
|
|
|
if t.regions {
|
2019-02-11 16:01:48 +00:00
|
|
|
location := openRegionRegex.FindIndex(newBytes)
|
2018-01-13 13:16:49 +00:00
|
|
|
if location != nil {
|
|
|
|
t.recentBytes = newBytes[location[0]:]
|
|
|
|
newBytes = newBytes[:location[0]]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-21 17:08:53 +00:00
|
|
|
// Transform the new bytes into strings.
|
2018-01-13 13:16:49 +00:00
|
|
|
newBytes = bytes.Replace(newBytes, []byte{'\t'}, bytes.Repeat([]byte{' '}, TabSize), -1)
|
2020-10-04 19:44:26 +00:00
|
|
|
for index, line := range bytes.Split(newBytes, []byte("\n")) {
|
2017-12-21 17:08:53 +00:00
|
|
|
if index == 0 {
|
|
|
|
if len(t.buffer) == 0 {
|
2020-10-04 19:44:26 +00:00
|
|
|
t.buffer = [][]byte{line}
|
2017-12-21 17:08:53 +00:00
|
|
|
} else {
|
2020-10-04 19:44:26 +00:00
|
|
|
t.buffer[len(t.buffer)-1] = append(t.buffer[len(t.buffer)-1], line...)
|
2017-12-21 17:08:53 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
t.buffer = append(t.buffer, line)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-15 16:52:20 +00:00
|
|
|
t.clipBuffer()
|
|
|
|
|
2017-12-21 17:08:53 +00:00
|
|
|
// Reset the index.
|
2020-09-04 02:23:56 +00:00
|
|
|
if t.reindex {
|
|
|
|
t.index = nil
|
|
|
|
}
|
2017-12-21 17:08:53 +00:00
|
|
|
|
|
|
|
return len(p), nil
|
|
|
|
}
|
|
|
|
|
2020-11-03 18:29:07 +00:00
|
|
|
// SetWrapWidth set the maximum width of lines when wrapping is enabled.
|
|
|
|
// When set to 0 the width of the TextView is used.
|
|
|
|
func (t *TextView) SetWrapWidth(width int) {
|
|
|
|
t.Lock()
|
|
|
|
defer t.Unlock()
|
|
|
|
|
|
|
|
t.wrapWidth = width
|
|
|
|
}
|
|
|
|
|
2020-09-04 02:23:56 +00:00
|
|
|
// SetReindexBuffer set a flag controlling whether the buffer is reindexed when
|
|
|
|
// it is modified. This improves the performance of TextViews whose contents
|
|
|
|
// always have line-breaks in the same location. This must be called after the
|
|
|
|
// buffer has been ind |