Documentation ¶
Overview ¶
Package text provides a text field widget.
Package text provides a text field widget.
Index ¶
- func CalculateTopMiddleBottom(w IWidget, size gowid.IRenderSize) (int, int, int)
- func GetCoordsFromCursorPos(cursorPos int, maxCol int, layout *TextLayout, at IChrAt) (x int, y int)
- func GetCursorPosFromCoords(ccol int, crow int, layout *TextLayout, at IChrAt) int
- func IsBreakableSpace(chr rune) bool
- func Render(w IWidget, size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) gowid.ICanvas
- type Content
- func (h *Content) AddAt(idx int, content ContentSegment)
- func (h Content) ChrAt(idx int) rune
- func (h *Content) Clone() IContent
- func (h *Content) DeleteAt(idx int, length int)
- func (h Content) Length() int
- func (h Content) RangeOver(start, end int, attrs gowid.IRenderContext, proc gowid.ICellProcessor)
- func (h Content) String() string
- func (h Content) Width() int
- type ContentCB
- type ContentSegment
- type ContentToCellArray
- type CopyableWidget
- type IChrAt
- type ICloneContent
- type IContent
- type ICursor
- type ISimple
- type IWidget
- type LineLayout
- type Options
- type SimpleCursor
- type StyledRune
- type TextLayout
- type Widget
- func (w *Widget) Align() gowid.IHAlignment
- func (w *Widget) ClipIndicator() string
- func (w *Widget) Content() IContent
- func (w *Widget) LinesFromTop() int
- func (w *Widget) OnContentSet(cb gowid.IWidgetChangedCallback)
- func (w *Widget) Read(p []byte) (n int, err error)
- func (w *Widget) RemoveOnContentSet(cb gowid.IIdentity)
- func (w *Widget) Render(size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) gowid.ICanvas
- func (w *Widget) RenderSize(size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) gowid.IRenderBox
- func (w *Widget) SetAlign(align gowid.IHAlignment, app gowid.IApp)
- func (w *Widget) SetContent(app gowid.IApp, content IContent)
- func (w *Widget) SetLinesFromTop(l int, app gowid.IApp)
- func (w *Widget) SetText(text string, app gowid.IApp)
- func (w *Widget) SetWrap(wrap WrapType, app gowid.IApp)
- func (w *Widget) String() string
- func (w *Widget) Wrap() WrapType
- type Widget1
- func (w *Widget1) Render(size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) gowid.ICanvas
- func (w *Widget1) RenderSize(size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) gowid.IRenderBox
- func (w *Widget1) Selectable() bool
- func (w *Widget1) UserInput(ev interface{}, size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) bool
- type WidgetWithCursor
- type WrapType
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateTopMiddleBottom ¶
CalculateTopMiddleBottom will, for a given size, calculate three indices: - the index of the line of text that should be at the top of the rendered area - the number of lines to display - the number of lines occluded from the bottom
func GetCoordsFromCursorPos ¶
func GetCoordsFromCursorPos(cursorPos int, maxCol int, layout *TextLayout, at IChrAt) (x int, y int)
zero-based
func GetCursorPosFromCoords ¶
func GetCursorPosFromCoords(ccol int, crow int, layout *TextLayout, at IChrAt) int
GetCursorPosFromCoords translates a (col, row) coord to a cursor position. It looks up the layout structure at the right line, then adds the col to the segment start offset.
func IsBreakableSpace ¶
Types ¶
type Content ¶
type Content []StyledRune
Content is an array of AttributedRune and implements IContent.
func NewContent ¶
func NewContent(content []ContentSegment) *Content
NewContent constructs Content suitable for initializing a text Widget.
func (*Content) AddAt ¶
func (h *Content) AddAt(idx int, content ContentSegment)
AddAt will insert the supplied ContentSegment at index idx.
func (*Content) DeleteAt ¶
DeleteAt will remove a segment of content of the provided length starting at index idx.
func (Content) Length ¶
Length will return the length of the content i.e. the number of runes it comprises.
func (Content) RangeOver ¶
func (h Content) RangeOver(start, end int, attrs gowid.IRenderContext, proc gowid.ICellProcessor)
RangeOver will call the supplied ICellProcessor for each element of the content between start and end, having first transformed that content element into an AttributedRune by using the accompanying ICellStyler and the IRenderContext. You can use this to build up an array of Cells, for example, in the process of converting a text widget to something that can be rendered in a canvas.
type ContentSegment ¶
type ContentSegment struct { Style gowid.ICellStyler Text string }
ContentSegment represents some text each character of which is styled the same way.
func StringContent ¶
func StringContent(s string) ContentSegment
StringContent makes a ContentSegment from a simple string.
func StyledContent ¶
func StyledContent(text string, style gowid.ICellStyler) ContentSegment
StyledContent makes a ContentSegment from a string and an ICellStyler.
type ContentToCellArray ¶
ContentToCellArray is a helper type; it can be used to construct a Cell array by passing it to a RangeOver() function.
func (*ContentToCellArray) ProcessCell ¶
func (m *ContentToCellArray) ProcessCell(cell gowid.Cell) gowid.Cell
type CopyableWidget ¶
type CopyableWidget struct { *Widget gowid.IIdentity gowid.IClipboardSelected }
func NewCopyable ¶
func NewCopyable(text string, id gowid.IIdentity, cs gowid.IClipboardSelected, opts ...Options) *CopyableWidget
func (*CopyableWidget) Clips ¶
func (w *CopyableWidget) Clips(app gowid.IApp) []gowid.ICopyResult
func (*CopyableWidget) Render ¶
func (w *CopyableWidget) Render(size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) gowid.ICanvas
func (*CopyableWidget) UserInput ¶
func (w *CopyableWidget) UserInput(ev interface{}, size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) bool
type ICloneContent ¶
type ICloneContent interface {
Clone() IContent
}
type IContent ¶
type IContent interface { Length() int Width() int ChrAt(idx int) rune RangeOver(start, end int, attrs gowid.IRenderContext, proc gowid.ICellProcessor) AddAt(idx int, content ContentSegment) DeleteAt(idx, length int) fmt.Stringer }
IContent represents a styled range of text. Different sections of the text can have different styles. Behind the scenes, this is just implemented as an array of (rune, ICellStyler) pairs - maybe nothing more complicated would ever be needed in practise. See also TextContent.
type ISimple ¶
ISimple is a gowid Widget that supports getting and setting plain unstyled text. It is used by edit.Widget, for example. This package's Widget type implements it.
type IWidget ¶
type IWidget interface { gowid.IWidget // Content returns an interface that provides access to the text and styling used. Content() IContent // Wrap determines whether the text is clipped, if too long, or flows onto the next line. Wrap() WrapType // Align can be used to keep each line of text left, right or center aligned. Align() gowid.IHAlignment // LinesFromTop is used to track how many widget lines are not in view off the top // given the current render. The widget tries to keep this the same when the widget // is re-rendered at a different size (e.g. the terminal is resized). LinesFromTop() int ClipIndicator() string }
IWidget is a gowid IWidget with the following extra APIs.
type LineLayout ¶
type Options ¶
type Options struct { Wrap WrapType ClipIndicator string Align gowid.IHAlignment }
Options is used to provide arguments to the various New initialization functions.
type SimpleCursor ¶
type SimpleCursor struct {
Pos int
}
func (*SimpleCursor) CursorEnabled ¶
func (c *SimpleCursor) CursorEnabled() bool
func (*SimpleCursor) CursorPos ¶
func (c *SimpleCursor) CursorPos() int
func (*SimpleCursor) SetCursorDisabled ¶
func (c *SimpleCursor) SetCursorDisabled()
func (*SimpleCursor) SetCursorPos ¶
func (c *SimpleCursor) SetCursorPos(pos int, app gowid.IApp)
type StyledRune ¶
type StyledRune struct { Chr rune Attr gowid.ICellStyler }
StyledRune is a styled rune.
func MakeAttributedRunes ¶
func MakeAttributedRunes(m ContentSegment) []StyledRune
MakeAttributedRunes converts a ContentSegment into an array of AttributeRune, which is used to build a Content implementing IContent.
type TextLayout ¶
type TextLayout struct {
Lines []LineLayout
}
func MakeTextLayout ¶
func MakeTextLayout(content IContent, width int, wrap WrapType, align gowid.IHAlignment) *TextLayout
MakeTextLayout builds an array of line layouts from an IContent object. It applies the provided text wrapping and alignment options. The line layouts can then be used to index the IContent in order to build a canvas for rendering.
type Widget ¶
type Widget struct { Callbacks *gowid.Callbacks gowid.RejectUserInput gowid.NotSelectable // contains filtered or unexported fields }
Widget can be used to display text on the screen, with optional styling for specified regions of the text.
func New ¶
New initializes a text widget with a string and some extra arguments e.g. to align the text within each line, and to determine whether or not it's clipped.
func NewFromContent ¶
NewFromContent initializes a text widget with IContent, which can be built from a set of content segments. This is a way of making a text widget with styling.
func NewFromContentExt ¶
NewFromContentExt initialized a text widget with IContent and some extra options such as wrapping, alignment, etc.
func (*Widget) Align ¶
func (w *Widget) Align() gowid.IHAlignment
func (*Widget) ClipIndicator ¶
func (*Widget) LinesFromTop ¶
func (*Widget) OnContentSet ¶
func (w *Widget) OnContentSet(cb gowid.IWidgetChangedCallback)
func (*Widget) RemoveOnContentSet ¶
func (*Widget) RenderSize ¶
func (w *Widget) RenderSize(size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) gowid.IRenderBox
type Widget1 ¶
type Widget1 struct {
I int
}
func (*Widget1) RenderSize ¶
func (w *Widget1) RenderSize(size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) gowid.IRenderBox
func (*Widget1) Selectable ¶
type WidgetWithCursor ¶
type WidgetWithCursor struct { *Widget *SimpleCursor }
This meets both IText and ICursor, and allows me to make a canvas from a text widget and a separately specified cursor position
func (*WidgetWithCursor) CalculateTopMiddleBottom ¶
func (w *WidgetWithCursor) CalculateTopMiddleBottom(size gowid.IRenderSize) (int, int, int)