Documentation ¶
Overview ¶
Package tktext implements a text-editing buffer with an API and capabilities like that of the Tcl/Tk text widget. The buffer is thread-safe.
Note that any function that takes an index string as a parameter will panic if the index is not well-formed. For documentation on index syntax, see http://www.tcl.tk/man/tcl8.5/TkCmd/text.htm#M7.
Index ¶
- type Gravity
- type Position
- type TkText
- func (t *TkText) BBox(index string) (x, y int)
- func (t *TkText) Compare(index1, index2 string) int
- func (t *TkText) CountChars(index1, index2 string) int
- func (t *TkText) CountDisplayLines(index1, index2 string) int
- func (t *TkText) CountLines(index1, index2 string) int
- func (t *TkText) DLineInfo(index string) (x, y, width int)
- func (t *TkText) Delete(index1, index2 string)
- func (t *TkText) EditGetModified() bool
- func (t *TkText) EditRedo(name ...string) bool
- func (t *TkText) EditReset()
- func (t *TkText) EditSeparator()
- func (t *TkText) EditSetModified(modified bool)
- func (t *TkText) EditUndo(name ...string) bool
- func (t *TkText) Get(index1, index2 string) string
- func (t *TkText) GetScreenLines() []string
- func (t *TkText) Index(index string) Position
- func (t *TkText) Insert(index, s string)
- func (t *TkText) MarkGetGravity(name string) (Gravity, error)
- func (t *TkText) MarkNames() []string
- func (t *TkText) MarkNext(index string) string
- func (t *TkText) MarkPrevious(index string) string
- func (t *TkText) MarkSet(name, index string)
- func (t *TkText) MarkSetGravity(name string, direction Gravity) error
- func (t *TkText) MarkUnset(name ...string)
- func (t *TkText) Replace(index1, index2, s string)
- func (t *TkText) See(index string)
- func (t *TkText) SetSize(width, height int)
- func (t *TkText) SetTabStop(width int)
- func (t *TkText) SetUndo(enabled bool)
- func (t *TkText) SetWrap(mode WrapMode)
- func (t *TkText) XView() (left, right float64)
- func (t *TkText) XViewMoveTo(fraction float64)
- func (t *TkText) XViewScroll(chars int)
- func (t *TkText) YView() (top, bottom float64)
- func (t *TkText) YViewMoveTo(fraction float64)
- func (t *TkText) YViewScroll(lines int)
- type WrapMode
- Bugs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Gravity ¶
type Gravity uint8
Gravity determines the behavior of a mark during insertions at its position. Right gravity is the default.
type Position ¶
type Position struct {
Line, Char int
}
Position denotes a position in a text buffer.
type TkText ¶
type TkText struct {
// contains filtered or unexported fields
}
TkText is a text buffer. Internally, the contents are stored as a doubly linked list of line strings.
func (*TkText) BBox ¶
BBox returns the row and column numbers of the given index on the screen. The resulting values may be beyond the bounds of the screen, indicating that the index is not visible.
func (*TkText) Compare ¶
Compare returns a positive integer if index1 is greater than index2, a negative integer if index1 is less than index2, and zero if the indices are equal.
func (*TkText) CountChars ¶
CountChars returns the number of UTF-8 characters between two indices. If index1 is after index2, the result will be a negative number.
func (*TkText) CountDisplayLines ¶
CountDisplayLines returns the number of displayed line breaks between two indices, taking wrapping into account. If index1 is after index2, the result will be a negative number (or zero).
func (*TkText) CountLines ¶
CountLines returns the number of line breaks between two indices. If index1 is after index2, the result will be a negative number (or zero).
func (*TkText) DLineInfo ¶
DLineInfo the starting row and column numbers of the display line containing the given index, as well as the width of that line in columns. The resulting values may be beyond the bounds of the screen, indicating that at least part of the line is not visible.
func (*TkText) Delete ¶
Delete deletes the text from index1 to index2. If index1 is after index2, no text is deleted. If the undo mechanism is enabled for the buffer, the operation is pushed onto the undo stack, and the redo stack is cleared.
func (*TkText) EditGetModified ¶
EditGetModified returns true if and only if the buffer contents differ from the last point at which the modified flag was set to false, or if the modified flag is set to true.
func (*TkText) EditRedo ¶
EditRedo redoes changes to the buffer until a separator is encountered after at least one change, or until the redo stack is empty. Redone changes are pushed onto the undo stack. Returns true if and only if a change was redone. If mark names are given as arguments, the corresponding marks are set to the position of the redone change.
func (*TkText) EditSeparator ¶
func (t *TkText) EditSeparator()
EditSeparator pushes a separator onto the undo stack if a separator is not already on top and the stack is not empty.
func (*TkText) EditSetModified ¶
EditSetModified sets the modified flag of the widget. If the flag is set to false, EditGetModified compares the buffer contents to the current state to determine whether the buffer was modified. If the flag is set to true, EditGetModified always returns true.
func (*TkText) EditUndo ¶
EditUndo undoes changes to the buffer until a separator is encountered after at least one change, or until the undo stack is empty. Undone changes are pushed onto the redo stack. Returns true if and only if a change was undone. If mark names are given as arguments, the corresponding marks are set to the position of the undone change.
func (*TkText) Get ¶
Get returns the text between two indices as a string. If index1 is after index2, an empty string will be returned.
func (*TkText) GetScreenLines ¶
GetScreenLines returns a slice of strings, one for each display line on the screen. The length of each line is no longer than the width of the screen. Fewer lines may be returned if there are not enough to fill the screen.
func (*TkText) Index ¶
Index parses a string index and returns an equivalent valid Position in the text buffer.
func (*TkText) Insert ¶
Insert inserts the given text at the given index. If the undo mechanism is enabled for the buffer, the operation is pushed onto the undo stack, and the redo stack is cleared.
func (*TkText) MarkGetGravity ¶
MarkGetGravity returns the gravity of the mark with the given name, or an error if a mark with the given name is not set.
func (*TkText) MarkNext ¶
MarkNext returns the name of the next mark at or after the given index. If the given index is a mark, that mark will not be returned. An empty string is returned if no mark is found. This function can be used to step through all set marks in order.
func (*TkText) MarkPrevious ¶
MarkPrevious returns the name of the next mark at or before the given index. If the given index is a mark, that mark will not be returned. An empty string is returned if no mark is found. This function can be used to step through all set marks in reverse order.
func (*TkText) MarkSet ¶
MarkSet sets a mark with the given name at the given index. If a mark with the given name is already set, its position is updated.
func (*TkText) MarkSetGravity ¶
MarkSetGravity sets the gravity of the mark with the given name, or returns an error if a mark with the given name is not set.
func (*TkText) MarkUnset ¶
MarkUnset removes the marks with the given names. It is not an error to remove a mark that is not set.
func (*TkText) Replace ¶
Replace replaces the text from index1 to index2 with the given text. If index1 is after index2, the operation is equivalent to an insertion at index1. If the undo mechanism is enabled for the buffer, the operation is pushed onto the undo stack, and the redo stack is cleared.
func (*TkText) See ¶
See adjusts the view so that the given index is visible. If the index is already visible, no adjustment is made. If the index is less than one page out of view, the view is adjusted so that the index is at the edge of the screen. Otherwise, the view is centered on the index.
func (*TkText) SetSize ¶
SetSize sets the text display's width and height in characters and lines, respectively.
func (*TkText) SetTabStop ¶
SetTabStop sets the width in characters of the text display's tab stops. The default is 8.
func (*TkText) SetUndo ¶
SetUndo enables or disables the undo mechanism for the buffer. The mechanism is enabled by default.
func (*TkText) XView ¶
XView returns two fractions in the range [0, 1]. The first describes the fraction of columns in the buffer that are off-screen to the left, and the second describes the fraction that are NOT off-screen to the right.
func (*TkText) XViewMoveTo ¶
XViewMoveTo adjusts the view so that the given fraction of columns in the buffer are off-screen to the left.
func (*TkText) XViewScroll ¶
XViewScroll shifts the horizontal scrolling right by the given number of columns.
func (*TkText) YView ¶
YView returns two fractions in the range [0, 1]. The first describes the fraction of lines in the buffer that are off-screen to the top, and the second describes the fraction that are NOT off-screen to the bottom.
func (*TkText) YViewMoveTo ¶
YViewMoveTo adjusts the view so that the given fraction of lines in the buffer are off-screen to the top.
func (*TkText) YViewScroll ¶
YViewScroll shifts the vertical scrolling down by the given number of lines.
Notes ¶
Bugs ¶
Unicode is not handled correctly in some situations.