Documentation
ΒΆ
Overview ΒΆ
Package bloom lays out, composites, and routes input for Bubble Tea views.
A view is described each frame as a tree of nodes built from model state: Row and Column share space between children, Box draws a Lip Gloss frame around one, Overlay puts [Layer]s such as dialogs over a base, and a Bubble Tea component is placed with View.
bloom.Column( bloom.Row( bloom.Fixed(20, m.sidebar).ID(paneSidebar).Collapsible(1), bloom.Fill(m.reader).ID(paneReader).Min(40), ), m.statusbar, )
Who sizes what ΒΆ
Constraints go down, sizes come up, and parents place. A parent decides each child's rectangle, whether it is collapsed, and how it is clipped. How a child takes part in sharing space is set where it is placed, by wrapping it in a slot such as Fixed or Fill, not by the child itself. A child only knows the size it was given: a component builds its layout from it in Layout, and one that knows its natural size can implement Measurer.
Rendering ΒΆ
Root turns a tree into a tea.View each frame. Leaf strings are parsed into cells once and cached, nodes are composited in tree order with every node clipped to its parent, and fx effects run on a node's cells or on the frame beneath a layer. A frame identical to the previous one is not composited again. Mouse events run the handlers of the nodes under the pointer, given with On and made by package on, using the geometry of the frame on screen.
Layout is a pure function of the tree, so Solve can compute the same rectangles in Update, for components that need their size there.
Documentation ΒΆ
See the documentation for guides and examples. It is also available for LLMs and agents as llms.txt.
Index ΒΆ
- Constants
- Variables
- func Debug(w, h int, c Child) string
- func MarkMatches(re *regexp.Regexp, style lipgloss.Style) func(line int, text string) []Mark
- func Render(w, h int, c Child) string
- func ThrottleMouse(every time.Duration) func(tea.Model, tea.Msg) tea.Msg
- type Align
- type BoxNode
- func (n BoxNode) BorderFx(t float64, effects ...fx.Effect) BoxNode
- func (n BoxNode) Edge(side Direction, align Align, child Child) BoxNode
- func (n BoxNode) EdgeAt(side Direction, at int, child Child) BoxNode
- func (n BoxNode) Focusable() BoxNode
- func (n BoxNode) HoverStyle(style lipgloss.Style) BoxNode
- func (n BoxNode) ID(id ID) BoxNode
- func (n BoxNode) Layout(Context) Child
- func (n BoxNode) NoTooltip() BoxNode
- func (n BoxNode) On(handlers ...on.Handler) BoxNode
- func (n BoxNode) Selectable() BoxNode
- func (n BoxNode) Tooltip(text string, opts ...TipOption) BoxNode
- func (n BoxNode) TooltipOpen(open bool) BoxNode
- type Buffer
- func (b *Buffer) Append(lines ...string)
- func (b *Buffer) Clamp(p Pos) Pos
- func (b *Buffer) Clear()
- func (b *Buffer) Delete(from, to Pos) Change
- func (b *Buffer) Edit(edits ...Edit) Change
- func (b *Buffer) End() Pos
- func (b *Buffer) Find(re *regexp.Regexp, line, at int) (Match, bool)
- func (b *Buffer) FindBefore(re *regexp.Regexp, line, at int) (Match, bool)
- func (b *Buffer) Insert(at Pos, text string) Change
- func (b *Buffer) Len() int
- func (b *Buffer) Line(i int) string
- func (b *Buffer) Next(p Pos) Pos
- func (b *Buffer) NextWord(p Pos) Pos
- func (b *Buffer) Offset(p Pos) int
- func (b *Buffer) PosOf(offset int) Pos
- func (b *Buffer) Prev(p Pos) Pos
- func (b *Buffer) PrevWord(p Pos) Pos
- func (b *Buffer) Replace(from, to Pos, text string) Change
- func (b *Buffer) Restore(s Snapshot)
- func (b *Buffer) Rev() uint64
- func (b *Buffer) SetContent(s string)
- func (b *Buffer) SetLines(lines ...string)
- func (b *Buffer) SetWordChars(chars string)
- func (b *Buffer) Snapshot() Snapshot
- func (b *Buffer) String() string
- func (b *Buffer) Text(i int) string
- func (b *Buffer) TextIn(from, to Pos) string
- func (b *Buffer) WordAt(p Pos) (from, to Pos, ok bool)
- type CenterNode
- func (n CenterNode) Focusable() CenterNode
- func (n CenterNode) ID(id ID) CenterNode
- func (n CenterNode) Layout(Context) Child
- func (n CenterNode) NoTooltip() CenterNode
- func (n CenterNode) On(handlers ...on.Handler) CenterNode
- func (n CenterNode) Selectable() CenterNode
- func (n CenterNode) Tooltip(text string, opts ...TipOption) CenterNode
- func (n CenterNode) TooltipOpen(open bool) CenterNode
- type Change
- type Child
- type Context
- type CopyMsg
- type Direction
- type DrawableNode
- func (n DrawableNode) Focusable() DrawableNode
- func (n DrawableNode) ID(id ID) DrawableNode
- func (n DrawableNode) Layout(Context) Child
- func (n DrawableNode) NoTooltip() DrawableNode
- func (n DrawableNode) On(handlers ...on.Handler) DrawableNode
- func (n DrawableNode) Tooltip(text string, opts ...TipOption) DrawableNode
- func (n DrawableNode) TooltipOpen(open bool) DrawableNode
- type Edit
- type Editable
- type FlexNode
- func (n FlexNode) Align(a Align) FlexNode
- func (n FlexNode) Focusable() FlexNode
- func (n FlexNode) Gap(cells int) FlexNode
- func (n FlexNode) ID(id ID) FlexNode
- func (n FlexNode) Justify(j flex.Justify) FlexNode
- func (n FlexNode) Layout(Context) Child
- func (n FlexNode) NoTooltip() FlexNode
- func (n FlexNode) On(handlers ...on.Handler) FlexNode
- func (n FlexNode) Selectable() FlexNode
- func (n FlexNode) Tooltip(text string, opts ...TipOption) FlexNode
- func (n FlexNode) TooltipOpen(open bool) FlexNode
- type Focus
- func (f *Focus) Clear()
- func (f *Focus) Current() ID
- func (f *Focus) Is(id ID) bool
- func (f *Focus) Next(frame *Frame) bool
- func (f *Focus) Pop()
- func (f *Focus) Prev(frame *Frame) bool
- func (f *Focus) Push(scope ID)
- func (f *Focus) Scope() ID
- func (f *Focus) Set(id ID)
- func (f *Focus) Update(msg tea.Msg, frame *Frame) (tea.Cmd, bool)
- func (f *Focus) Within(frame *Frame, scope ID) bool
- type Frame
- type GridNode
- func (n GridNode) Focusable() GridNode
- func (n GridNode) Gap(x, y int) GridNode
- func (n GridNode) ID(id ID) GridNode
- func (n GridNode) Layout(Context) Child
- func (n GridNode) NoTooltip() GridNode
- func (n GridNode) On(handlers ...on.Handler) GridNode
- func (n GridNode) Selectable() GridNode
- func (n GridNode) Tooltip(text string, opts ...TipOption) GridNode
- func (n GridNode) TooltipOpen(open bool) GridNode
- type GutterRow
- type ID
- type LayerNode
- func (n LayerNode) Anchor(x, y Align) LayerNode
- func (n LayerNode) AnchorTo(id ID, side Direction) LayerNode
- func (n LayerNode) Animate(opts ...anim.Option) LayerNode
- func (n LayerNode) Backdrop(effects ...fx.Effect) LayerNode
- func (n LayerNode) Float() LayerNode
- func (n LayerNode) Focusable() LayerNode
- func (n LayerNode) ID(id ID) LayerNode
- func (n LayerNode) Layout(Context) Child
- func (n LayerNode) Margin(cells int) LayerNode
- func (n LayerNode) Modal() LayerNode
- func (n LayerNode) MoveWith(effects ...fx.Effect) LayerNode
- func (n LayerNode) NoTooltip() LayerNode
- func (n LayerNode) Offset(x, y int) LayerNode
- func (n LayerNode) On(handlers ...on.Handler) LayerNode
- func (n LayerNode) Place(r image.Rectangle) LayerNode
- func (n LayerNode) Presence(p anim.Presence, effects ...fx.Effect) LayerNode
- func (n LayerNode) Selectable() LayerNode
- func (n LayerNode) Shadow(x, y int, effects ...fx.Effect) LayerNode
- func (n LayerNode) Size(w, h int) LayerNode
- func (n LayerNode) Tooltip(text string, opts ...TipOption) LayerNode
- func (n LayerNode) TooltipOpen(open bool) LayerNode
- func (n LayerNode) Transition(t float64, effects ...fx.Effect) LayerNode
- func (n LayerNode) Transparent() LayerNode
- type LayoutFunc
- type ListNode
- func (n ListNode) Focusable() ListNode
- func (n ListNode) Gap(cells int) ListNode
- func (n ListNode) ID(id ID) ListNode
- func (n ListNode) ItemText(text func(i int) string) ListNode
- func (n ListNode) Keep(i int) ListNode
- func (n ListNode) Layout(Context) Child
- func (n ListNode) NoTooltip() ListNode
- func (n ListNode) Offset(i int) ListNode
- func (n ListNode) On(handlers ...on.Handler) ListNode
- func (n ListNode) Selectable() ListNode
- func (n ListNode) Tooltip(text string, opts ...TipOption) ListNode
- func (n ListNode) TooltipOpen(open bool) ListNode
- type ListView
- type Mark
- type MarqueeNode
- func (n MarqueeNode) Focusable() MarqueeNode
- func (n MarqueeNode) Gap(s string) MarqueeNode
- func (n MarqueeNode) ID(id ID) MarqueeNode
- func (n MarqueeNode) Layout(ctx Context) Child
- func (n MarqueeNode) NoTooltip() MarqueeNode
- func (n MarqueeNode) On(handlers ...on.Handler) MarqueeNode
- func (n MarqueeNode) Selectable() MarqueeNode
- func (n MarqueeNode) Style(style lipgloss.Style) MarqueeNode
- func (n MarqueeNode) Tooltip(text string, opts ...TipOption) MarqueeNode
- func (n MarqueeNode) TooltipOpen(open bool) MarqueeNode
- type Match
- type Measurer
- type MinSizeNode
- func (n MinSizeNode) Focusable() MinSizeNode
- func (n MinSizeNode) ID(id ID) MinSizeNode
- func (n MinSizeNode) Layout(ctx Context) Child
- func (n MinSizeNode) NoTooltip() MinSizeNode
- func (n MinSizeNode) On(handlers ...on.Handler) MinSizeNode
- func (n MinSizeNode) Selectable() MinSizeNode
- func (n MinSizeNode) Tooltip(text string, opts ...TipOption) MinSizeNode
- func (n MinSizeNode) TooltipOpen(open bool) MinSizeNode
- type Option
- func WithClickDelay(enabled bool) Option
- func WithClipboard(write func(text string) error) Option
- func WithClock(now func() time.Time) Option
- func WithColors(fg, bg color.Color) Option
- func WithCopyFlash(enabled bool) Option
- func WithFPS(n int) Option
- func WithFocus(f *Focus) Option
- func WithSelectionStyle(style lipgloss.Style) Option
- func WithTooltips(t Tooltips) Option
- func WithUnfocusedFPS(n int) Option
- func WithWidthMethod(method ansi.Method) Option
- func WithWordChars(chars string) Option
- type OverlayNode
- func (n OverlayNode) Focusable() OverlayNode
- func (n OverlayNode) ID(id ID) OverlayNode
- func (n OverlayNode) Layout(Context) Child
- func (n OverlayNode) NoTooltip() OverlayNode
- func (n OverlayNode) On(handlers ...on.Handler) OverlayNode
- func (n OverlayNode) Selectable() OverlayNode
- func (n OverlayNode) Tooltip(text string, opts ...TipOption) OverlayNode
- func (n OverlayNode) TooltipOpen(open bool) OverlayNode
- type Pos
- type Range
- type Root
- func (r *Root) ClearSelection()
- func (r *Root) Click(id ID) (tea.Cmd, bool)
- func (r *Root) ClickAt(x, y int) tea.Cmd
- func (r *Root) CopySelection() tea.Cmd
- func (r *Root) EnableTooltips(on bool)
- func (r *Root) Frame() *Frame
- func (r *Root) Init() tea.Cmd
- func (r *Root) Render(w, h int, c Child) string
- func (r *Root) SelectAll(id ID) bool
- func (r *Root) Selection() (string, bool)
- func (r *Root) SetTooltips(t Tooltips)
- func (r *Root) Tooltip() (string, bool)
- func (r *Root) Update(msg tea.Msg) tea.Cmd
- func (r *Root) View(w, h int, c Child) tea.View
- type ScrollNode
- func (n ScrollNode) Focusable() ScrollNode
- func (n ScrollNode) ID(id ID) ScrollNode
- func (n ScrollNode) Layout(Context) Child
- func (n ScrollNode) NoTooltip() ScrollNode
- func (n ScrollNode) On(handlers ...on.Handler) ScrollNode
- func (n ScrollNode) Selectable() ScrollNode
- func (n ScrollNode) Tooltip(text string, opts ...TipOption) ScrollNode
- func (n ScrollNode) TooltipOpen(open bool) ScrollNode
- func (n ScrollNode) X(offset int) ScrollNode
- type ScrollbarNode
- func (n ScrollbarNode) Focusable() ScrollbarNode
- func (n ScrollbarNode) Horizontal() ScrollbarNode
- func (n ScrollbarNode) HoverStyle(style ScrollbarStyle) ScrollbarNode
- func (n ScrollbarNode) ID(id ID) ScrollbarNode
- func (n ScrollbarNode) Layout(Context) Child
- func (n ScrollbarNode) NoTooltip() ScrollbarNode
- func (n ScrollbarNode) On(handlers ...on.Handler) ScrollbarNode
- func (n ScrollbarNode) OnScroll(fn func(offset int) tea.Cmd) ScrollbarNode
- func (n ScrollbarNode) Style(style ScrollbarStyle) ScrollbarNode
- func (n ScrollbarNode) Tooltip(text string, opts ...TipOption) ScrollbarNode
- func (n ScrollbarNode) TooltipOpen(open bool) ScrollbarNode
- type ScrollbarStyle
- type SelectionMsg
- type Size
- type SkeletonNode
- func (n SkeletonNode) Focusable() SkeletonNode
- func (n SkeletonNode) ID(id ID) SkeletonNode
- func (n SkeletonNode) Layout(ctx Context) Child
- func (n SkeletonNode) NoTooltip() SkeletonNode
- func (n SkeletonNode) On(handlers ...on.Handler) SkeletonNode
- func (n SkeletonNode) Selectable() SkeletonNode
- func (n SkeletonNode) Shimmer(phase float64) SkeletonNode
- func (n SkeletonNode) Style(style lipgloss.Style) SkeletonNode
- func (n SkeletonNode) Tooltip(text string, opts ...TipOption) SkeletonNode
- func (n SkeletonNode) TooltipOpen(open bool) SkeletonNode
- type SlotNode
- func (n SlotNode) Align(a Align) SlotNode
- func (n SlotNode) Animate(opts ...anim.Option) SlotNode
- func (n SlotNode) Collapsible(priority int) SlotNode
- func (n SlotNode) Focusable() SlotNode
- func (n SlotNode) ID(id ID) SlotNode
- func (n SlotNode) Layout(Context) Child
- func (n SlotNode) Max(cells int) SlotNode
- func (n SlotNode) Min(cells int) SlotNode
- func (n SlotNode) MoveWith(effects ...fx.Effect) SlotNode
- func (n SlotNode) NoTooltip() SlotNode
- func (n SlotNode) On(handlers ...on.Handler) SlotNode
- func (n SlotNode) Scope() SlotNode
- func (n SlotNode) Selectable() SlotNode
- func (n SlotNode) Tooltip(text string, opts ...TipOption) SlotNode
- func (n SlotNode) TooltipOpen(open bool) SlotNode
- type Snapshot
- type Span
- type TextMap
- type TextNode
- func (n TextNode) Cursor(c *tea.Cursor) TextNode
- func (n TextNode) Focusable() TextNode
- func (n TextNode) HoverStyle(style lipgloss.Style) TextNode
- func (n TextNode) ID(id ID) TextNode
- func (n TextNode) Layout(Context) Child
- func (n TextNode) NoTooltip() TextNode
- func (n TextNode) NoWrap() TextNode
- func (n TextNode) On(handlers ...on.Handler) TextNode
- func (n TextNode) Selectable() TextNode
- func (n TextNode) Style(style lipgloss.Style) TextNode
- func (n TextNode) Tooltip(text string, opts ...TipOption) TextNode
- func (n TextNode) TooltipOpen(open bool) TextNode
- func (n TextNode) Truncate() TextNode
- func (n TextNode) Trusted() TextNode
- type TextSource
- type TipMode
- type TipOption
- type TooltipSinkNode
- func (n TooltipSinkNode) Focusable() TooltipSinkNode
- func (n TooltipSinkNode) ID(id ID) TooltipSinkNode
- func (n TooltipSinkNode) Layout(Context) Child
- func (n TooltipSinkNode) NoTooltip() TooltipSinkNode
- func (n TooltipSinkNode) On(handlers ...on.Handler) TooltipSinkNode
- func (n TooltipSinkNode) Style(style lipgloss.Style) TooltipSinkNode
- func (n TooltipSinkNode) Tooltip(text string, opts ...TipOption) TooltipSinkNode
- func (n TooltipSinkNode) TooltipOpen(open bool) TooltipSinkNode
- type Tooltips
- type TransitionNode
- func (n TransitionNode) Focusable() TransitionNode
- func (n TransitionNode) ID(id ID) TransitionNode
- func (n TransitionNode) Layout(Context) Child
- func (n TransitionNode) NoTooltip() TransitionNode
- func (n TransitionNode) On(handlers ...on.Handler) TransitionNode
- func (n TransitionNode) Selectable() TransitionNode
- func (n TransitionNode) Tooltip(text string, opts ...TipOption) TransitionNode
- func (n TransitionNode) TooltipOpen(open bool) TransitionNode
- type ViewNode
- type Viewer
- type ViewportNode
- func (n ViewportNode) At(pos ViewportPos) ViewportNode
- func (n ViewportNode) Caret(sel *Range) ViewportNode
- func (n ViewportNode) Cursor(c *tea.Cursor) ViewportNode
- func (n ViewportNode) Focusable() ViewportNode
- func (n ViewportNode) Follow() ViewportNode
- func (n ViewportNode) Gutter(width int, fn func(row GutterRow) string) ViewportNode
- func (n ViewportNode) ID(id ID) ViewportNode
- func (n ViewportNode) Layout(Context) Child
- func (n ViewportNode) LineNumbers(style lipgloss.Style) ViewportNode
- func (n ViewportNode) LineStyle(fn func(line int) lipgloss.Style) ViewportNode
- func (n ViewportNode) Marks(fn func(line int, text string) []Mark) ViewportNode
- func (n ViewportNode) NoTooltip() ViewportNode
- func (n ViewportNode) On(handlers ...on.Handler) ViewportNode
- func (n ViewportNode) OnCaret(fn func(sel Range) tea.Cmd) ViewportNode
- func (n ViewportNode) OnScroll(fn func(pos ViewportPos) tea.Cmd) ViewportNode
- func (n ViewportNode) Selectable() ViewportNode
- func (n ViewportNode) Style(style lipgloss.Style) ViewportNode
- func (n ViewportNode) Tooltip(text string, opts ...TipOption) ViewportNode
- func (n ViewportNode) TooltipOpen(open bool) ViewportNode
- func (n ViewportNode) Trusted() ViewportNode
- func (n ViewportNode) Wrap(mode WrapMode) ViewportNode
- type ViewportPos
- type ViewportView
- func (v ViewportView) AtBottom() bool
- func (v ViewportView) AtRow(row int) ViewportPos
- func (v ViewportView) AtTop() bool
- func (v ViewportView) Bottom() ViewportPos
- func (v ViewportView) CaretAt(cell image.Point) Range
- func (v ViewportView) CaretCell(sel Range) (image.Point, bool)
- func (v ViewportView) CellOf(p Pos) (image.Point, bool)
- func (v ViewportView) Column(sel Range) int
- func (v ViewportView) Down(n int) ViewportPos
- func (v ViewportView) HalfPageDown() ViewportPos
- func (v ViewportView) HalfPageUp() ViewportPos
- func (v ViewportView) Left(n int) ViewportPos
- func (v ViewportView) MoveRows(sel Range, n, column int) Range
- func (v ViewportView) PageDown() ViewportPos
- func (v ViewportView) PageUp() ViewportPos
- func (v ViewportView) Percent() float64
- func (v ViewportView) PosAt(cell image.Point) Pos
- func (v ViewportView) Reveal(line int) ViewportPos
- func (v ViewportView) Right(n int) ViewportPos
- func (v ViewportView) RowEnd(sel Range) Range
- func (v ViewportView) RowStart(sel Range) Range
- func (v ViewportView) ScrollRows(sel Range, n, column int) (Range, ViewportPos)
- func (v ViewportView) Show(sel Range) ViewportPos
- func (v ViewportView) Top() ViewportPos
- func (v ViewportView) Up(n int) ViewportPos
- type WrapMode
- type WrapNode
- func (n WrapNode) Focusable() WrapNode
- func (n WrapNode) Gap(x, y int) WrapNode
- func (n WrapNode) ID(id ID) WrapNode
- func (n WrapNode) Layout(Context) Child
- func (n WrapNode) NoTooltip() WrapNode
- func (n WrapNode) On(handlers ...on.Handler) WrapNode
- func (n WrapNode) Selectable() WrapNode
- func (n WrapNode) Tooltip(text string, opts ...TipOption) WrapNode
- func (n WrapNode) TooltipOpen(open bool) WrapNode
Constants ΒΆ
const ( Bottom = fx.Bottom Top = fx.Top Left = fx.Left Right = fx.Right TopLeft = fx.TopLeft TopRight = fx.TopRight BottomLeft = fx.BottomLeft BottomRight = fx.BottomRight )
The sides and corners of a node or of the screen.
const ( // WrapNone shows lines whole, cut off at the viewport's right edge, // and scrolled sideways with [ViewportPos.X]. It is the default. WrapNone = WrapMode(linebuf.None) // WrapWords wraps lines at the spaces between words, and after // hyphens, as a [Text] wraps, breaking a word only when it is // wider than the viewport. WrapWords = WrapMode(linebuf.Words) // WrapChars wraps lines at the viewport's width, wherever it falls. WrapChars = WrapMode(linebuf.Chars) )
Variables ΒΆ
var ViewportEnd = ViewportPos{Line: math.MaxInt}
ViewportEnd is the position of a Viewport scrolled to its end, showing its last line at its bottom, which stays at the end as lines are appended. See ViewportNode.Follow.
Functions ΒΆ
func Debug ΒΆ
Debug lays out c in a wΓh frame, as Solve does, and returns its tree of nodes as text, one node per line: what it is, how it is sized, its ID, where it was laid out as x,y and width x height, and anything else that affects it. A node its container collapsed, or a layer whose anchor is not on screen, is marked hidden; one partly on screen is marked with the part that is, and one not on screen at all is marked offscreen. Components are shown by their type, with the tree they built, and a View by the type of what it draws. A node with the same ID as one before it is marked duplicate: IDs should be unique in a frame, and the nodes in two with the same ID, which are known by where they are in them, are not told apart either.
Debug is meant for finding out why a layout looks the way it does, such as by writing it to a log from View. Its format may change between versions.
Column 0,0 30x5 ββ Row 0,0 30x3 β ββ Fixed(10) id="sidebar" 0,0 10x3 collapsible=1 β β ββ Box 0,0 10x3 β β ββ Text "Inbox" 1,1 8x1 β ββ Fill id="reader" 10,0 20x3 min=12 β ββ main.reader 10,0 20x3 ββ Text "ready" 0,3 30x1 truncate
func MarkMatches ΒΆ
MarkMatches returns a function for ViewportNode.Marks that marks every match of re in style. A nil re marks nothing.
func Render ΒΆ
Render lays out and draws c in a wΓh frame and returns it as a string, for using a layout where a string is wanted. A w or h of zero or less is c's natural size on that axis. A model's View should use Root instead, which keeps more between frames. Render is stateless and draws animation targets immediately.
func ThrottleMouse ΒΆ
ThrottleMouse returns a tea.WithFilter filter that drops wheel and motion events that come within every of the last of the same kind let through, which spares a frame for each one when the terminal sends them faster than they can be drawn. A dropped event is not made up for: the wheel scrolls less, and when the pointer stops right after one, hover waits until it moves again.
Types ΒΆ
type Align ΒΆ
type Align uint8
Align is where a child goes on the cross axis of a Row or Column, or on either axis of a Layer.
type BoxNode ΒΆ
type BoxNode struct {
// contains filtered or unexported fields
}
BoxNode draws a Lip Gloss style's frame, its margins, border, padding, and background, around a child. Build one with Box.
func Box ΒΆ
Box draws style's frame around child, which gets the space inside it. A box given less space than its frame takes is not drawn, rather than drawn broken.
func (BoxNode) BorderFx ΒΆ
BorderFx applies effects to the box's frame for progress t, its border, padding, and background, but not what is inside it or on its edges. The effects of package fx made for borders, such as fx.Chase, change only the border's cells. Effects that move cells do not move the frame.
func (BoxNode) Edge ΒΆ
Edge draws child over side of the box's border, such as a title or a counter on the top border, or a Scrollbar on the right one, without taking space from what is inside. side is Top, Bottom, Left, or Right; a corner shows nothing. On the top and bottom, children are one row tall and kept a cell from the corners; on the left and right, they are one column wide, and a Text runs down the side, a character to a row. Children at Start and End are placed from that end inward, in the order given, and children at Center share the middle of what is left. A Stretch child takes all of what is left. Children are given no more room than is left, one cell apart, and one with no room is not shown. A side without a border shows none.
func (BoxNode) EdgeAt ΒΆ
EdgeAt draws child over side of the box's border at cell at along it, counted from the top or left end of the side, where 0 is the corner, or back from the other end when negative, where -1 is the far corner. Use it to join lines drawn inside the box to its border, such as a β¬ where a column separator meets the top, or a β in place of a corner where boxes stack. The child is given the room from at to the end of the side, one row tall on the top and bottom, or one column wide on the left and right, where a Text runs down the side as with BoxNode.Edge. Children placed with EdgeAt take no room from those placed with Edge, and are drawn with them in the order given, so a later child is drawn over an earlier one. A cell outside the side, or a side without a border, shows nothing.
func (BoxNode) HoverStyle ΒΆ
HoverStyle draws the box's frame with style instead of its own while the pointer is over it. It should take the same space as the box's style, changing only how it looks. See on.Hover for when the pointer is followed.
func (BoxNode) ID ΒΆ
ID sets the ID that focus and Frame.Rect refer to the box by.
func (BoxNode) Layout ΒΆ
Layout implements Child, returning the box itself: bloom lays it out without calling it.
func (BoxNode) NoTooltip ΒΆ
NoTooltip keeps the TextNode.Truncate nodes inside the box that are cut to fit from showing their full text as a tooltip, such as where the app shows it some other way. A tooltip given with Tooltip, to the box or to a node inside it, still shows, and so does the full text of a node pinned open with TooltipOpen.
func (BoxNode) On ΒΆ
On adds mouse handlers to the box, made by package on. The box takes events on its frame as well as inside it, and the positions handlers are given are relative to its outer corner.
func (BoxNode) Selectable ΒΆ
Selectable lets the left button select text in the box by dragging over it, as a terminal selects text, but kept inside the box. Holding alt as the drag starts selects a rectangle of cells instead. The innermost selectable node under the pointer takes the drag, unless a node inside it has an on.Drag handler. See Root.Selection for the text selected. Only what is inside the box's frame is selected.
func (BoxNode) Tooltip ΒΆ
Tooltip gives the box a tooltip showing text, which a Root with tooltips on (see WithTooltips) draws beside it once the pointer has rested on it, or once a key press has moved the focus onto it. Without them it does nothing. A node without a tooltip of its own shows that of the nearest node it is inside that has one. On a TextNode.Truncate node, it shows in place of the full text the node was cut from. Empty text gives the box no tooltip. The text is drawn without the escape sequences that TextNode.Trusted keeps.
func (BoxNode) TooltipOpen ΒΆ
TooltipOpen pins the box's tooltip open while open is true: a Root with tooltips on (see WithTooltips) shows it at once, without the pointer or the focus, and keys and the pointer do not close it. Several can be pinned at once, each placed where it covers none of the others or their nodes, and one that fits nowhere is left out of the frame. It shows the tooltip given with Tooltip, or for a TextNode.Truncate node cut to fit, its full text, even inside a node with NoTooltip, as the app asked for it. Text that fits, and a box without a tooltip, show nothing. Use it to show the full text of a row the app has selected, which bloom does not know of.
type Buffer ΒΆ
type Buffer struct {
// contains filtered or unexported fields
}
Buffer holds the lines of text a Viewport shows, such as a log or a file, kept in the model and changed as the text changes. A viewport only lays out and draws the lines in sight, and the buffer keeps what it works out about its lines, such as how wide each is, so that appending a line to a buffer of a million costs about as much as appending one to a buffer of ten.
Lines may hold ANSI styles and hyperlinks. A style left open at the end of a line carries on into the next, as it would in a terminal, so the output of a syntax highlighter that styles a comment over many lines is drawn as it would be printed. Tabs are drawn as spaces to the next stop, every four columns.
The zero value is an empty buffer, ready to use. A Buffer is not safe for use by more than one goroutine at a time: change it in Update, as the rest of the model is.
func NewBuffer ΒΆ
NewBuffer returns a buffer holding s, as Buffer.SetContent sets it.
func (*Buffer) Append ΒΆ
Append adds lines to the end of the buffer. A line holding newlines is split at them, and a newline at the end of one ends it, so lines read from a program's output can be given as they come. "" adds an empty line.
func (*Buffer) Clamp ΒΆ
Clamp returns p moved to the nearest place in the buffer's text, as each method given a position moves it: the start for a line before the first, the end of the buffer for a line past the last, the end of the line for a Col past it, and the start of the character for a Col within one that takes more than a byte, or within a grapheme cluster, such as a letter and the accent on it.
func (*Buffer) Delete ΒΆ
Delete removes the text from from up to to, as Buffer.Replace removes it, and returns the change.
func (*Buffer) Edit ΒΆ
Edit makes edits at once, as one change, each as Buffer.Replace makes it, such as the text typed at each of several carets. The positions of each are those of the buffer before any of them, and the edits may be given in any order. They must not overlap, though they may touch: of two that overlap, the one given later is dropped. Text put in at the same place by more than one goes in in the order they are given.
func (*Buffer) Find ΒΆ
Find returns the first match of re that starts at or after byte at of the text of line, looking through the lines after it in turn, and whether there is one. It does not wrap around to the first line. To find the match after m, give m.Line and m.End, or m.Start+1 for an empty match.
func (*Buffer) FindBefore ΒΆ
FindBefore returns the last match of re that starts before byte at of the text of line, looking through the lines before it in turn, and whether there is one. To find the match before m, give m.Line and m.Start.
func (*Buffer) Insert ΒΆ
Insert puts text at at, as Buffer.Replace puts it in, and returns the change.
func (*Buffer) Line ΒΆ
Line returns line i as it was given, with its styles, or "" when there is no such line.
func (*Buffer) Next ΒΆ
Next returns the position one character after p, clamped, as the right arrow moves a caret: past a grapheme cluster, such as a letter and the accent on it, or a tab, and from the end of a line to the start of the next. It is the end of the buffer at its end.
func (*Buffer) NextWord ΒΆ
NextWord returns the end of the word p is in, or of the next word after it, clamped, as ctrl+right moves a caret in most editors: the spaces and punctuation between words are skipped, and line ends crossed. Words are found as Buffer.SetWordChars tells, so "don't" and "3.14" are a word each. It is the end of the buffer when no word follows p.
func (*Buffer) Offset ΒΆ
Offset returns the byte of Buffer.String that p, clamped, is at, counting the bytes of the lines before it, with their styles and newlines, from what the buffer keeps of them, and then those of its line before it.
func (*Buffer) PosOf ΒΆ
PosOf returns the position that byte offset of Buffer.String is at, the inverse of Buffer.Offset: that of the character the byte is in, or of the next one when it is in an escape sequence, the end of a line for its newline, and the start or end of the buffer for an offset before or past it.
func (*Buffer) Prev ΒΆ
Prev returns the position one character before p, clamped, as the left arrow moves a caret, and from the start of a line to the end of the one before. It is the start of the buffer at its start.
func (*Buffer) PrevWord ΒΆ
PrevWord returns the start of the word p is in, or of the word before it, clamped, as ctrl+left moves a caret, skipping what Buffer.NextWord skips. It is the start of the buffer when no word comes before p.
func (*Buffer) Replace ΒΆ
Replace replaces the text from from up to to with text, and returns the change, to follow positions through it with. Text is split into lines at its newlines, a newline at its end starting an empty line, unlike with Buffer.Append, and a carriage return before a newline is dropped. Removing a newline joins the lines either side of it.
Both positions are clamped to the text, as Buffer.Clamp clamps them, and swapped when from comes after to. A buffer with no lines takes the change as though it held one empty line, and one that has been changed keeps at least one: removing all of its text leaves an empty line.
Text is put in as it is given, and may hold escape sequences, as an appended line may. The text after the change is drawn in the style it was drawn in: the escape sequences of the text removed are left in its place as the one that sets the style they leave, when it is not the style the text before is in, so that removing a word that starts a color does not lose the color of the words after it.
It costs a step a level of the buffer's tree, and works out again only the lines it changes, however many lines it removes.
func (*Buffer) Restore ΒΆ
Restore puts the buffer's text back to snapshot s, in a step, keeping what the buffer worked out about the lines when it held them, such as how wide each is, so that undoing a change to a million lines measures nothing again. A snapshot of another buffer may be restored too: the two buffers then share their lines, and what they work out about them, and must be changed on the same goroutine, as the rest of a model is. Positions cannot be followed through a restore with a Change.
func (*Buffer) Rev ΒΆ
Rev counts the changes made to the buffer, each edit, line appended, and time it is set, so that what is worked out from its text, such as the matches of a search, can be kept until it changes.
func (*Buffer) SetContent ΒΆ
SetContent replaces the buffer's lines with those of s, split at its newlines. A newline at the end of s ends its last line, rather than starting an empty one after it, and "" leaves the buffer empty.
func (*Buffer) SetLines ΒΆ
SetLines replaces the buffer's lines with lines. A line holding newlines is split at them.
func (*Buffer) SetWordChars ΒΆ
SetWordChars sets the characters other than letters and digits that are part of the words of the buffer's text, as Buffer.WordAt, Buffer.NextWord, and Buffer.PrevWord find them, and as a double click in a Viewport of the buffer selects them. Words are found as Unicode text segmentation (UAX #29) finds them, and are joined across these characters: "_" keeps snake_case one word, as an editor of code wants, and with "", words are as Unicode finds them.
A buffer never given any takes those of the Root that shows it in a viewport, set with WithWordChars, from the first frame it is drawn in, so that a double click and these methods find the same words. Until then, and in a buffer never shown, they are bloom's default set, "@-./_~?&=%+#", which keeps a path, a URL, or an email address one word.
func (*Buffer) Snapshot ΒΆ
Snapshot returns the buffer's text as it is, in a step, however many lines it holds: the snapshot shares the buffer's lines, and an edit after it copies the few parts of the buffer it changes, rather than changing them in place.
func (*Buffer) Text ΒΆ
Text returns the text of line i without its styles, with its tabs, as the function given to ViewportNode.Marks is given it, or "" when there is no such line.
func (*Buffer) TextIn ΒΆ
TextIn returns the text from from up to to, clamped, and swapped when from comes after to, without styles, as Buffer.Text gives each line, with the lines joined with newlines, such as to copy a selection.
func (*Buffer) WordAt ΒΆ
WordAt returns the start and the end of the word that the character after p, clamped, is in, or failing that, of the word that ends at p, and whether there is one, such as to select the word under a caret. Words are found as Buffer.SetWordChars tells. Only the text around p, up to the nearest whitespace either side, is looked through, however long its line is.
type CenterNode ΒΆ
type CenterNode struct {
// contains filtered or unexported fields
}
CenterNode places a child in its middle. Build one with Centered.
func Centered ΒΆ
func Centered(child Child) CenterNode
Centered places child at its natural size in the middle of the space it is given.
func (CenterNode) Focusable ΒΆ
func (n CenterNode) Focusable() CenterNode
Focusable makes the node one that Focus can move to.
func (CenterNode) ID ΒΆ
func (n CenterNode) ID(id ID) CenterNode
ID sets the ID that focus and Frame.Rect refer to the node by.
func (CenterNode) Layout ΒΆ
func (n CenterNode) Layout(Context) Child
Layout implements Child, returning the node itself: bloom lays it out without calling it.
func (CenterNode) NoTooltip ΒΆ
func (n CenterNode) NoTooltip() CenterNode
NoTooltip keeps the TextNode.Truncate nodes inside the node that are cut to fit from showing their full text as a tooltip, such as where the app shows it some other way. A tooltip given with Tooltip, to the node or to a node inside it, still shows, and so does the full text of a node pinned open with TooltipOpen.
func (CenterNode) On ΒΆ
func (n CenterNode) On(handlers ...on.Handler) CenterNode
On adds mouse handlers to the node, made by package on.
func (CenterNode) Selectable ΒΆ
func (n CenterNode) Selectable() CenterNode
Selectable lets the left button select text in the node by dragging over it, as a terminal selects text, but kept inside the node. Holding alt as the drag starts selects a rectangle of cells instead. The innermost selectable node under the pointer takes the drag, unless a node inside it has an on.Drag handler. See Root.Selection for the text selected.
func (CenterNode) Tooltip ΒΆ
func (n CenterNode) Tooltip(text string, opts ...TipOption) CenterNode
Tooltip gives the node a tooltip showing text, which a Root with tooltips on (see WithTooltips) draws beside it once the pointer has rested on it, or once a key press has moved the focus onto it. Without them it does nothing. A node without a tooltip of its own shows that of the nearest node it is inside that has one. On a TextNode.Truncate node, it shows in place of the full text the node was cut from. Empty text gives the node no tooltip. The text is drawn without the escape sequences that TextNode.Trusted keeps.
func (CenterNode) TooltipOpen ΒΆ
func (n CenterNode) TooltipOpen(open bool) CenterNode
TooltipOpen pins the node's tooltip open while open is true: a Root with tooltips on (see WithTooltips) shows it at once, without the pointer or the focus, and keys and the pointer do not close it. Several can be pinned at once, each placed where it covers none of the others or their nodes, and one that fits nowhere is left out of the frame. It shows the tooltip given with Tooltip, or for a TextNode.Truncate node cut to fit, its full text, even inside a node with NoTooltip, as the app asked for it. Text that fits, and a node without a tooltip, show nothing. Use it to show the full text of a row the app has selected, which bloom does not know of.
type Change ΒΆ
type Change struct {
// contains filtered or unexported fields
}
Change is what Buffer.Replace and the other edits did to a buffer, to follow positions through it with, such as the carets of an editor, or a selection, as the text changes under them. Its methods take positions in the buffer as it was before the change, and give them in the buffer as it is after. The zero value is a change that moves no position.
func (Change) End ΒΆ
End returns where the text put in by the change's last edit ends, in the buffer after it, which is where a caret goes after typing.
func (Change) Map ΒΆ
Map returns where position p of the buffer before the change is after it: unchanged before the text changed, moved with the text after it, and at the end of the text put in when it was within the text replaced. A position where text was put in stays before that text; see Change.MapAfter.
func (Change) MapAfter ΒΆ
MapAfter is Change.Map, but a position where text was put in goes after that text, as a caret where text is typed does.
type Child ΒΆ
Child is anything that can be placed in a layout: every node of this package, and any component that builds its own layout for the space it is given, which lets it change with its size. A component drawn from a View string, such as a Bubbles component, is placed with View, and a plain string with Text.
Layout must not change the component: it is called while measuring as well as for the final layout, and its result is reused for any space that differs only in a size it did not read from ctx. A node's Layout returns the node itself, as bloom lays nodes out without calling it, so a component can return a node, another component, or nil for nothing.
A component that is also used where a string is wanted, such as by a program that doesn't use bloom, can draw itself with Render, or with a Root it keeps, which skips drawing a frame that did not change.
type Context ΒΆ
type Context struct {
// contains filtered or unexported fields
}
Context is what a component is given to build its layout for: the space it has, and where it is.
The sizes a component reads are noted, so that bloom calls Layout again only when a size it read changes. A component that never reads its size, such as one that leaves sizing to the nodes it returns, is laid out once a frame wherever it is. A size read later, such as by a component it returned, or by the item builder of a list, is the one the component is laid out in by then.
func (Context) Frame ΒΆ
Frame returns the frame on screen when it is called, rather than when the component was laid out, for the mouse handlers it makes to read where its parts ended up when they run, such as which items of a List were shown or whether a node was laid out at all. In a handler, it is the frame the event was found in. Called from Layout itself, it is the frame before the one being laid out. Outside a Root, such as with Render, it is nil, which finds nothing.
func (Context) Height ΒΆ
Height returns the height available. Once layout is done it is the exact height the component was given.
func (Context) Side ΒΆ
Side returns the side or corner of its node that the layer the component is in was placed against with LayerNode.AnchorTo, which is the opposite of the one asked for when the layer did not fit there. A menu can use it to draw its edge facing the node. It reports false for a component that is not in a layer, or is in one that is not anchored to a node.
func (Context) Width ΒΆ
Width returns the width available. Once layout is done it is the exact width the component was given.
func (Context) WidthMethod ΒΆ
WidthMethod returns how the renderer laying out with ctx measures text, set with WithWidthMethod, for a component that measures or cuts strings itself, as with ansi.Method.StringWidth and ansi.Method.Truncate.
type CopyMsg ΒΆ
type CopyMsg struct {
// ID is the ID of the node the text was selected in, as in
// [SelectionMsg].
ID ID
// Text is the text copied.
Text string
// Err is what the function given with [WithClipboard] returned, such as
// when the system clipboard did not take the text. The text was sent to
// the terminal's clipboard with OSC 52 either way, which terminals do not
// answer, so a nil Err cannot promise the text arrived there.
Err error
}
CopyMsg is sent once Root.CopySelection has copied the text selected.
type Direction ΒΆ
Direction is a side or a corner of a node or of the screen, such as where a layer is anchored to a node, or where an effect starts from.
type DrawableNode ΒΆ
type DrawableNode struct {
// contains filtered or unexported fields
}
DrawableNode draws a uv.Drawable onto the cells it is given. Build one with Drawable.
func Drawable ΒΆ
func Drawable(d uv.Drawable) DrawableNode
Drawable returns a node that draws d directly onto the cells it is given, clipped to them. Its natural size is zero unless d implements Measurer.
func (DrawableNode) Focusable ΒΆ
func (n DrawableNode) Focusable() DrawableNode
Focusable makes the node one that Focus can move to.
func (DrawableNode) ID ΒΆ
func (n DrawableNode) ID(id ID) DrawableNode
ID sets the ID that focus and Frame.Rect refer to the node by.
func (DrawableNode) Layout ΒΆ
func (n DrawableNode) Layout(Context) Child
Layout implements Child, returning the node itself: bloom lays it out without calling it.
func (DrawableNode) NoTooltip ΒΆ
func (n DrawableNode) NoTooltip() DrawableNode
NoTooltip keeps the TextNode.Truncate nodes inside the node that are cut to fit from showing their full text as a tooltip, such as where the app shows it some other way. A tooltip given with Tooltip, to the node or to a node inside it, still shows, and so does the full text of a node pinned open with TooltipOpen.
func (DrawableNode) On ΒΆ
func (n DrawableNode) On(handlers ...on.Handler) DrawableNode
On adds mouse handlers to the node, made by package on.
func (DrawableNode) Tooltip ΒΆ
func (n DrawableNode) Tooltip(text string, opts ...TipOption) DrawableNode
Tooltip gives the node a tooltip showing text, which a Root with tooltips on (see WithTooltips) draws beside it once the pointer has rested on it, or once a key press has moved the focus onto it. Without them it does nothing. A node without a tooltip of its own shows that of the nearest node it is inside that has one. On a TextNode.Truncate node, it shows in place of the full text the node was cut from. Empty text gives the node no tooltip. The text is drawn without the escape sequences that TextNode.Trusted keeps.
func (DrawableNode) TooltipOpen ΒΆ
func (n DrawableNode) TooltipOpen(open bool) DrawableNode
TooltipOpen pins the node's tooltip open while open is true: a Root with tooltips on (see WithTooltips) shows it at once, without the pointer or the focus, and keys and the pointer do not close it. Several can be pinned at once, each placed where it covers none of the others or their nodes, and one that fits nowhere is left out of the frame. It shows the tooltip given with Tooltip, or for a TextNode.Truncate node cut to fit, its full text, even inside a node with NoTooltip, as the app asked for it. Text that fits, and a node without a tooltip, show nothing. Use it to show the full text of a row the app has selected, which bloom does not know of.
type Edit ΒΆ
Edit is a change to a buffer's text, as Buffer.Edit makes it: the text from From up to To replaced with Text.
type Editable ΒΆ
type Editable interface {
TextMap
// Selection returns what is selected, an empty range at the caret when
// nothing is.
Selection() Range
// Select sets what is selected, from the mouse.
Select(r Range)
}
Editable is a TextMap that keeps its own selection, such as an editor or an input, whose caret is the selection's Head. It keeps the range itself because its caret outlives the selection and is wanted while it handles a key, which may make or move the selection as often as the mouse does. The root does everything else: it sets the range from the mouse, draws it, copies it, and keeps one selection at a time across the screen.
A press puts the caret under the pointer, and with shift held moves the Head there and keeps the Anchor. The Root leaves Range.EndOfRow unset in the ranges it gives, since the methods of a TextMap tell positions in the text, not which side of a wrap a caret is drawn on. A drag moves the Head, running the range from where the caret went at the press to where it is under the pointer. A double click selects the word, and a triple click the line. Holding alt as the drag starts selects as a drag does. The positions given to Select may be past the end of a line or of the text: the component clamps them.
Every frame the root reads Selection and draws a range that holds text over the cells Cells reports, as it draws its own selection: the component draws no highlight of its own. A selection started anywhere else collapses the range to its Head. A range the component makes itself, such as with shift and an arrow key, becomes the selection as soon as the root sees it, in Root.Selection or Root.CopySelection in the same Update, or in the next frame, and any other is cleared. SelectionMsg is sent for what the mouse selects in it, and not for what the component selects.
Root.CopySelection copies Text of the range and leaves the range as it is, Root.ClearSelection collapses it to its Head, and Root.SelectAll, given the ID of the node the component is in, selects all of it.
The component must be placed in the tree by pointer, such as bloom.Fixed(1, &m.input), so that Select reaches the model's copy of it.
To edit the lines of a Buffer, give a Viewport a caret with ViewportNode.Caret rather than implementing Editable: it behaves as one.
type FlexNode ΒΆ
type FlexNode struct {
// contains filtered or unexported fields
}
FlexNode lays children out in a row or column. Build one with Row or Column.
func (FlexNode) ID ΒΆ
ID sets the ID that focus and Frame.Rect refer to the row or column by.
func (FlexNode) Layout ΒΆ
Layout implements Child, returning the row or column itself: bloom lays it out without calling it.
func (FlexNode) NoTooltip ΒΆ
NoTooltip keeps the TextNode.Truncate nodes inside the row or column that are cut to fit from showing their full text as a tooltip, such as where the app shows it some other way. A tooltip given with Tooltip, to the row or column or to a node inside it, still shows, and so does the full text of a node pinned open with TooltipOpen.
func (FlexNode) On ΒΆ
On adds mouse handlers to the node, made by package on. They take events on the gaps between children too.
func (FlexNode) Selectable ΒΆ
Selectable lets the left button select text in the row or column by dragging over it, as a terminal selects text, but kept inside the row or column. Holding alt as the drag starts selects a rectangle of cells instead. The innermost selectable node under the pointer takes the drag, unless a node inside it has an on.Drag handler. See Root.Selection for the text selected.
func (FlexNode) Tooltip ΒΆ
Tooltip gives the row or column a tooltip showing text, which a Root with tooltips on (see WithTooltips) draws beside it once the pointer has rested on it, or once a key press has moved the focus onto it. Without them it does nothing. A node without a tooltip of its own shows that of the nearest node it is inside that has one. On a TextNode.Truncate node, it shows in place of the full text the node was cut from. Empty text gives the row or column no tooltip. The text is drawn without the escape sequences that TextNode.Trusted keeps.
func (FlexNode) TooltipOpen ΒΆ
TooltipOpen pins the row or column's tooltip open while open is true: a Root with tooltips on (see WithTooltips) shows it at once, without the pointer or the focus, and keys and the pointer do not close it. Several can be pinned at once, each placed where it covers none of the others or their nodes, and one that fits nowhere is left out of the frame. It shows the tooltip given with Tooltip, or for a TextNode.Truncate node cut to fit, its full text, even inside a node with NoTooltip, as the app asked for it. Text that fits, and a row or column without a tooltip, show nothing. Use it to show the full text of a row the app has selected, which bloom does not know of.
type Focus ΒΆ
type Focus struct {
// contains filtered or unexported fields
}
Focus is which node has the keyboard focus, by its ID. Keep it in the model: the layout only says which nodes can be focused, with Focusable, and where focus scopes are.
const (
fieldName bloom.ID = "name"
fieldEmail bloom.ID = "email"
buttonSave bloom.ID = "save"
)
type model struct {
focus bloom.Focus
}
Focus.Push confines focus to a scope, such as a modal Layer, until Focus.Pop puts it back where it was:
case openConfirmMsg:
m.focus.Push(dialogConfirm)
m.focus.Set(buttonOK)
case closeConfirmMsg:
m.focus.Pop()
case tea.KeyPressMsg:
if msg.String() == "tab" {
m.focus.Next(m.ui.Frame())
}
func (*Focus) Next ΒΆ
Next focuses the next node that can be focused, in the order of frame, inside the innermost scope pushed, wrapping around. It reports whether there was one.
func (*Focus) Pop ΒΆ
func (f *Focus) Pop()
Pop leaves the innermost scope, focusing what was focused when it was pushed.
func (*Focus) Prev ΒΆ
Prev focuses the previous node that can be focused, as Focus.Next does.
func (*Focus) Push ΒΆ
Push confines focus to the scope with ID scope, clearing it until a node there is focused, and remembers the focus to go back to on Focus.Pop.
func (*Focus) Update ΒΆ
Update handles tab and shift+tab, which move the focus, and enter and space, which run the on.Press handlers of the focused node in frame. It returns their commands, and reports whether it handled msg: tab keys are handled even when frame has no focusable nodes, and enter and space only when the focused node has a Press handler that takes the key, rather than passing it on with on.Pass, such as a button that is disabled leaving enter to the form. Clicks move the focus with WithFocus.
type Frame ΒΆ
type Frame struct {
// contains filtered or unexported fields
}
Frame is the geometry of a laid-out frame: where each node with an ID went, which nodes can be focused, and what the mouse can hit, with the mouse handlers nodes were given. It does not change once made, so it is safe to keep.
func Solve ΒΆ
Solve lays out c in a wΓh frame without drawing it, and returns its geometry at animation targets. Solve is stateless; retained layout animations may draw intermediate rectangles. Components that need their target size in Update can use Solve there. Effects are not run, so a node a transition is moving, such as with fx.Slide, is where it was laid out:
case tea.WindowSizeMsg:
m.width, m.height = msg.Width, msg.Height
if r, ok := bloom.Solve(m.width, m.height, m.layout()).Rect(paneReader); ok {
m.reader.SetWidth(r.Dx())
m.reader.SetHeight(r.Dy())
}
func (*Frame) Hit ΒΆ
Hit returns the IDs of the nodes at x, y on screen that mouse events there reach, outermost first, so the last is the topmost node hit. It is nil when nothing with an ID is there, or when a modal layer takes the point although it is outside the layer. It is for handling a tea.MouseMsg in Update rather than with handlers.
func (*Frame) List ΒΆ
List returns which items the List with ID id showed, and whether it is in the frame. Use it in Update to page by ListView.Visible items, and to scroll from ListView.First, where the list actually was.
func (*Frame) Rect ΒΆ
Rect returns where the node with ID id was laid out, which may be partly off screen, and whether it is in the frame. Retained layout animations report the visual rectangle drawn this frame, except for a node moving with effects, such as with SlotNode.MoveWith, which is laid out where it goes from the start.
func (*Frame) Truncated ΒΆ
Truncated reports whether the TextNode.Truncate node with ID id was cut to fit in the frame, so it shows "β¦" in place of the rest of its text. It is false for a node that fits, that is not in the frame, or that is not truncated. A frame from Solve reports it too, as the node would be drawn.
func (*Frame) Viewport ΒΆ
func (f *Frame) Viewport(id ID) (ViewportView, bool)
Viewport returns where the Viewport with ID id was scrolled to, and whether it is in the frame. Use it in Update to scroll from where it actually was, with the methods of ViewportView.
type GridNode ΒΆ
type GridNode struct {
// contains filtered or unexported fields
}
GridNode lays children out in equal-width columns. Build one with Grid.
func Grid ΒΆ
Grid fills cols columns row by row; cols below one means one column. A short last row keeps the column widths. Each row is as tall as its tallest cell; rows share extra height equally, and give up height in proportion to their own when short of it. A slot child sizes its content horizontally within its cell.
func (GridNode) ID ΒΆ
ID sets the ID that focus and Frame.Rect refer to the grid by.
func (GridNode) Layout ΒΆ
Layout implements Child, returning the grid itself: bloom lays it out without calling it.
func (GridNode) NoTooltip ΒΆ
NoTooltip keeps the TextNode.Truncate nodes inside the grid that are cut to fit from showing their full text as a tooltip, such as where the app shows it some other way. A tooltip given with Tooltip, to the grid or to a node inside it, still shows, and so does the full text of a node pinned open with TooltipOpen.
func (GridNode) Selectable ΒΆ
Selectable lets the left button select text in the grid by dragging over it, as a terminal selects text, but kept inside the grid. Holding alt as the drag starts selects a rectangle of cells instead. The innermost selectable node under the pointer takes the drag, unless a node inside it has an on.Drag handler. See Root.Selection for the text selected.
func (GridNode) Tooltip ΒΆ
Tooltip gives the grid a tooltip showing text, which a Root with tooltips on (see WithTooltips) draws beside it once the pointer has rested on it, or once a key press has moved the focus onto it. Without them it does nothing. A node without a tooltip of its own shows that of the nearest node it is inside that has one. On a TextNode.Truncate node, it shows in place of the full text the node was cut from. Empty text gives the grid no tooltip. The text is drawn without the escape sequences that TextNode.Trusted keeps.
func (GridNode) TooltipOpen ΒΆ
TooltipOpen pins the grid's tooltip open while open is true: a Root with tooltips on (see WithTooltips) shows it at once, without the pointer or the focus, and keys and the pointer do not close it. Several can be pinned at once, each placed where it covers none of the others or their nodes, and one that fits nowhere is left out of the frame. It shows the tooltip given with Tooltip, or for a TextNode.Truncate node cut to fit, its full text, even inside a node with NoTooltip, as the app asked for it. Text that fits, and a grid without a tooltip, show nothing. Use it to show the full text of a row the app has selected, which bloom does not know of.
type GutterRow ΒΆ
type GutterRow struct {
// Line is the line the row shows, or -1 for a row below the last line,
// which shows none.
Line int
// Continued is set for a row after the first of a line that wraps.
Continued bool
// Lines is how many lines the buffer has, such as to size line numbers
// by.
Lines int
}
GutterRow is a row of a Viewport that a gutter is drawn beside.
type ID ΒΆ
type ID string
ID names a node for focus, for lookups such as Frame.Rect, and for anchoring and layout animation. IDs must be unique in a frame: two nodes with the same one are not told apart.
Make the IDs of an application or a component with NewID, which never returns the same ID twice, however they are named, and the IDs of their parts with ID.Sub:
var (
buttonConfirm = bloom.NewID("confirm")
dialogConfirm = bloom.NewID("confirm") // not the button's
)
type tabs struct{ id bloom.ID }
func newTabs() tabs { return tabs{id: bloom.NewID("tabs")} }
// in Layout, tab i:
bloom.Text(label).ID(t.id.Sub(i))
Any string is an ID too, for a small program or a test, where keeping them apart is left to you:
bloom.Fixed(24, m.sidebar).ID("sidebar")
m.ui.Click("sidebar")
The empty ID is no ID; ID.IsZero reports it.
func NewID ΒΆ
NewID returns an ID that no other call returns, whatever its name, shown as name followed by a number, such as "select#3". Make it once and keep it: in a package's variables for an application's IDs, or in a component when it is made, for each instance of it to have its own. A component that holds it can be copied.
func (ID) IsZero ΒΆ
IsZero reports whether id is the empty ID, the zero value of ID, which names no node.
func (ID) Sub ΒΆ
Sub returns the ID of a part of the node with ID id: a named part, such as Sub("title"), or one of many, such as Sub(i) for row i. It is id followed by "/" and the part, so two IDs made by NewID from names without a "/" never share a part. Keeping the parts of one ID apart is left to you: Sub(1) and Sub("1") are the same ID, and so are Sub("a/b") and Sub("a").Sub("b").
Each call makes a new string. A node drawn every frame can call it in Layout, as it costs as much as an ID made of a struct did; keep the result to make it only once.
type LayerNode ΒΆ
type LayerNode struct {
// contains filtered or unexported fields
}
LayerNode is a child of an Overlay, such as a dialog, placed over the base. Build one with Layer.
func Layer ΒΆ
Layer returns a layer showing child at its natural size, in the middle of its overlay.
func (LayerNode) AnchorTo ΒΆ
AnchorTo places the layer against side of the node with ID id, such as a dropdown below its input, and aligned with its start, shifted to stay inside the overlay. A corner places the layer diagonally off that corner of the node, such as below it and to its right for BottomRight. The zero value is Bottom.
A layer that does not fit on that side goes on the opposite one when it fits there, such as above its input near the bottom of the screen, and is shifted over the node otherwise. A corner flips each way on its own. A component in the layer reads the side it went on from Context.Side, and LayerNode.Offset is mirrored with it, so a gap stays between the layer and the node.
The node can be anywhere laid out before the layer: in the overlay's base, or, for a layer that floats, anywhere on screen. The layer is hidden while no such node is on screen.
func (LayerNode) Animate ΒΆ
Animate smoothly moves and resizes the layer when layout changes. It needs an ID and a retained Root; without either it does nothing. Options default to anim.NewValue and are captured when it starts animating. A layer drawn without Animate on the last frame, such as one following the pointer while dragged, glides from where it was then. Root controls the clock and FPS. A hidden anchor or removed layer disappears immediately.
func (LayerNode) Backdrop ΒΆ
Backdrop applies effects to everything drawn beneath the layer, with the layer's transition progress as their strength.
func (LayerNode) Float ΒΆ
Float places and draws the layer against the whole screen rather than the overlay it is in, so a component can keep its popover next to it, in its own overlay, without the popover being cut off at the edges of that overlay or of a dialog it is in:
bloom.Overlay(field, bloom.Layer(menu).AnchorTo(fieldID, bloom.Bottom).Float())
It is drawn once everything else in the layer its overlay is in, such as a dialog, has been drawn, or in the overlay base it is in, or in the whole tree, so it covers the rest of that, and layers declared after it, such as a toast, cover it. Inside a node drawn with effects, such as a dialog fading in, it waits for that node, and is drawn without them. It is shown only while its own overlay is on screen.
Mouse handlers, on.ClickOutside, modal layers, and focus treat it as part of what it is declared in: a click on it is not outside the dialog it is in, and its focusable nodes are in that dialog's focus scope. A modal layer that floats takes mouse events from the whole screen.
func (LayerNode) ID ΒΆ
ID sets the ID that focus, layout animation, anchoring, and Frame.Rect refer to the layer by.
func (LayerNode) Layout ΒΆ
Layout implements Child, returning the layer itself: bloom lays it out without calling it.
func (LayerNode) Margin ΒΆ
Margin keeps the layer at least cells away from the overlay's edges, or the screen's for a layer that floats, shrinking it if needed.
func (LayerNode) Modal ΒΆ
Modal makes the layer take every mouse event from what is beneath it. Clicks outside it run its on.ClickOutside handlers, such as to close a dialog when its backdrop is clicked. It is also a focus scope, for Focus.Push.
func (LayerNode) MoveWith ΒΆ
MoveWith has LayerNode.Animate move the layer with effects rather than by gliding, as SlotNode.MoveWith does a slot: it snaps to its new place, and effects draw it on its way there from where it was, over the layers before it. It does nothing without Animate.
func (LayerNode) NoTooltip ΒΆ
NoTooltip keeps the TextNode.Truncate nodes inside the layer that are cut to fit from showing their full text as a tooltip, such as where the app shows it some other way. A tooltip given with Tooltip, to the layer or to a node inside it, still shows, and so does the full text of a node pinned open with TooltipOpen.
func (LayerNode) Place ΒΆ
Place puts the layer at r in its overlay, or on the screen for a layer that floats, for a layer whose place and size the model keeps, such as a window that is dragged around. It is Anchor(Start, Start), Offset to r.Min, and Size of r's, which a zero width or height of r leaves to the child as Size does, and it undoes AnchorTo.
func (LayerNode) Presence ΒΆ
Presence sets the transition from p, omitting the entire layer, including its backdrop, shadow, and input entries, while p is not visible. While p animates out, the layer is still drawn but takes no input: its mouse handlers do not run, and its nodes cannot be focused, selected, or show tooltips. A modal layer still keeps events from what is beneath it until it is gone, unless another modal layer is beneath it, such as the next dialog of a stack, which then gets them.
func (LayerNode) Selectable ΒΆ
Selectable lets the left button select text in the layer by dragging over it, as a terminal selects text, but kept inside the layer. Holding alt as the drag starts selects a rectangle of cells instead. The innermost selectable node under the pointer takes the drag, unless a node inside it has an on.Drag handler. See Root.Selection for the text selected.
func (LayerNode) Shadow ΒΆ
Shadow applies effects to the frame beneath the layer, offset by x, y, the way a drop shadow darkens what is under it.
func (LayerNode) Size ΒΆ
Size sets the layer's size; zero for either is the child's natural size on that axis, measured with the other axis at the layer's size, so a layer of fixed width is as tall as its content wraps to at that width. The size is clamped to the overlay, or the screen for a layer that floats, less the margin.
func (LayerNode) Tooltip ΒΆ
Tooltip gives the layer a tooltip showing text, which a Root with tooltips on (see WithTooltips) draws beside it once the pointer has rested on it, or once a key press has moved the focus onto it. Without them it does nothing. A node without a tooltip of its own shows that of the nearest node it is inside that has one. On a TextNode.Truncate node, it shows in place of the full text the node was cut from. Empty text gives the layer no tooltip. The text is drawn without the escape sequences that TextNode.Trusted keeps.
func (LayerNode) TooltipOpen ΒΆ
TooltipOpen pins the layer's tooltip open while open is true: a Root with tooltips on (see WithTooltips) shows it at once, without the pointer or the focus, and keys and the pointer do not close it. Several can be pinned at once, each placed where it covers none of the others or their nodes, and one that fits nowhere is left out of the frame. It shows the tooltip given with Tooltip, or for a TextNode.Truncate node cut to fit, its full text, even inside a node with NoTooltip, as the app asked for it. Text that fits, and a layer without a tooltip, show nothing. Use it to show the full text of a row the app has selected, which bloom does not know of.
func (LayerNode) Transition ΒΆ
Transition draws the layer with effects applied to its cells for progress t, as with Transition, and sets the strength of its backdrop and shadow.
func (LayerNode) Transparent ΒΆ
Transparent lets what is beneath the layer show through the blank cells its child draws, rather than the layer covering its whole rectangle: cells holding a space with no background, underline, or reverse video. Use it for text drawn over other content, such as a banner from package fig, or ASCII art. A transparent layer is drawn into cells of its own each frame, as a layer with effects is.
type LayoutFunc ΒΆ
LayoutFunc is a function that builds a layout for the space it is given, placed as a Child: a responsive piece of a layout that needs no type of its own. A nil LayoutFunc lays out nothing, as a nil child does.
bloom.LayoutFunc(func(ctx bloom.Context) bloom.Child {
if ctx.Width() < 80 {
return bloom.Column(sidebar, body)
}
return bloom.Row(bloom.Fixed(30, sidebar), bloom.Fill(body))
})
type ListNode ΒΆ
type ListNode struct {
// contains filtered or unexported fields
}
ListNode shows as many items of a list as fit in the space it is given, laying out and drawing only those, however many items there are. Build one with List.
func List ΒΆ
List returns a list of count items, top to bottom, where item returns the node for item i. It is called only for items that may be shown, so a list of a million rows costs no more to draw than the rows on screen. Each item is as wide as the list and as tall as it wants. The list shows items from the first set with ListNode.Offset, cutting off the last one that does not fit, and never leaves space below its last item while there are items before the first that would fill it.
Frame.List tells which items a frame showed, and ScrollbarOf the list's ID makes a scrollbar for it, in items. In space of unbounded height, such as inside a Scroll, every item from the first is laid out.
Item is also called outside of a frame, in Update, to read the text of a selection in the list (see ListNode.Selectable): Root.Selection, Root.CopySelection, and the Root as it sends a SelectionMsg build the items selected that the last frame did not, at the width the list was laid out at. Until the next frame, item must give the items of the list as it was drawn, for any index below count, even after the program has changed what the list holds. When it panics then, such as with an index out of range, the panic is raised again saying so.
func (ListNode) ID ΒΆ
ID sets the ID that focus, Frame.Rect, Frame.List, and ScrollbarOf refer to the list by.
func (ListNode) ItemText ΒΆ
ItemText sets the text a selection takes from item i of the list when the item is selected whole and the list did not build it, such as when it is scrolled out of sight, rather than building the item to read it. It must return what selecting all of the item would: the text of its nodes, joined as a selection joins them, a line to a row and a space between nodes side by side. The items a selection starts and ends in are built to read, as it starts and ends at a place in them as laid out.
It is called outside of a frame, as item is (see List), for each such item every time the text is read.
func (ListNode) Keep ΒΆ
Keep scrolls the list as little as it can from its offset so that item i is shown whole, such as the item under a cursor. An item taller than the list is shown from its top. While it is given, the list cannot be scrolled away from item i: to let the wheel do that, move i along with the offset, or stop giving it.
func (ListNode) Layout ΒΆ
Layout implements Child, returning the list itself: bloom lays it out without calling it.
func (ListNode) NoTooltip ΒΆ
NoTooltip keeps the TextNode.Truncate nodes inside the list that are cut to fit from showing their full text as a tooltip, such as where the app shows it some other way. A tooltip given with Tooltip, to the list or to a node inside it, still shows, and so does the full text of a node pinned open with TooltipOpen.
func (ListNode) On ΒΆ
On adds mouse handlers to the list, made by package on. They take events on the gaps between items too, such as the wheel.
func (ListNode) Selectable ΒΆ
Selectable lets the left button select text in the list by dragging over it, as a terminal selects text, but kept inside the list. Holding alt as the drag starts selects a rectangle of cells instead. The innermost selectable node under the pointer takes the drag, unless a node inside it has an on.Drag handler. See Root.Selection for the text selected.
A selection is kept in the items it starts and ends in, by their index, so it stays as they scroll out of sight and back, and reaches the items between them, which the list does not build: dragging past the list's edge, when its on.Scroll handler moves its offset, takes the items that scroll into sight. The text selected is that of every item it covers, built or not. When the list's items change, the selection keeps to the same indexes, and ends when an index it is in is past the count, or the list leaves the frame. A rectangle selected with alt held is of the cells in sight: nothing is selected while a corner of it is scrolled away.
func (ListNode) Tooltip ΒΆ
Tooltip gives the list a tooltip showing text, which a Root with tooltips on (see WithTooltips) draws beside it once the pointer has rested on it, or once a key press has moved the focus onto it. Without them it does nothing. A node without a tooltip of its own shows that of the nearest node it is inside that has one. On a TextNode.Truncate node, it shows in place of the full text the node was cut from. Empty text gives the list no tooltip. The text is drawn without the escape sequences that TextNode.Trusted keeps.
func (ListNode) TooltipOpen ΒΆ
TooltipOpen pins the list's tooltip open while open is true: a Root with tooltips on (see WithTooltips) shows it at once, without the pointer or the focus, and keys and the pointer do not close it. Several can be pinned at once, each placed where it covers none of the others or their nodes, and one that fits nowhere is left out of the frame. It shows the tooltip given with Tooltip, or for a TextNode.Truncate node cut to fit, its full text, even inside a node with NoTooltip, as the app asked for it. Text that fits, and a list without a tooltip, show nothing. Use it to show the full text of a row the app has selected, which bloom does not know of.
type ListView ΒΆ
type ListView struct {
// First is the first item shown, which is where the list was scrolled to
// once its offset was clamped and [ListNode.Keep] applied. Keep it as the
// offset to scroll from.
First int
// Visible is how many items from First were shown whole, or 1 when the
// first is too tall to be, so a page is Visible items long. A last item
// that was cut off is not counted.
Visible int
// Count is how many items the list has.
Count int
}
ListView is the part of a List that a frame showed, as Frame.List reports it.
type Mark ΒΆ
type Mark struct {
// Start and End are the bytes of the line's text that are marked, End
// exclusive, as [regexp.Regexp.FindAllStringIndex] gives them for the
// text the function is given.
Start, End int
// Style's colors and attributes are drawn over the text marked.
Style lipgloss.Style
}
Mark is part of a line drawn in a style of its own, such as a match of a search, as a function given to ViewportNode.Marks returns it.
type MarqueeNode ΒΆ
type MarqueeNode struct {
// contains filtered or unexported fields
}
MarqueeNode is a line of text that scrolls when it does not fit. Build one with Marquee.
func Marquee ΒΆ
func Marquee(s string, phase float64) MarqueeNode
Marquee returns a single line showing s, a string that may hold ANSI styles and whose newlines are shown as spaces. Text that fits its width is shown as it is, at its natural width, so the node shrinks in a Fill slot. Text that does not fit is cut off with "β¦" while phase is 0, and otherwise scrolls: phase from 0 to 1 moves it one full loop, the text and the gap after it, wrapping around seamlessly. A phase outside that range wraps.
Show a marquee at phase 0 until something, such as focus, gives it a phase to scroll with. A looping Sequence from package anim can drive it:
anim.NewSequence(0, anim.Jump(0), anim.To(1, anim.Duration(8*time.Second), anim.Ease(anim.Linear)))
func (MarqueeNode) Focusable ΒΆ
func (n MarqueeNode) Focusable() MarqueeNode
Focusable makes the marquee one that Focus can move to.
func (MarqueeNode) Gap ΒΆ
func (n MarqueeNode) Gap(s string) MarqueeNode
Gap sets what is shown between the end of the text and its start again while scrolling, three spaces by default.
func (MarqueeNode) ID ΒΆ
func (n MarqueeNode) ID(id ID) MarqueeNode
ID sets the ID that focus and Frame.Rect refer to the marquee by.
func (MarqueeNode) Layout ΒΆ
func (n MarqueeNode) Layout(ctx Context) Child
Layout implements Child.
func (MarqueeNode) NoTooltip ΒΆ
func (n MarqueeNode) NoTooltip() MarqueeNode
NoTooltip keeps the TextNode.Truncate nodes inside the marquee that are cut to fit from showing their full text as a tooltip, such as where the app shows it some other way. A tooltip given with Tooltip, to the marquee or to a node inside it, still shows, and so does the full text of a node pinned open with TooltipOpen.
func (MarqueeNode) On ΒΆ
func (n MarqueeNode) On(handlers ...on.Handler) MarqueeNode
On adds mouse handlers to the marquee, made by package on.
func (MarqueeNode) Selectable ΒΆ
func (n MarqueeNode) Selectable() MarqueeNode
Selectable lets the left button select text in the marquee by dragging over it, as a terminal selects text, but kept inside the marquee. Holding alt as the drag starts selects a rectangle of cells instead. The innermost selectable node under the pointer takes the drag, unless a node inside it has an on.Drag handler. See Root.Selection for the text selected.
func (MarqueeNode) Style ΒΆ
func (n MarqueeNode) Style(style lipgloss.Style) MarqueeNode
Style renders the text with style, at the size the node is given as TextNode.Style does, so a background fills it. The style's padding and borders count against the width the text has to scroll in.
func (MarqueeNode) Tooltip ΒΆ
func (n MarqueeNode) Tooltip(text string, opts ...TipOption) MarqueeNode
Tooltip gives the marquee a tooltip showing text, which a Root with tooltips on (see WithTooltips) draws beside it once the pointer has rested on it, or once a key press has moved the focus onto it. Without them it does nothing. A node without a tooltip of its own shows that of the nearest node it is inside that has one. On a TextNode.Truncate node, it shows in place of the full text the node was cut from. Empty text gives the marquee no tooltip. The text is drawn without the escape sequences that TextNode.Trusted keeps.
func (MarqueeNode) TooltipOpen ΒΆ
func (n MarqueeNode) TooltipOpen(open bool) MarqueeNode
TooltipOpen pins the marquee's tooltip open while open is true: a Root with tooltips on (see WithTooltips) shows it at once, without the pointer or the focus, and keys and the pointer do not close it. Several can be pinned at once, each placed where it covers none of the others or their nodes, and one that fits nowhere is left out of the frame. It shows the tooltip given with Tooltip, or for a TextNode.Truncate node cut to fit, its full text, even inside a node with NoTooltip, as the app asked for it. Text that fits, and a marquee without a tooltip, show nothing. Use it to show the full text of a row the app has selected, which bloom does not know of.
type Match ΒΆ
type Match struct {
Line, Start, End int
}
Match is where a regular expression matched the text of a line, as Buffer.Find finds it: the bytes from Start to End, End exclusive, of Buffer.Text of the line.
type Measurer ΒΆ
Measurer is a component that knows its natural size, so it is not measured from what it lays out or draws. It is checked on a component, on the Viewer of a View, and on the drawable of a Drawable. Measure returns the size the component wants within avail; the result is clamped to avail. Return what the component needs, not avail itself: when a layout is drawn at its natural size, avail is unbounded.
type MinSizeNode ΒΆ
type MinSizeNode struct {
// contains filtered or unexported fields
}
MinSizeNode draws its child only when it is given at least a minimum size, and a note saying the space is too small otherwise. Build one with MinSize.
func MinSize ΒΆ
func MinSize(w, h int, child Child) MinSizeNode
MinSize draws child when it is given at least wΓh cells, and in a smaller space draws a line in its middle, faded toward the terminal's background, saying the window is too small and what it needs, such as "window too small, min 80x24", or only "window too small" where the rest does not fit. A w or h of zero or less has no minimum on that axis.
Where it fits, its natural size is at least wΓh, so in a slot sized by its content, or drawn at its natural height as Root.Render does for a height of zero, it is given its minimum. Wrap the root of a model's layout in it for an application that cannot be used below some size:
func (m *model) View() tea.View {
return m.ui.View(m.width, m.height, bloom.MinSize(80, 24, m.layout()))
}
While the note is drawn the child is not laid out, so its nodes are not in the frame: their mouse handlers do not run and Focus skips them. Keys still reach the model, which can compare its own size with the minimum to ignore them.
func (MinSizeNode) Focusable ΒΆ
func (n MinSizeNode) Focusable() MinSizeNode
Focusable makes the node one that Focus can move to.
func (MinSizeNode) ID ΒΆ
func (n MinSizeNode) ID(id ID) MinSizeNode
ID sets the ID that focus and Frame.Rect refer to the node by.
func (MinSizeNode) Layout ΒΆ
func (n MinSizeNode) Layout(ctx Context) Child
Layout implements Child, returning the child, or the note when the space is too small. It reads only the sizes it has a minimum for, so the child is laid out again only when one of those changes.
func (MinSizeNode) NoTooltip ΒΆ
func (n MinSizeNode) NoTooltip() MinSizeNode
NoTooltip keeps the TextNode.Truncate nodes inside the node that are cut to fit from showing their full text as a tooltip, such as where the app shows it some other way. A tooltip given with Tooltip, to the node or to a node inside it, still shows, and so does the full text of a node pinned open with TooltipOpen.
func (MinSizeNode) On ΒΆ
func (n MinSizeNode) On(handlers ...on.Handler) MinSizeNode
On adds mouse handlers to the node, made by package on.
func (MinSizeNode) Selectable ΒΆ
func (n MinSizeNode) Selectable() MinSizeNode
Selectable lets the left button select text in the node by dragging over it, as a terminal selects text, but kept inside the node. Holding alt as the drag starts selects a rectangle of cells instead. The innermost selectable node under the pointer takes the drag, unless a node inside it has an on.Drag handler. See Root.Selection for the text selected.
func (MinSizeNode) Tooltip ΒΆ
func (n MinSizeNode) Tooltip(text string, opts ...TipOption) MinSizeNode
Tooltip gives the node a tooltip showing text, which a Root with tooltips on (see WithTooltips) draws beside it once the pointer has rested on it, or once a key press has moved the focus onto it. Without them it does nothing. A node without a tooltip of its own shows that of the nearest node it is inside that has one. On a TextNode.Truncate node, it shows in place of the full text the node was cut from. Empty text gives the node no tooltip. The text is drawn without the escape sequences that TextNode.Trusted keeps.
func (MinSizeNode) TooltipOpen ΒΆ
func (n MinSizeNode) TooltipOpen(open bool) MinSizeNode
TooltipOpen pins the node's tooltip open while open is true: a Root with tooltips on (see WithTooltips) shows it at once, without the pointer or the focus, and keys and the pointer do not close it. Several can be pinned at once, each placed where it covers none of the others or their nodes, and one that fits nowhere is left out of the frame. It shows the tooltip given with Tooltip, or for a TextNode.Truncate node cut to fit, its full text, even inside a node with NoTooltip, as the app asked for it. Text that fits, and a node without a tooltip, show nothing. Use it to show the full text of a row the app has selected, which bloom does not know of.
type Option ΒΆ
type Option func(*config)
Option configures a Root.
func WithClickDelay ΒΆ
WithClickDelay sets whether a click inside a node made selectable waits until it can no longer become a double click before its click handlers run, so that double clicking to select a word does not also click what it is in. A double or triple click there selects rather than clicks. It is on by default; off, clicks run at once, and a double click is two.
func WithClipboard ΒΆ
WithClipboard sets the function Root.CopySelection writes text to the system clipboard with, such as one that runs xclip or wl-copy. It runs first, and the text then goes to the terminal's clipboard with OSC 52, which also reaches a terminal over SSH; what it returns is sent in CopyMsg. A function that cannot reach a system clipboard at all, such as over SSH, should return nil, leaving the copy to OSC 52.
func WithClock ΒΆ
WithClock sets the clock for layout animations and for telling double clicks apart, for tests. It must not be nil.
func WithColors ΒΆ
WithColors sets the terminal's default colors, for effects that blend colors, until the terminal reports its own (see Root.Init).
func WithCopyFlash ΒΆ
WithCopyFlash sets whether Root.CopySelection sweeps a band of the selection's color across the text it copied, to show what went. It is on by default, and the band only sweeps while anim.Motion is on.
func WithFPS ΒΆ
WithFPS sets the layout animation tick rate, defaulting to 60. Values below one use one frame per second.
func WithFocus ΒΆ
WithFocus lets clicks move the model's focus: a click focuses the innermost node under the pointer that f can focus, as Focus.Next would, before any handler for the click runs, so a handler can move the focus on from there. With tooltips on (see WithTooltips), a key press that moves the focus onto a node shows the node's tooltip. f also picks the terminal cursor: one given inside a focusable node f moves to is shown only while that node is focused (see TextNode.Cursor). f must stay where it is, as a field of a model used by pointer does.
func WithSelectionStyle ΒΆ
WithSelectionStyle sets how text selected with the mouse is drawn: with the style's foreground and background, and its bold, italic, faint, underline, strikethrough, and reverse. A color the style leaves unset is kept from each cell, such as a background alone to keep the colors of highlighted code; a foreground kept that would be hard to read on the background, such as a dim one, takes the terminal's default foreground or background instead, whichever reads better.
Without it, selected cells get a background between the terminal's default background and foreground, and keep their own foregrounds where they can be read on it.
func WithTooltips ΒΆ
WithTooltips turns tooltips on, configured with t. Without it, they are off: a node's Tooltip does nothing, and drawing a frame costs nothing more. Root.EnableTooltips turns them on and off again.
func WithUnfocusedFPS ΒΆ
WithUnfocusedFPS sets the layout animation tick rate while the terminal is not focused, defaulting to 20, and never above WithFPS. Terminals report focus only while tea.View ReportFocus is set, as on the view from Root.View; until they do, the root counts the terminal as focused.
func WithWidthMethod ΒΆ
WithWidthMethod sets how the width of graphemes is measured. It must match the terminal's, which Bubble Tea measures with ansi.GraphemeWidth when the terminal supports it. The default is ansi.GraphemeWidth, as Lip Gloss uses.
func WithWordChars ΒΆ
WithWordChars sets the characters other than letters and digits that a double click takes into a word. Words are found as Unicode text segmentation (UAX #29) finds them, and are joined across these characters, so that the default, "@-./_~?&=%+#", keeps a path, a URL, or an email address one word. With "", words are as Unicode finds them.
A double click in a Viewport finds the word in its buffer's text, so that a word its lines wrap across rows is selected whole, with the characters the buffer was given with Buffer.SetWordChars, and these when it was given none: such a buffer takes these for Buffer.WordAt, Buffer.NextWord, and Buffer.PrevWord too, once it is shown. Elsewhere, such as in a Text or a TextMap, it finds the word in the cells drawn on the row, with these.
type OverlayNode ΒΆ
type OverlayNode struct {
// contains filtered or unexported fields
}
OverlayNode puts layers over a base. Build one with Overlay.
func Overlay ΒΆ
func Overlay(base Child, layers ...LayerNode) OverlayNode
Overlay draws layers, in order, over base, which gets all the overlay's space. Layers do not take space from the base.
func (OverlayNode) Focusable ΒΆ
func (n OverlayNode) Focusable() OverlayNode
Focusable makes the overlay one that Focus can move to.
func (OverlayNode) ID ΒΆ
func (n OverlayNode) ID(id ID) OverlayNode
ID sets the ID that focus and Frame.Rect refer to the overlay by.
func (OverlayNode) Layout ΒΆ
func (n OverlayNode) Layout(Context) Child
Layout implements Child, returning the overlay itself: bloom lays it out without calling it.
func (OverlayNode) NoTooltip ΒΆ
func (n OverlayNode) NoTooltip() OverlayNode
NoTooltip keeps the TextNode.Truncate nodes inside the overlay that are cut to fit from showing their full text as a tooltip, such as where the app shows it some other way. A tooltip given with Tooltip, to the overlay or to a node inside it, still shows, and so does the full text of a node pinned open with TooltipOpen.
func (OverlayNode) On ΒΆ
func (n OverlayNode) On(handlers ...on.Handler) OverlayNode
On adds mouse handlers to the overlay, made by package on.
func (OverlayNode) Selectable ΒΆ
func (n OverlayNode) Selectable() OverlayNode
Selectable lets the left button select text in the overlay by dragging over it, as a terminal selects text, but kept inside the overlay. Holding alt as the drag starts selects a rectangle of cells instead. The innermost selectable node under the pointer takes the drag, unless a node inside it has an on.Drag handler. See Root.Selection for the text selected.
func (OverlayNode) Tooltip ΒΆ
func (n OverlayNode) Tooltip(text string, opts ...TipOption) OverlayNode
Tooltip gives the overlay a tooltip showing text, which a Root with tooltips on (see WithTooltips) draws beside it once the pointer has rested on it, or once a key press has moved the focus onto it. Without them it does nothing. A node without a tooltip of its own shows that of the nearest node it is inside that has one. On a TextNode.Truncate node, it shows in place of the full text the node was cut from. Empty text gives the overlay no tooltip. The text is drawn without the escape sequences that TextNode.Trusted keeps.
func (OverlayNode) TooltipOpen ΒΆ
func (n OverlayNode) TooltipOpen(open bool) OverlayNode
TooltipOpen pins the overlay's tooltip open while open is true: a Root with tooltips on (see WithTooltips) shows it at once, without the pointer or the focus, and keys and the pointer do not close it. Several can be pinned at once, each placed where it covers none of the others or their nodes, and one that fits nowhere is left out of the frame. It shows the tooltip given with Tooltip, or for a TextNode.Truncate node cut to fit, its full text, even inside a node with NoTooltip, as the app asked for it. Text that fits, and a overlay without a tooltip, show nothing. Use it to show the full text of a row the app has selected, which bloom does not know of.
type Pos ΒΆ
type Pos struct{ Line, Col int }
Pos is a place in a buffer's text: a line, and a byte of that line's text as Buffer.Text gives it, without styles, a tab one byte, the unit a Mark and a Match count in. A position is between two characters, or at the start or end of a line, so that Col is the length of the line's text at its end.
type Range ΒΆ
type Range struct {
Anchor, Head Pos
// EndOfRow says which side of a wrap the caret is drawn on. The place
// where a line wraps is one position in its text but two places on the
// screen, the end of a row and the start of the next, and a caret there
// is drawn at the start of the next row unless EndOfRow is set, as the
// end key and a click past the end of the row set it. It means nothing
// anywhere else: it is ignored where Head is not a place its line wraps,
// in a viewport whose lines do not wrap, and by everything that reads
// the text, such as the selection drawn and copied.
EndOfRow bool
}
Range is a run of text from Anchor to Head, which may come before it. A selection is one, with the caret at Head, where it was moved to, and the Anchor where it started.
func (Range) Collapse ΒΆ
Collapse returns the empty range at r's Head, keeping EndOfRow, so that a caret at the end of a row stays there.
func (Range) WithHead ΒΆ
WithHead returns r with its Head moved to p, its Anchor kept, and EndOfRow cleared, as a caret moved through the text, rather than by rows, is drawn at the start of a row. Moving the Head and then collapsing the range unless shift is held moves a caret or extends a selection:
m.sel = m.sel.WithHead(m.buf.NextWord(m.sel.Head))
if !shift {
m.sel = m.sel.Collapse()
}
type Root ΒΆ
type Root struct {
// contains filtered or unexported fields
}
Root renders a layout as a model's tea.View, keeping what it can between frames. Keep one in the root model, by pointer, and pass it the model's layout from View. Pass every message to Root.Update and return its command.
func (*Root) ClearSelection ΒΆ
func (r *Root) ClearSelection()
ClearSelection clears the text selected with the mouse, if any, such as when escape is pressed. The range of an Editable, or of a viewport's caret, that is the selection is collapsed to its Head.
func (*Root) Click ΒΆ
Click runs the handlers for a click of the left button in the middle of the part of the node with ID id that is on screen, as Root.ClickAt does, and reports whether the node is on screen.
func (*Root) ClickAt ΒΆ
ClickAt runs the handlers for a click of the left button at x, y, as a press and a release with nothing drawn between them, and returns their commands. It is for tests, which can also pass any tea.MouseMsg to Root.Update.
func (*Root) CopySelection ΒΆ
CopySelection copies the text selected with the mouse to the clipboard, with the function given with WithClipboard and with OSC 52, clears the selection, and sweeps a band across the text copied (see WithCopyFlash). It returns nil when nothing is selected, so ctrl+c can copy, or quit with nothing to copy:
case "ctrl+c":
if cmd := m.ui.CopySelection(); cmd != nil {
return m, cmd
}
return m, tea.Quit
A CopyMsg is sent once the text is copied.
The range of an Editable, or of a viewport's caret, is copied and left as it is, and the band sweeps across it in place of the selection's color until the band has crossed it, or the range changes.
func (*Root) EnableTooltips ΒΆ
EnableTooltips turns tooltips on or off, such as for a setting of the user's. Turning them off closes the one showing.
func (*Root) Frame ΒΆ
Frame returns the geometry of the last frame rendered, for moving focus with Focus and for finding where nodes are on screen.
func (*Root) Init ΒΆ
Init asks the terminal for its default colors, which effects that blend colors use. Return it from the model's Init. Pass every message to Root.Update and return its command from the model's Update.
func (*Root) Render ΒΆ
Render lays out and draws c in a wΓh frame and returns it as a string. A height of zero or less is c's natural height, for programs that do not use the whole screen. Nothing is drawn while the width is zero or less, as it is before Bubble Tea reports the window's size.
func (*Root) SelectAll ΒΆ
SelectAll selects all the text of the node with ID id, or of its nearest ancestor made selectable, including what is scrolled out of sight and every item of a List in it, such as for ctrl+a, and reports whether there is such a node in the last frame with any text. One without text clears the selection. It can be copied at once, with Root.CopySelection. No SelectionMsg is sent for it. It costs no more for a list of many items: their text is read only when it is wanted.
The ID of an Editable's node, or of a node it is in that is not made selectable itself, selects all of the Editable's text, as its range, and so does that of a viewport given ViewportNode.Caret, of its buffer.
func (*Root) Selection ΒΆ
Selection returns the text selected with the mouse and whether any is selected, as laid out in the last frame. Text is read from the nodes inside the node selected in: all of a Text or component, including what is scrolled out of sight, with the lines that a text wrapped to fit joined again, and from a TextSource, what it says it shows. Text drawn around them, such as a Box's border, is not selected. Every item of a List that the selection covers is read, including those the last frame did not build, which are built now to read, as the list would build them, or read with ListNode.ItemText. The text is kept until the next frame, so reading it again costs nothing, unless it was read from a TextMap or TextSource, which is asked again.
The selection may be the range of an Editable, or of a viewport given ViewportNode.Caret, made with the mouse or by the program, which is read from it: a range made since the last frame is seen at once.
func (*Root) SetTooltips ΒΆ
SetTooltips replaces the configuration of tooltips, such as for a new theme, without turning them on or off.
func (*Root) Tooltip ΒΆ
Tooltip returns the text of the tooltip of the pointer or the focus showing now, however it is shown, and reports false while none is. It is not one pinned open. It is what the root last drew, or opened since, so read it in View, before the frame is drawn.
It is for an app that shows the tooltip itself, such as in a status line of its own. To have the root draw nothing for it, set the Tooltips mode of its kind to TipHidden, which still has it open and close as it otherwise would. TooltipSink is a node that shows it in the frame it opens in, for an app that only needs it placed.
func (*Root) Update ΒΆ
Update notes what the terminal reports about itself: its default colors, color profile, and focus. Pass every message to Update and return its command: it schedules frames while layout animations run, fewer while the terminal is not focused (see WithUnfocusedFPS), and returns the commands of mouse handlers it runs. It runs them for mouse events that the OnMouse handler of Root.View did not see, such as when the view is built some other way, and runs on.Hover handlers as nodes move under the pointer or the window loses focus.
func (*Root) View ΒΆ
View lays out and draws c in a wΓh frame, and returns a view showing it, with the cursor of the TextNode that placed one, and an OnMouse handler that runs the mouse handlers of the nodes under the pointer in this frame, which is the one on screen when Bubble Tea calls it, or in the latest frame if that draws the same. It runs them on the event loop, before Update gets the event, so they can change the model, and returns their commands to run in the background.
The view's MouseMode is the least the frame needs: all motion while a node follows the pointer with a hover style or on.Hover, or has a tooltip that the pointer can open, and otherwise cell motion while a node takes clicks, the wheel, or drags, is selectable, or can be focused with a click (see WithFocus). Tooltips pinned open need nothing. Set the field on the view returned to ask for something else.
type ScrollNode ΒΆ
type ScrollNode struct {
// contains filtered or unexported fields
}
ScrollNode shows part of a child bigger than the space it is given. Build one with Scroll.
func Scroll ΒΆ
func Scroll(child Child, offset int) ScrollNode
Scroll gives child as much height as it wants and shows it from row offset, clipped to the space the scroll is given. The child is measured and drawn whole, so content far larger than the screen, such as a long log, is best windowed by the component itself.
func (ScrollNode) Focusable ΒΆ
func (n ScrollNode) Focusable() ScrollNode
Focusable makes the scroll one that Focus can move to.
func (ScrollNode) ID ΒΆ
func (n ScrollNode) ID(id ID) ScrollNode
ID sets the ID that focus and Frame.Rect refer to the scroll by.
func (ScrollNode) Layout ΒΆ
func (n ScrollNode) Layout(Context) Child
Layout implements Child, returning the scroll itself: bloom lays it out without calling it.
func (ScrollNode) NoTooltip ΒΆ
func (n ScrollNode) NoTooltip() ScrollNode
NoTooltip keeps the TextNode.Truncate nodes inside the scroll that are cut to fit from showing their full text as a tooltip, such as where the app shows it some other way. A tooltip given with Tooltip, to the scroll or to a node inside it, still shows, and so does the full text of a node pinned open with TooltipOpen.
func (ScrollNode) On ΒΆ
func (n ScrollNode) On(handlers ...on.Handler) ScrollNode
On adds mouse handlers to the scroll, made by package on.
func (ScrollNode) Selectable ΒΆ
func (n ScrollNode) Selectable() ScrollNode
Selectable lets the left button select text in the scroll by dragging over it, as a terminal selects text, but kept inside the scroll. Holding alt as the drag starts selects a rectangle of cells instead. The innermost selectable node under the pointer takes the drag, unless a node inside it has an on.Drag handler. See Root.Selection for the text selected.
func (ScrollNode) Tooltip ΒΆ
func (n ScrollNode) Tooltip(text string, opts ...TipOption) ScrollNode
Tooltip gives the scroll a tooltip showing text, which a Root with tooltips on (see WithTooltips) draws beside it once the pointer has rested on it, or once a key press has moved the focus onto it. Without them it does nothing. A node without a tooltip of its own shows that of the nearest node it is inside that has one. On a TextNode.Truncate node, it shows in place of the full text the node was cut from. Empty text gives the scroll no tooltip. The text is drawn without the escape sequences that TextNode.Trusted keeps.
func (ScrollNode) TooltipOpen ΒΆ
func (n ScrollNode) TooltipOpen(open bool) ScrollNode
TooltipOpen pins the scroll's tooltip open while open is true: a Root with tooltips on (see WithTooltips) shows it at once, without the pointer or the focus, and keys and the pointer do not close it. Several can be pinned at once, each placed where it covers none of the others or their nodes, and one that fits nowhere is left out of the frame. It shows the tooltip given with Tooltip, or for a TextNode.Truncate node cut to fit, its full text, even inside a node with NoTooltip, as the app asked for it. Text that fits, and a scroll without a tooltip, show nothing. Use it to show the full text of a row the app has selected, which bloom does not know of.
func (ScrollNode) X ΒΆ
func (n ScrollNode) X(offset int) ScrollNode
X scrolls the child sideways too: it gets as much width as it wants, such as for lines that should not wrap, and is shown from column offset. Without it, the child gets the scroll's width.
type ScrollbarNode ΒΆ
type ScrollbarNode struct {
// contains filtered or unexported fields
}
ScrollbarNode is a scrollbar, one column wide, or one row tall when horizontal, that shows which part of some content is in view. Build one with Scrollbar or ScrollbarOf.
It is drawn only while the content is bigger than its view, so given to BoxNode.Edge on a border, it shows over the border while there is more to scroll to, and takes no space. Its natural length is zero, so place it with Stretch there, or in a Row, or a Column when horizontal, which stretches it across.
func Scrollbar ΒΆ
func Scrollbar(total, visible, offset int) ScrollbarNode
Scrollbar returns a scrollbar for content of total rows, visible of them in view from row offset, as a Bubbles viewport reports with TotalLineCount, VisibleLineCount, and YOffset. When horizontal, they are columns.
func ScrollbarOf ΒΆ
func ScrollbarOf(id ID) ScrollbarNode
ScrollbarOf returns a scrollbar for the Scroll that the node with ID id is in, or for the List with ID id, in items, which follows it from its layout, with no state of its own. It is not drawn while there is no such node on screen.
func (ScrollbarNode) Focusable ΒΆ
func (n ScrollbarNode) Focusable() ScrollbarNode
Focusable makes the scrollbar one that Focus can move to while it is drawn.
func (ScrollbarNode) Horizontal ΒΆ
func (n ScrollbarNode) Horizontal() ScrollbarNode
Horizontal makes the scrollbar one row tall, for content scrolled sideways, such as with ScrollNode.X, and for a border's top or bottom.
func (ScrollbarNode) HoverStyle ΒΆ
func (n ScrollbarNode) HoverStyle(style ScrollbarStyle) ScrollbarNode
HoverStyle sets how the scrollbar looks while the pointer is over it, or while it is being dragged, in place of its ScrollbarNode.Style, whole. Without one, it looks the same under the pointer. To grow a vertical thumb, set its glyph to "β":
sb.Style(bloom.ScrollbarStyle{ThumbStyle: thumb}).
HoverStyle(bloom.ScrollbarStyle{Thumb: "β", ThumbStyle: thumb})
Only a scrollbar that takes the mouse, with ScrollbarNode.OnScroll or from the viewport it follows, is hovered, which needs mouse motion reported with no button down, as Root.View then asks for.
func (ScrollbarNode) ID ΒΆ
func (n ScrollbarNode) ID(id ID) ScrollbarNode
ID sets the ID that focus and Frame.Rect refer to the scrollbar by. It is in the frame only while it is drawn.
func (ScrollbarNode) Layout ΒΆ
func (n ScrollbarNode) Layout(Context) Child
Layout implements Child, returning the scrollbar itself: bloom lays it out without calling it.
func (ScrollbarNode) NoTooltip ΒΆ
func (n ScrollbarNode) NoTooltip() ScrollbarNode
NoTooltip keeps the TextNode.Truncate nodes inside the scrollbar that are cut to fit from showing their full text as a tooltip, such as where the app shows it some other way. A tooltip given with Tooltip, to the scrollbar or to a node inside it, still shows, and so does the full text of a node pinned open with TooltipOpen.
func (ScrollbarNode) On ΒΆ
func (n ScrollbarNode) On(handlers ...on.Handler) ScrollbarNode
On adds mouse handlers to the scrollbar, made by package on, beside the one of ScrollbarNode.OnScroll. They take events only while it is drawn.
func (ScrollbarNode) OnScroll ΒΆ
func (n ScrollbarNode) OnScroll(fn func(offset int) tea.Cmd) ScrollbarNode
OnScroll runs fn with the offset to scroll to when the scrollbar is used with the mouse, so it needs no state in the model beyond the offset itself. Pressing on the thumb and moving drags it; pressing on the rest of the scrollbar jumps so the thumb is centered on the pointer, and holding the button down drags it from there.
func (ScrollbarNode) Style ΒΆ
func (n ScrollbarNode) Style(style ScrollbarStyle) ScrollbarNode
Style sets how the scrollbar looks. See ScrollbarStyle for the defaults.
func (ScrollbarNode) Tooltip ΒΆ
func (n ScrollbarNode) Tooltip(text string, opts ...TipOption) ScrollbarNode
Tooltip gives the scrollbar a tooltip showing text, which a Root with tooltips on (see WithTooltips) draws beside it once the pointer has rested on it, or once a key press has moved the focus onto it. Without them it does nothing. A node without a tooltip of its own shows that of the nearest node it is inside that has one. On a TextNode.Truncate node, it shows in place of the full text the node was cut from. Empty text gives the scrollbar no tooltip. The text is drawn without the escape sequences that TextNode.Trusted keeps.
func (ScrollbarNode) TooltipOpen ΒΆ
func (n ScrollbarNode) TooltipOpen(open bool) ScrollbarNode
TooltipOpen pins the scrollbar's tooltip open while open is true: a Root with tooltips on (see WithTooltips) shows it at once, without the pointer or the focus, and keys and the pointer do not close it. Several can be pinned at once, each placed where it covers none of the others or their nodes, and one that fits nowhere is left out of the frame. It shows the tooltip given with Tooltip, or for a TextNode.Truncate node cut to fit, its full text, even inside a node with NoTooltip, as the app asked for it. Text that fits, and a scrollbar without a tooltip, show nothing. Use it to show the full text of a row the app has selected, which bloom does not know of.
type ScrollbarStyle ΒΆ
type ScrollbarStyle struct {
// Thumb is the glyph of the thumb, repeated along it. Empty is the
// default: "β", or "β" when horizontal. A hover style with "β" grows a
// vertical thumb under the pointer; no glyph a row tall grows as evenly
// from the middle of a cell.
Thumb string
ThumbStyle lipgloss.Style
// Track is the glyph of the track. Empty draws nothing there, leaving a
// border beneath it shown.
Track string
TrackStyle lipgloss.Style
}
ScrollbarStyle is how a scrollbar looks: its thumb, the part for what is in view, and its track, the rest. The zero value is the default look.
type SelectionMsg ΒΆ
type SelectionMsg struct {
// ID is the ID of the node the text was selected in, or of its nearest
// ancestor with one, such as the slot a component is placed in.
ID ID
// Text is the text selected.
Text string
}
SelectionMsg is sent when text is selected with the mouse in a node made selectable: when a drag that selected some ends, or once a double click can no longer become a triple click. The selection stays until the next click, Root.ClearSelection, or Root.CopySelection.
type Size ΒΆ
type Size struct {
W, H int
}
Size is a width and height in cells.
func Measure ΒΆ
Measure returns the size c takes in a wΓh space: its natural size, cut to wΓh, as a slot that sizes it to its content would give it. A w or h of zero or less is unbounded on that axis. A Measurer that falls back to another child can return its size, and a component can size children it is given. Like Render, Measure is stateless.
type SkeletonNode ΒΆ
type SkeletonNode struct {
// contains filtered or unexported fields
}
SkeletonNode is a placeholder for content that is still loading. Build one with Skeleton.
func Skeleton ΒΆ
func Skeleton(lines ...int) SkeletonNode
Skeleton returns a placeholder for content that is still loading: a bar of blocks for each of lines, that many cells wide, with 0 for a blank line. Give it a line for each line of the content it stands in for, so that nothing moves when the content arrives:
if !m.loaded {
return bloom.Box(card, bloom.Skeleton(8, 0, 5, 11).Shimmer(m.shimmer.Float()))
}
return bloom.Box(card, bloom.Column(title, bloom.Fixed(1, nil), value, unit))
Bars are cut to the width the skeleton is given. They are drawn in the terminal's foreground, faded most of the way into its background, unless given a SkeletonNode.Style.
func (SkeletonNode) Focusable ΒΆ
func (n SkeletonNode) Focusable() SkeletonNode
Focusable makes the skeleton one that Focus can move to.
func (SkeletonNode) ID ΒΆ
func (n SkeletonNode) ID(id ID) SkeletonNode
ID sets the ID that focus and Frame.Rect refer to the skeleton by.
func (SkeletonNode) Layout ΒΆ
func (n SkeletonNode) Layout(ctx Context) Child
Layout implements Child.
func (SkeletonNode) NoTooltip ΒΆ
func (n SkeletonNode) NoTooltip() SkeletonNode
NoTooltip keeps the TextNode.Truncate nodes inside the skeleton that are cut to fit from showing their full text as a tooltip, such as where the app shows it some other way. A tooltip given with Tooltip, to the skeleton or to a node inside it, still shows, and so does the full text of a node pinned open with TooltipOpen.
func (SkeletonNode) On ΒΆ
func (n SkeletonNode) On(handlers ...on.Handler) SkeletonNode
On adds mouse handlers to the skeleton, made by package on.
func (SkeletonNode) Selectable ΒΆ
func (n SkeletonNode) Selectable() SkeletonNode
Selectable lets the left button select text in the skeleton by dragging over it, as a terminal selects text, but kept inside the skeleton. Holding alt as the drag starts selects a rectangle of cells instead. The innermost selectable node under the pointer takes the drag, unless a node inside it has an on.Drag handler. See Root.Selection for the text selected.
func (SkeletonNode) Shimmer ΒΆ
func (n SkeletonNode) Shimmer(phase float64) SkeletonNode
Shimmer sweeps a band of light across the skeleton, as fx.Shimmer does, at phase from 0 to 1. A looping sequence from package anim can drive it, started in Init and stopped once the content arrives:
shimmer: anim.NewLoop(1400 * time.Millisecond),
For a band of another color or width, draw the skeleton in a Transition with an fx.Shimmer instead.
func (SkeletonNode) Style ΒΆ
func (n SkeletonNode) Style(style lipgloss.Style) SkeletonNode
Style draws the bars with style, whose foreground colors them.
func (SkeletonNode) Tooltip ΒΆ
func (n SkeletonNode) Tooltip(text string, opts ...TipOption) SkeletonNode
Tooltip gives the skeleton a tooltip showing text, which a Root with tooltips on (see WithTooltips) draws beside it once the pointer has rested on it, or once a key press has moved the focus onto it. Without them it does nothing. A node without a tooltip of its own shows that of the nearest node it is inside that has one. On a TextNode.Truncate node, it shows in place of the full text the node was cut from. Empty text gives the skeleton no tooltip. The text is drawn without the escape sequences that TextNode.Trusted keeps.
func (SkeletonNode) TooltipOpen ΒΆ
func (n SkeletonNode) TooltipOpen(open bool) SkeletonNode
TooltipOpen pins the skeleton's tooltip open while open is true: a Root with tooltips on (see WithTooltips) shows it at once, without the pointer or the focus, and keys and the pointer do not close it. Several can be pinned at once, each placed where it covers none of the others or their nodes, and one that fits nowhere is left out of the frame. It shows the tooltip given with Tooltip, or for a TextNode.Truncate node cut to fit, its full text, even inside a node with NoTooltip, as the app asked for it. Text that fits, and a skeleton without a tooltip, show nothing. Use it to show the full text of a row the app has selected, which bloom does not know of.
type SlotNode ΒΆ
type SlotNode struct {
// contains filtered or unexported fields
}
SlotNode places a child in a Row or Column with a sizing rule. Build one with Fixed, Fill, Grow, Percent, or Auto. A child given to a row or column directly is placed as with Auto.
Outside a row, column, or Grid, such as in a List item or a Box, a slot's sizing rule does nothing: it takes the space its parent gives it and passes it to its child. That makes Auto(child) a way to give any child an ID, focus, mouse handlers, or a tooltip without changing how it is laid out.
func Auto ΒΆ
Auto places child at its natural size. It can shrink when space runs short, down to its Min, which is zero unless set: in a row, with the others, in proportion to their sizes, each keeping a cell while they all can, and in a column, the last first, so that a column too short for its children cuts off the last of them rather than any from the middle. When a row's children cannot each keep a cell, the last are cut off too.
func Fixed ΒΆ
Fixed places child at exactly n cells on the main axis. A nil child is empty space, such as Fixed(1, nil) for a blank line in a column; Space is empty space that grows to fill instead.
func Grow ΒΆ
Grow places child in a share of the space left by its siblings, weighted against the other growing children's weights.
func Percent ΒΆ
Percent places child at p percent of its container's main axis. It can shrink when space runs short, as an Auto slot does.
func Space ΒΆ
func Space() SlotNode
Space is an empty slot that fills the space left by its siblings.
func (SlotNode) Animate ΒΆ
Animate smoothly moves and resizes the slot when layout changes, reflowing its child at each intermediate size. It needs an ID and a retained Root; without either it does nothing. Zero-size slots animate closed; collapsed slots and removed nodes disappear immediately. Options default to anim.NewValue and are captured when it starts animating. A slot drawn without Animate on the last frame glides from where it was then. Root controls the clock and FPS.
func (SlotNode) Collapsible ΒΆ
Collapsible lets the slot be dropped, with the gap beside it, when its container cannot fit the minimum sizes of all its children, or for a column, the natural sizes of those it would cut off. Slots with the lowest priority are dropped first.
func (SlotNode) ID ΒΆ
ID sets the ID that focus, layout animation, and Frame.Rect refer to the slot by.
func (SlotNode) Layout ΒΆ
Layout implements Child, returning the slot itself: bloom lays it out without calling it.
func (SlotNode) MoveWith ΒΆ
MoveWith has SlotNode.Animate move the slot with effects rather than by gliding: when layout changes where it goes, it snaps there, and effects are applied to its cells as its animation runs from 0 to 1, with canvas.Surface.From where it was. Its cells may be drawn anywhere between the two, over the rest of its container, such as by fx.Fly, which flies them over. A slot still gliding, such as one that was a dragged layer with the same ID, finishes its glide first. It does nothing without Animate.
func (SlotNode) NoTooltip ΒΆ
NoTooltip keeps the TextNode.Truncate nodes inside the slot that are cut to fit from showing their full text as a tooltip, such as where the app shows it some other way. A tooltip given with Tooltip, to the slot or to a node inside it, still shows, and so does the full text of a node pinned open with TooltipOpen.
func (SlotNode) Scope ΒΆ
Scope makes the slot a focus scope: Focus.Within reports whether focus is inside it, and Focus.Push confines focus to it. A slot needs an ID to be a scope.
func (SlotNode) Selectable ΒΆ
Selectable lets the left button select text in the slot by dragging over it, as a terminal selects text, but kept inside the slot. Holding alt as the drag starts selects a rectangle of cells instead. The innermost selectable node under the pointer takes the drag, unless a node inside it has an on.Drag handler. See Root.Selection for the text selected.
func (SlotNode) Tooltip ΒΆ
Tooltip gives the slot a tooltip showing text, which a Root with tooltips on (see WithTooltips) draws beside it once the pointer has rested on it, or once a key press has moved the focus onto it. Without them it does nothing. A node without a tooltip of its own shows that of the nearest node it is inside that has one. On a TextNode.Truncate node, it shows in place of the full text the node was cut from. Empty text gives the slot no tooltip. The text is drawn without the escape sequences that TextNode.Trusted keeps.
func (SlotNode) TooltipOpen ΒΆ
TooltipOpen pins the slot's tooltip open while open is true: a Root with tooltips on (see WithTooltips) shows it at once, without the pointer or the focus, and keys and the pointer do not close it. Several can be pinned at once, each placed where it covers none of the others or their nodes, and one that fits nowhere is left out of the frame. It shows the tooltip given with Tooltip, or for a TextNode.Truncate node cut to fit, its full text, even inside a node with NoTooltip, as the app asked for it. Text that fits, and a slot without a tooltip, show nothing. Use it to show the full text of a row the app has selected, which bloom does not know of.
type Snapshot ΒΆ
type Snapshot struct {
// contains filtered or unexported fields
}
Snapshot is the text of a Buffer as it was when Buffer.Snapshot took it, which it stays as the buffer goes on changing, to undo a change with Buffer.Restore, or to read the text in another goroutine, such as to save it or search it, while the buffer goes on being changed. Unlike the buffer, its methods are safe to call from any goroutine. The zero value holds no lines.
func (Snapshot) Line ΒΆ
Line returns line i as it was given, with its styles, or "" when there is no such line.
func (Snapshot) Lines ΒΆ
Lines returns an iterator over the lines, as they were given, with their styles, and their numbers.
type Span ΒΆ
type Span struct {
// Start and End are the first and last cells selected, inclusive: every
// cell from Start to End in reading order, or with Block, the rectangle
// with them at its top-left and bottom-right corners. A selection that
// takes a row to its end ends at the node's last column, which may be
// past the end of the row's text.
Start, End image.Point
Block bool
// Size is the size the node was laid out at, such as for a component
// that wraps its text to its width, to wrap it the same way again.
Size Size
}
Span is the part of a node selected with the mouse, in cells relative to its top-left as laid out. Inside a Scroll, that is the top-left of all of it, not of what is in sight.
type TextMap ΒΆ
type TextMap interface {
// PosAt returns the position in the text of the character drawn at
// cell, relative to the component's top-left, laid out at size: the end
// of the row for a cell past its text, including one just past the
// component's right edge, the start of the row for one before its text,
// such as in a gutter, and the start of the text for a cell above it, and
// its end for one below it.
PosAt(cell image.Point, size Size) Pos
// Cells calls row for each row in sight, laid out at size, that the text
// from from up to to covers, with the cells of it it takes, from x0 up to
// x1, relative to the component's top-left. Either position may be past
// the end of its line, or of the text, which the root gives for "to the
// end": the component clamps them.
Cells(from, to Pos, size Size, row func(y, x0, x1 int))
// Text returns the text from from up to to, which may be past the end of
// their lines or of the text, as for Cells.
Text(from, to Pos) string
}
TextMap is a component that shows part of its text, or lays it out itself, and tells where in that text its cells are, such as one that scrolls its own lines or wraps them, or draws a gutter beside them. A selection in it is kept as positions in its text rather than as cells, so that it stays on the text as the component scrolls, and takes the text scrolled out of sight. The root keeps the selection, draws it over the cells Cells reports, after the component draws, in the selection's style (see WithSelectionStyle), and reads the text copied from Text.
A component that implements it is selectable without being made so, as with SlotNode.Selectable, and may also be inside a larger node made selectable, which a selection then runs into and through, as it does through a Text. Dragging in it selects the character under the pointer, as a terminal does; a double click selects the word there, as drawn, and a triple click the whole line of the text. Holding alt as the drag starts selects as a drag does, since a rectangle of cells is more than the methods tell. Dragging past its edge scrolls it through the on.Scroll handler under the pointer, as the wheel would, for as long as the pointer is held there, since the root cannot know how much text is out of sight.
A selection in it ends when it leaves the frame. When its text changes under a selection, clearing the selection, with Root.ClearSelection, is the program's to do.
It is for a component that draws its own cells, with View, and is checked on the Viewer of a View. A component laid out by its Layout is drawn by the nodes it lays out, whose text the root reads from them, and is not taken as a TextMap, or as an Editable.
type TextNode ΒΆ
type TextNode struct {
// contains filtered or unexported fields
}
TextNode is a string, optionally styled. Build one with Text.
func Text ΒΆ
Text returns a node showing s, a string that may hold ANSI styles and hyperlinks. A line wider than the node is given wraps onto the lines after it, at a space where it can and mid-word where a word is too long, and the node is measured that many lines tall. TextNode.NoWrap cuts it off at the edge instead, and TextNode.Truncate keeps it to one line, cut with "β¦". Escape sequences meant for the terminal rather than for drawing text, such as images, are dropped unless the text is TextNode.Trusted.
func (TextNode) Cursor ΒΆ
Cursor shows the terminal cursor at c, relative to the node's top-left cell, while that cell is on screen and not covered by a later layer. A terminal has one cursor: with WithFocus, a cursor inside a focusable node with an ID is shown only while the nearest such node, which may be the node itself, is focused, and is shown over one in no such node. Otherwise the cursor drawn last is shown.
func (TextNode) HoverStyle ΒΆ
HoverStyle renders the text with style instead of its own while the pointer is over it, which needs no state in the model. It should take the same space as the node's style, changing only how it looks. See on.Hover for when the pointer is followed.
func (TextNode) ID ΒΆ
ID sets the ID that focus and Frame.Rect refer to the node by.
func (TextNode) Layout ΒΆ
Layout implements Child, returning the node itself: bloom lays it out without calling it.
func (TextNode) NoTooltip ΒΆ
NoTooltip keeps the node's full text from showing as its tooltip when it is cut to fit with TextNode.Truncate, such as where the app shows it some other way. A tooltip given with Tooltip still shows, and so does the full text while the node is pinned open with TooltipOpen.
func (TextNode) NoWrap ΒΆ
NoWrap keeps each line whole rather than wrapping it, cutting off what does not fit at the edge of the node, less a style's padding and borders, for text laid out in columns of its own, such as a table or ASCII art. The node is measured at its lines' natural width, and as many lines tall as it has. It does nothing to text that is [TextNode.Truncate]d, which is kept to one line already.
func (TextNode) Selectable ΒΆ
Selectable lets the left button select text in the node by dragging over it, as a terminal selects text, but kept inside the node. Holding alt as the drag starts selects a rectangle of cells instead. The innermost selectable node under the pointer takes the drag, unless a node inside it has an on.Drag handler. See Root.Selection for the text selected. Text scrolled out of sight is selected as well.
func (TextNode) Style ΒΆ
Style renders the text with style at the size the node is given, so a background fills the node, and long lines wrap to its width less the style's padding and borders. A width or height set on style itself is kept.
func (TextNode) Tooltip ΒΆ
Tooltip gives the node a tooltip showing text, which a Root with tooltips on (see WithTooltips) draws beside it once the pointer has rested on it, or once a key press has moved the focus onto it. Without them it does nothing. A node without a tooltip of its own shows that of the nearest node it is inside that has one. On a TextNode.Truncate node, it shows in place of the full text the node was cut from. Empty text gives the node no tooltip. The text is drawn without the escape sequences that TextNode.Trusted keeps.
func (TextNode) TooltipOpen ΒΆ
TooltipOpen pins the node's tooltip open while open is true: a Root with tooltips on (see WithTooltips) shows it at once, without the pointer or the focus, and keys and the pointer do not close it. Several can be pinned at once, each placed where it covers none of the others or their nodes, and one that fits nowhere is left out of the frame. It shows the tooltip given with Tooltip, or for a TextNode.Truncate node cut to fit, its full text, even inside a node with NoTooltip, as the app asked for it. Text that fits, and a node without a tooltip, show nothing. Use it to show the full text of a row the app has selected, which bloom does not know of.
func (TextNode) Truncate ΒΆ
Truncate shows one line, replacing newlines with spaces and cutting text that does not fit with "β¦". Padding and borders count against its width. With tooltips on (see WithTooltips), text that was cut shows the rest of it as its tooltip, unless it has NoTooltip, and Frame.Truncated reports whether it was cut.
func (TextNode) Trusted ΒΆ
Trusted keeps the escape sequences in the text that are written to the terminal as they are rather than drawn: APC, DCS, SOS and PM commands, such as images drawn with the Kitty graphics protocol or sixel. They are dropped otherwise, as text from outside the program, such as a log or a file, could hold any of them, to delete images, query the terminal, and such. Mark text trusted only when the program made all of it.
type TextSource ΒΆ
type TextSource interface {
// SelectedText returns the text of the component in span.
SelectedText(span Span) string
}
TextSource is a component that knows its own text, which selecting text in it with the mouse reads instead of its cells as drawn: such as to copy a secret it shows masked, or to leave out what it draws around its text. A component that implements it is selectable without being made so, as with SlotNode.Selectable. It is checked on a component laid out by its Layout, and on the Viewer of a View.
type TipMode ΒΆ
type TipMode uint8
TipMode is how the tooltips of a kind are shown, set for each kind in Tooltips. The zero value, TipDefault, is the kind's default.
const ( // TipDefault shows the tooltips of a kind as the kind does by default: // TipUnfold for truncated text, and TipBubble for the text given with // Tooltip. TipDefault TipMode = iota // TipUnfold draws the full text of text that was cut over it, in place, // as if the rest of it were revealed: the first glyph of the full text // is in the cell of the first glyph of the cut text, and the chip's // padding goes before it, shifted left only to stay on screen. Text // wider than the screen is shown as a bubble instead. The one of the // pointer stays open only while the pointer is over the cut text. It is // the default for truncated text. TipUnfold // TipBubble draws a tooltip in a chip beside its node. It is the default // for the text given with Tooltip. TipBubble // TipSink shows tooltips in a [TooltipSink] that the layout places, such // as in a status line, and none beside their nodes while a sink has a // cell on screen. While none does, they are shown as they are by // default. TipSink // TipHidden draws no tooltips of the kind, but has them open and close // as they otherwise would, for an app that draws the one of the // pointer or the focus itself, from [Root.Tooltip]. TipHidden // TipOff shows no tooltips of the kind. Unlike TipHidden, the kind has // no tooltips at all: none opens. TipOff )
type TipOption ΒΆ
type TipOption func(*tooltip)
TipOption configures the tooltip given with a node's Tooltip method.
func TipDelay ΒΆ
TipDelay shows the tooltip once the pointer has rested on its node for d, or the focus has stayed on it for d, in place of the Tooltips Delay. A delay of zero or less shows it at once.
func TipSide ΒΆ
TipSide puts the tooltip against side of its node: above or below it on the next row, or left or right of it with a blank cell between, shifted along the side to stay on screen, even when it covers what is there. It goes on the opposite side when it does not fit on side, or would cover the cell under the pointer or the cursor, and where it would without TipSide when it fits on neither. Without it, a tooltip goes on whichever side hides the least of what is on screen.
type TooltipSinkNode ΒΆ
type TooltipSinkNode struct {
// contains filtered or unexported fields
}
TooltipSinkNode shows the text of a tooltip in the layout, such as in a status line. Build one with TooltipSink.
func TooltipSink ΒΆ
func TooltipSink() TooltipSinkNode
TooltipSink returns a node that shows the text of the tooltip of the pointer or the focus, or else of the first one pinned open in the order of the tree, for the kinds of tooltip whose Tooltips mode is TipSink, and is blank while there is none, such as in a status line. While a sink has a cell on screen, tooltips of those kinds are not drawn beside their nodes; one laid out but clipped or scrolled out of sight is not on screen, and they are shown as by default. Every sink on screen shows the same text. It shows a tooltip in the same frame the tooltip opens in.
The tooltip of the pointer stays open while the pointer is over its node: the sink is not part of it. A sink is a row tall, inside its style's frame, and as wide as the space it is given. Text too long for it is cut with "β¦", and shows no tooltip of its own.
func (TooltipSinkNode) Focusable ΒΆ
func (n TooltipSinkNode) Focusable() TooltipSinkNode
Focusable makes the sink one that Focus can move to.
func (TooltipSinkNode) ID ΒΆ
func (n TooltipSinkNode) ID(id ID) TooltipSinkNode
ID sets the ID that focus and Frame.Rect refer to the sink by.
func (TooltipSinkNode) Layout ΒΆ
func (n TooltipSinkNode) Layout(Context) Child
Layout implements Child, returning the sink itself: bloom lays it out without calling it.
func (TooltipSinkNode) NoTooltip ΒΆ
func (n TooltipSinkNode) NoTooltip() TooltipSinkNode
NoTooltip keeps the TextNode.Truncate nodes inside the sink that are cut to fit from showing their full text as a tooltip, such as where the app shows it some other way. A tooltip given with Tooltip, to the sink or to a node inside it, still shows, and so does the full text of a node pinned open with TooltipOpen.
func (TooltipSinkNode) On ΒΆ
func (n TooltipSinkNode) On(handlers ...on.Handler) TooltipSinkNode
On adds mouse handlers to the sink, made by package on.
func (TooltipSinkNode) Style ΒΆ
func (n TooltipSinkNode) Style(style lipgloss.Style) TooltipSinkNode
Style draws the sink's text with style, whose background fills the sink, also while it is blank.
func (TooltipSinkNode) Tooltip ΒΆ
func (n TooltipSinkNode) Tooltip(text string, opts ...TipOption) TooltipSinkNode
Tooltip gives the sink a tooltip showing text, which a Root with tooltips on (see WithTooltips) draws beside it once the pointer has rested on it, or once a key press has moved the focus onto it. Without them it does nothing. A node without a tooltip of its own shows that of the nearest node it is inside that has one. On a TextNode.Truncate node, it shows in place of the full text the node was cut from. Empty text gives the sink no tooltip. The text is drawn without the escape sequences that TextNode.Trusted keeps.
func (TooltipSinkNode) TooltipOpen ΒΆ
func (n TooltipSinkNode) TooltipOpen(open bool) TooltipSinkNode
TooltipOpen pins the sink's tooltip open while open is true: a Root with tooltips on (see WithTooltips) shows it at once, without the pointer or the focus, and keys and the pointer do not close it. Several can be pinned at once, each placed where it covers none of the others or their nodes, and one that fits nowhere is left out of the frame. It shows the tooltip given with Tooltip, or for a TextNode.Truncate node cut to fit, its full text, even inside a node with NoTooltip, as the app asked for it. Text that fits, and a sink without a tooltip, show nothing. Use it to show the full text of a row the app has selected, which bloom does not know of.
type Tooltips ΒΆ
type Tooltips struct {
// Style is the style of the chip a tooltip is drawn in. Without one, the
// chip has a cell of padding on either side and a background between the
// terminal's default background and foreground.
Style lipgloss.Style
// Delay is how long the pointer rests on a node, or the focus stays on
// it, before its tooltip shows: 500ms by default. A negative delay shows
// it at once. A tooltip's [TipDelay] replaces it.
Delay time.Duration
// Warm is how long, after a tooltip closes because the pointer left it,
// the next one the pointer moves onto shows at once, without waiting for
// its delay: 300ms by default. A negative one never does.
Warm time.Duration
// MaxWidth is the widest a tooltip beside its node gets, its padding and
// border included, before its text wraps: 60 cells by default. It is
// never wider than the screen.
MaxWidth int
// Truncated is how the full text of a [TextNode.Truncate] node that was
// cut is shown: [TipUnfold] for [TipDefault], [TipBubble], [TipSink],
// [TipHidden], or [TipOff] for not at all. Cut text has a tooltip of
// its own only while it is not TipOff, which costs a frame with
// tooltips on a little for each node that was cut.
Truncated TipMode
// Explicit is how the text given with Tooltip is shown: [TipBubble] for
// [TipDefault], [TipSink], or [TipHidden]. Other modes are taken as
// TipBubble.
Explicit TipMode
}
Tooltips configures the tooltips of a Root, given with WithTooltips or Root.SetTooltips. A field left at its zero value takes its default.
A tooltip is short text about one node, given with the node's Tooltip method, or the full text of a TextNode.Truncate node that was cut to fit, unless the node or one it is inside has NoTooltip. It shows when the pointer rests on the node, or when a key press moves the focus onto it (see WithFocus), and goes away on any key press, click, or wheel event, or when the pointer leaves the node, unless onto the tooltip's bubble. Root draws it over everything in the layout. It takes no space in the layout and no mouse events: a click on it reaches what is beneath, and the pointer over it is over what is beneath.
A tooltip given with Tooltip is a bubble beside its node, on the side given with TipSide, or without one, on whichever side hides the least of what is on screen, preferring above, then below, right, and left. It is never drawn over its node, the cell under the pointer, or the cursor, unless it fits nowhere else, but for the pointer on a node taller than a row, it goes beside the node's cells on the pointer's row, to stay near the pointer, and may cover the node's other rows. Cut text is unfolded: its full text is drawn over it, in place, on its row, and stays while the pointer is over the cut text, not over the rest of it past the node, which covers what is beside the node, such as the next cell of a table's row. Either kind can be shown in a TooltipSink instead, such as in a status line, or drawn by the app from Root.Tooltip.
A node's TooltipOpen pins its tooltip open.
type TransitionNode ΒΆ
type TransitionNode struct {
// contains filtered or unexported fields
}
TransitionNode draws a child with effects. Build one with Transition or Present.
func Present ΒΆ
Present draws child with p's progress while visible. When hidden, child is absent, taking neither space nor a gap in its container. While p animates out, child is still drawn but takes no input: its mouse handlers do not run, and its nodes cannot be focused, selected, or show tooltips.
func Transition ΒΆ
func Transition(t float64, child Child, effects ...fx.Effect) TransitionNode
Transition draws child with effects applied to its cells for progress t, from 0, as it starts to enter, to 1, when it is fully shown. See fx.Effect.
func (TransitionNode) Focusable ΒΆ
func (n TransitionNode) Focusable() TransitionNode
Focusable makes the transition one that Focus can move to.
func (TransitionNode) ID ΒΆ
func (n TransitionNode) ID(id ID) TransitionNode
ID sets the ID that focus and Frame.Rect refer to the transition by.
func (TransitionNode) Layout ΒΆ
func (n TransitionNode) Layout(Context) Child
Layout implements Child, returning the transition itself: bloom lays it out without calling it.
func (TransitionNode) NoTooltip ΒΆ
func (n TransitionNode) NoTooltip() TransitionNode
NoTooltip keeps the TextNode.Truncate nodes inside the transition that are cut to fit from showing their full text as a tooltip, such as where the app shows it some other way. A tooltip given with Tooltip, to the transition or to a node inside it, still shows, and so does the full text of a node pinned open with TooltipOpen.
func (TransitionNode) On ΒΆ
func (n TransitionNode) On(handlers ...on.Handler) TransitionNode
On adds mouse handlers to the transition, made by package on.
func (TransitionNode) Selectable ΒΆ
func (n TransitionNode) Selectable() TransitionNode
Selectable lets the left button select text in the transition by dragging over it, as a terminal selects text, but kept inside the transition. Holding alt as the drag starts selects a rectangle of cells instead. The innermost selectable node under the pointer takes the drag, unless a node inside it has an on.Drag handler. See Root.Selection for the text selected.
func (TransitionNode) Tooltip ΒΆ
func (n TransitionNode) Tooltip(text string, opts ...TipOption) TransitionNode
Tooltip gives the transition a tooltip showing text, which a Root with tooltips on (see WithTooltips) draws beside it once the pointer has rested on it, or once a key press has moved the focus onto it. Without them it does nothing. A node without a tooltip of its own shows that of the nearest node it is inside that has one. On a TextNode.Truncate node, it shows in place of the full text the node was cut from. Empty text gives the transition no tooltip. The text is drawn without the escape sequences that TextNode.Trusted keeps.
func (TransitionNode) TooltipOpen ΒΆ
func (n TransitionNode) TooltipOpen(open bool) TransitionNode
TooltipOpen pins the transition's tooltip open while open is true: a Root with tooltips on (see WithTooltips) shows it at once, without the pointer or the focus, and keys and the pointer do not close it. Several can be pinned at once, each placed where it covers none of the others or their nodes, and one that fits nowhere is left out of the frame. It shows the tooltip given with Tooltip, or for a TextNode.Truncate node cut to fit, its full text, even inside a node with NoTooltip, as the app asked for it. Text that fits, and a transition without a tooltip, show nothing. Use it to show the full text of a row the app has selected, which bloom does not know of.
type ViewNode ΒΆ
type ViewNode struct {
// contains filtered or unexported fields
}
ViewNode draws a Viewer from its View string. Build one with View.
func View ΒΆ
View returns a node that draws v, a component such as a Bubbles one, from its View string, which is called at most once a frame, and only when the node is measured or drawn. The node is as big as the string, clipped to the space it is given, and its lines are not wrapped.
Pass a pointer to a component kept in a model, such as &m.input, so that it is not copied each frame. A v that is also a Child is still drawn from its View, so a component can lay itself out as a View of itself; place it directly to have it laid out.
v is checked for the interfaces a component that draws its own cells can implement: Measurer, TextSource, TextMap, and Editable.
A view is drawn as it is, with any commands in it that are written to the terminal rather than drawn, such as images, which Text and Viewport drop unless they are trusted. A component that shows text from outside the program, such as a file, should clean it with bloomfx.dev/bloom/canvas.Sanitize first.
type Viewer ΒΆ
type Viewer interface {
View() string
}
Viewer is a component drawn from a string, such as a Bubbles component. Place one in a layout with View.
type ViewportNode ΒΆ
type ViewportNode struct {
// contains filtered or unexported fields
}
ViewportNode shows the lines of a Buffer, as many as fit, from a position kept in the model. Build one with Viewport.
func Viewport ΒΆ
func Viewport(buf *Buffer) ViewportNode
Viewport returns a viewport showing the lines of buf, from the start until it is given a position with ViewportNode.At. It lays out and draws only the lines in sight, however many the buffer holds, so a log of a million lines costs no more to draw than one of a screenful, and costs little more to append to.
It is as wide as its widest line and as tall as its lines, wrapped, and is usually placed where it fills the space it is given, such as in a Fill slot or a Box. Frame.Viewport tells where a frame showed it scrolled to, and moves it from there, ScrollbarOf its ID makes a scrollbar for it, and ViewportNode.OnScroll scrolls it with the mouse.
func (ViewportNode) At ΒΆ
func (n ViewportNode) At(pos ViewportPos) ViewportNode
At sets where the viewport is scrolled to. A position past the end shows the last of the lines, and the viewport never leaves space below its last line while there are lines above its top to fill it.
func (ViewportNode) Caret ΒΆ
func (n ViewportNode) Caret(sel *Range) ViewportNode
Caret makes the viewport an editing surface: sel is what is selected in its buffer, the caret at its Head, kept in the model. The viewport reads it whenever it is drawn, and Root.Selection whenever it is asked, so a range the program changes with the keyboard is seen in the same Update, and the mouse writes it, as it does the range of an Editable: a press puts the caret under the pointer, before the character there, and with shift held moves the Head there and keeps the Anchor; a drag moves the Head; a double click selects the word, found in the buffer's text as WithWordChars tells, and a triple click the line. A press past the end of a row its line wraps after leaves the caret at the end of that row, with Range.EndOfRow set, rather than at the start of the next. A range that holds text is drawn as the selection is, and is the one selection on the screen: Root.CopySelection copies it and leaves it, Root.ClearSelection collapses it to its Head, and Root.SelectAll, given the viewport's ID, selects all of the buffer. The viewport is selectable without ViewportNode.Selectable, and dragging past its edge scrolls it through ViewportNode.OnScroll.
So that the caret has a cell at the end of a line as wide as the viewport, the lines are laid out one column narrower than it, the last column kept for the caret, whether they wrap or scroll sideways. An empty buffer has the caret at its top-left, and takes edits as one empty line.
Following the range through the edits to the buffer is the program's to do, with the Change each edit returns, such as to put the caret at Change.End after typing. A range out of the buffer's bounds is clamped where it is drawn and read. The methods of ViewportView move the caret by the rows the lines wrap to, to the ends of rows, and by pages, and keep it in sight.
func (ViewportNode) Cursor ΒΆ
func (n ViewportNode) Cursor(c *tea.Cursor) ViewportNode
Cursor shows the terminal cursor at the caret, the Head of the range given to ViewportNode.Caret, drawn on the side of a wrap its EndOfRow tells, as ViewportView.CaretCell has it, while it is in sight, in c's shape and color, as TextNode.Cursor does at a cell, by its rules for which cursor is shown. The position of c is not used. It does nothing without a caret.
func (ViewportNode) Focusable ΒΆ
func (n ViewportNode) Focusable() ViewportNode
Focusable makes the viewport one that Focus can move to.
func (ViewportNode) Follow ΒΆ
func (n ViewportNode) Follow() ViewportNode
Follow keeps the viewport at its end while it is there, as a terminal or tail -f does: a position scrolled to its end, by the wheel or with the methods of ViewportView, is given as ViewportEnd, which stays at the end as lines are appended. Scrolled away from the end, it stays where it is. Start it at ViewportEnd to follow from the start.
func (ViewportNode) Gutter ΒΆ
func (n ViewportNode) Gutter(width int, fn func(row GutterRow) string) ViewportNode
Gutter draws a column width cells wide on the left of the lines, beside them, with what fn returns for each row in sight, such as a marker for a changed line or a breakpoint. Text wider than the gutter is cut off. The column runs the viewport's full height: fn is also called for the rows below the last line, with a Line of -1, such as to carry the gutter's background down, or draw a "~". Gutters are drawn left to right in the order given, and take their space from the lines.
func (ViewportNode) ID ΒΆ
func (n ViewportNode) ID(id ID) ViewportNode
ID sets the ID that focus, Frame.Rect, Frame.Viewport, and ScrollbarOf refer to the viewport by.
func (ViewportNode) Layout ΒΆ
func (n ViewportNode) Layout(Context) Child
Layout implements Child, returning the viewport itself: bloom lays it out without calling it.
func (ViewportNode) LineNumbers ΒΆ
func (n ViewportNode) LineNumbers(style lipgloss.Style) ViewportNode
LineNumbers draws the number of each line, from 1, in a gutter on the left as wide as the largest number and a space, drawn in style's colors and attributes. Rows that continue a wrapped line, and those below the last line, have none, but are drawn in style.
func (ViewportNode) LineStyle ΒΆ
func (n ViewportNode) LineStyle(fn func(line int) lipgloss.Style) ViewportNode
LineStyle draws each line in sight in the colors and attributes of the style fn returns for it, under the line's own and its marks, across the whole width of the viewport, such as to show the line under a cursor. It is called only for lines in sight.
func (ViewportNode) Marks ΒΆ
func (n ViewportNode) Marks(fn func(line int, text string) []Mark) ViewportNode
Marks draws parts of lines in styles of their own, such as the matches of a search, as fn returns them. It is given each line in sight as it is drawn, with the line's text without styles, as Buffer.Text gives it, so that it costs nothing for lines out of sight. A mark that overlaps one before it is not drawn.
func (ViewportNode) NoTooltip ΒΆ
func (n ViewportNode) NoTooltip() ViewportNode
NoTooltip keeps the TextNode.Truncate nodes inside the viewport that are cut to fit from showing their full text as a tooltip, such as where the app shows it some other way. A tooltip given with Tooltip, to the viewport or to a node inside it, still shows, and so does the full text of a node pinned open with TooltipOpen.
func (ViewportNode) On ΒΆ
func (n ViewportNode) On(handlers ...on.Handler) ViewportNode
On adds mouse handlers to the viewport, made by package on.
func (ViewportNode) OnCaret ΒΆ
func (n ViewportNode) OnCaret(fn func(sel Range) tea.Cmd) ViewportNode
OnCaret calls fn when the mouse moves the caret or changes what is selected, after the range given to ViewportNode.Caret is written, such as to forget the column kept while moving up and down. Its command is run as the mouse event's.
func (ViewportNode) OnScroll ΒΆ
func (n ViewportNode) OnScroll(fn func(pos ViewportPos) tea.Cmd) ViewportNode
OnScroll scrolls the viewport with the mouse wheel, three rows a step, or three columns sideways, running fn with the position to scroll to, to keep in the model for ViewportNode.At. A step that doesn't move it, at its edge or with all of its text in sight, isn't run through fn, and goes to the on.Scroll handler of the node around it instead, such as the form a one-line input is in. A ScrollbarOf the viewport without an OnScroll of its own drags it with fn too, and selecting text in it scrolls it while the pointer is held past its edge.
func (ViewportNode) Selectable ΒΆ
func (n ViewportNode) Selectable() ViewportNode
Selectable lets the left button select text in the viewport by dragging over it, as a terminal selects text, but kept inside the viewport. Holding alt as the drag starts selects a rectangle of cells instead, and a triple click selects the whole line, on all the rows it wraps to. See Root.Selection for the text selected, which takes the lines scrolled out of sight as well, with the rows of a wrapped line joined again, and without the gutters.
The selection is kept on the buffer's text, rather than on the rows drawn, so that it stays on the same text as the viewport scrolls and wraps its lines differently, and as lines are appended, and the buffer is edited, such as to take out the first lines of a capped log. Setting the buffer's content again, as Buffer.SetContent does, clears it.
func (ViewportNode) Style ΒΆ
func (n ViewportNode) Style(style lipgloss.Style) ViewportNode
Style draws the viewport's lines, and its rows below them, in the colors and attributes of style, under their own styles, those of ViewportNode.LineStyle, and their marks. Its padding, borders, and margins are not drawn: put the viewport in a Box for those.
func (ViewportNode) Tooltip ΒΆ
func (n ViewportNode) Tooltip(text string, opts ...TipOption) ViewportNode
Tooltip gives the viewport a tooltip showing text, which a Root with tooltips on (see WithTooltips) draws beside it once the pointer has rested on it, or once a key press has moved the focus onto it. Without them it does nothing. A node without a tooltip of its own shows that of the nearest node it is inside that has one. On a TextNode.Truncate node, it shows in place of the full text the node was cut from. Empty text gives the viewport no tooltip. The text is drawn without the escape sequences that TextNode.Trusted keeps.
func (ViewportNode) TooltipOpen ΒΆ
func (n ViewportNode) TooltipOpen(open bool) ViewportNode
TooltipOpen pins the viewport's tooltip open while open is true: a Root with tooltips on (see WithTooltips) shows it at once, without the pointer or the focus, and keys and the pointer do not close it. Several can be pinned at once, each placed where it covers none of the others or their nodes, and one that fits nowhere is left out of the frame. It shows the tooltip given with Tooltip, or for a TextNode.Truncate node cut to fit, its full text, even inside a node with NoTooltip, as the app asked for it. Text that fits, and a viewport without a tooltip, show nothing. Use it to show the full text of a row the app has selected, which bloom does not know of.
func (ViewportNode) Trusted ΒΆ
func (n ViewportNode) Trusted() ViewportNode
Trusted keeps the escape sequences in the buffer's lines, and in the text of its gutters, that are written to the terminal as they are rather than drawn, as TextNode.Trusted does for a Text: APC, DCS, SOS and PM commands, such as images. Each is drawn with the row holding the glyph after it, or the last glyph of its line. Mark the viewport trusted only when the program made all of what it shows.
func (ViewportNode) Wrap ΒΆ
func (n ViewportNode) Wrap(mode WrapMode) ViewportNode
Wrap sets how lines wider than the viewport are fitted to it. The default is WrapNone.
type ViewportPos ΒΆ
type ViewportPos struct {
// Line is the line at the top. One past the last line or more, as with
// [ViewportEnd], shows the last of them.
Line int
// Row is how many rows of Line are above the top, while it wraps.
Row int
// X is how many columns the lines are scrolled sideways, while they do
// not wrap.
X int
}
ViewportPos is where a Viewport is scrolled to: the line at its top, and with wrapping, how many of that line's rows are above the top, so that the same text stays at the top as its width changes. Keep it in the model, and set it from what Frame.Viewport and ViewportNode.OnScroll give, which have it clamped to the lines there are.
func (ViewportPos) AtEnd ΒΆ
func (p ViewportPos) AtEnd() bool
AtEnd reports whether p is the end of a viewport, as ViewportEnd is, rather than a line of it.
type ViewportView ΒΆ
type ViewportView struct {
// Pos is where the viewport was, once clamped to its lines, or
// [ViewportEnd] while it followed its end. Keep it as the position to
// scroll from.
Pos ViewportPos
// First is the line at the top, which Pos does not tell while it is
// ViewportEnd.
First int
// Row is how many rows were above the top: the offset of the
// viewport, in rows.
Row int
// Rows is how many rows tall the viewport was.
Rows int
// TotalRows is how many rows all of the lines took, wrapped.
TotalRows int
// Lines is how many lines the buffer had.
Lines int
// Width is how many columns wide the lines were shown in, besides the
// gutters, and besides the column kept for the caret of a viewport
// given [ViewportNode.Caret].
Width int
// Widest is how many columns the widest line took.
Widest int
// contains filtered or unexported fields
}
ViewportView is where a Viewport was scrolled to in a frame, as Frame.Viewport reports it, and how big it was. Its methods return the positions to scroll to from there, to give to ViewportNode.At:
case "pgdown": v, _ := m.ui.Frame().Viewport(paneLog) m.pos = v.PageDown()
They work out the rows of the buffer as it is when they are called, so a view kept from before lines were appended still scrolls through them.
func (ViewportView) AtBottom ΒΆ
func (v ViewportView) AtBottom() bool
AtBottom reports whether the last line was in sight at the bottom.
func (ViewportView) AtRow ΒΆ
func (v ViewportView) AtRow(row int) ViewportPos
AtRow returns the position with row at the top, counting the rows of all of the lines, wrapped, from 0, as a Scrollbar gives its offset.
func (ViewportView) AtTop ΒΆ
func (v ViewportView) AtTop() bool
AtTop reports whether the first line was at the top.
func (ViewportView) Bottom ΒΆ
func (v ViewportView) Bottom() ViewportPos
Bottom returns the position showing the last line at the bottom.
func (ViewportView) CaretAt ΒΆ
func (v ViewportView) CaretAt(cell image.Point) Range
CaretAt returns the empty range at cell, relative to the viewport's top-left, as a click puts the caret there: at the position ViewportView.PosAt gives, with EndOfRow set when the cell is past the text of a row its line wraps after, so that the caret stays on that row rather than going to the start of the next.
func (ViewportView) CaretCell ΒΆ
func (v ViewportView) CaretCell(sel Range) (image.Point, bool)
CaretCell returns the cell, relative to the viewport's top-left, that the caret of sel, at its Head, is drawn at, and whether that is in sight: as ViewportView.CellOf has it, but at a place its line wraps with EndOfRow set, past the cells of the row before, in the caret's column at the latest.
func (ViewportView) CellOf ΒΆ
func (v ViewportView) CellOf(p Pos) (image.Point, bool)
CellOf returns the cell, relative to the viewport's top-left, that p, clamped to the buffer, is drawn at, and whether that is in sight. A position where a line wraps is drawn at the start of the row after, and one among the spaces that hang off the end of a row wrapped at words, at the column past its text. ViewportView.CaretCell finds where a caret is drawn, which may be at the end of the row before.
func (ViewportView) Column ΒΆ
func (v ViewportView) Column(sel Range) int
Column returns the column of its row that the caret of sel is drawn at, counting from the start of the row rather than from where the viewport is scrolled to, to keep while moving up and down with ViewportView.MoveRows.
func (ViewportView) Down ΒΆ
func (v ViewportView) Down(n int) ViewportPos
Down returns the position n rows further down, or up for a negative n.
func (ViewportView) HalfPageDown ΒΆ
func (v ViewportView) HalfPageDown() ViewportPos
HalfPageDown returns the position half a viewport's height further down.
func (ViewportView) HalfPageUp ΒΆ
func (v ViewportView) HalfPageUp() ViewportPos
HalfPageUp returns the position half a viewport's height further up.
func (ViewportView) Left ΒΆ
func (v ViewportView) Left(n int) ViewportPos
Left returns the position scrolled n columns further left.
func (ViewportView) MoveRows ΒΆ
func (v ViewportView) MoveRows(sel Range, n, column int) Range
MoveRows returns sel with its Head moved n rows down from the row its caret is drawn on, or up for a negative n, counting the rows the lines wrap to, to column of that row, as an arrow key moves a caret: to the character boundary nearest the column, never inside a wide character or a tab, and to the end of the row, as ViewportView.RowEnd has it, for a column at or past the row's cells. A move above the first row goes to the start of the text, and one below the last row to its end. The Anchor is kept, and EndOfRow is set for the Head at the end of a row its line wraps after.
func (ViewportView) PageDown ΒΆ
func (v ViewportView) PageDown() ViewportPos
PageDown returns the position a viewport's height further down.
func (ViewportView) PageUp ΒΆ
func (v ViewportView) PageUp() ViewportPos
PageUp returns the position a viewport's height further up.
func (ViewportView) Percent ΒΆ
func (v ViewportView) Percent() float64
Percent returns how far down the viewport was scrolled, from 0 at the top to 1 at the bottom, or 1 when all of it was in sight.
func (ViewportView) PosAt ΒΆ
func (v ViewportView) PosAt(cell image.Point) Pos
PosAt returns the position in the buffer of the character drawn at cell, relative to the viewport's top-left, as the mouse finds it to put a caret there: before the character, the end of the row for a cell past its text, the start of the buffer for a cell above its first row, and its end for one below its last. A row a line wraps after ends where the next row starts, past the spaces that hang off a row wrapped at words. The cells of the gutters are columns before the first in sight.
func (ViewportView) Reveal ΒΆ
func (v ViewportView) Reveal(line int) ViewportPos
Reveal returns the position that scrolls as little as it can for line to be in sight, whole if it fits, or from its start if it does not.
func (ViewportView) Right ΒΆ
func (v ViewportView) Right(n int) ViewportPos
Right returns the position scrolled n columns further right, or left for a negative n, while the lines do not wrap.
func (ViewportView) RowEnd ΒΆ
func (v ViewportView) RowEnd(sel Range) Range
RowEnd returns sel with its Head moved to the end of the row its caret is drawn on, as the end key moves a caret, its Anchor kept: the end of the line on its last row, and on a row the line wraps after, the place it wraps, where the next row starts, after any spaces that hang off a row wrapped at words, with EndOfRow set so that the caret is drawn at the end of the row rather than at the start of the next.
func (ViewportView) RowStart ΒΆ
func (v ViewportView) RowStart(sel Range) Range
RowStart returns sel with its Head moved to the start of the row its caret is drawn on, as the home key moves a caret, its Anchor kept.
func (ViewportView) ScrollRows ΒΆ
func (v ViewportView) ScrollRows(sel Range, n, column int) (Range, ViewportPos)
ScrollRows returns sel with its Head moved n rows as ViewportView.MoveRows moves it, and the position scrolled n rows the same way, so that the caret stays on the row of the viewport it was on, as page up and page down move it. Near the top or the bottom, the viewport scrolls as far as it can, and the caret still moves. The position has the caret in sight, scrolled as ViewportView.Show scrolls it when it would not be, such as for a caret that was out of sight.
func (ViewportView) Show ΒΆ
func (v ViewportView) Show(sel Range) ViewportPos
Show returns the position scrolled as little as it takes for the caret of sel to be in sight, at the cell ViewportView.CaretCell gives, down or up, and while the lines do not wrap, sideways, such as to keep a caret in sight as it moves. It is Pos when the caret is in sight.
func (ViewportView) Top ΒΆ
func (v ViewportView) Top() ViewportPos
Top returns the position at the first line.
func (ViewportView) Up ΒΆ
func (v ViewportView) Up(n int) ViewportPos
Up returns the position n rows further up.
type WrapNode ΒΆ
type WrapNode struct {
// contains filtered or unexported fields
}
WrapNode flows children at their natural sizes onto successive lines. Build one with Wrap.
func Wrap ΒΆ
Wrap places children left to right, starting a new line when the next child does not fit. Each line is as tall as its tallest child. An overwide child gets a line of its own, clipped to the container. Slot sizing rules do not apply: every child keeps its natural size.
func (WrapNode) Gap ΒΆ
Gap sets the horizontal space between children and vertical space between lines.
func (WrapNode) ID ΒΆ
ID sets the ID that focus and Frame.Rect refer to the flow by.
func (WrapNode) Layout ΒΆ
Layout implements Child, returning the flow itself: bloom lays it out without calling it.
func (WrapNode) NoTooltip ΒΆ
NoTooltip keeps the TextNode.Truncate nodes inside the flow that are cut to fit from showing their full text as a tooltip, such as where the app shows it some other way. A tooltip given with Tooltip, to the flow or to a node inside it, still shows, and so does the full text of a node pinned open with TooltipOpen.
func (WrapNode) Selectable ΒΆ
Selectable lets the left button select text in the flow by dragging over it, as a terminal selects text, but kept inside the flow. Holding alt as the drag starts selects a rectangle of cells instead. The innermost selectable node under the pointer takes the drag, unless a node inside it has an on.Drag handler. See Root.Selection for the text selected.
func (WrapNode) Tooltip ΒΆ
Tooltip gives the flow a tooltip showing text, which a Root with tooltips on (see WithTooltips) draws beside it once the pointer has rested on it, or once a key press has moved the focus onto it. Without them it does nothing. A node without a tooltip of its own shows that of the nearest node it is inside that has one. On a TextNode.Truncate node, it shows in place of the full text the node was cut from. Empty text gives the flow no tooltip. The text is drawn without the escape sequences that TextNode.Trusted keeps.
func (WrapNode) TooltipOpen ΒΆ
TooltipOpen pins the flow's tooltip open while open is true: a Root with tooltips on (see WithTooltips) shows it at once, without the pointer or the focus, and keys and the pointer do not close it. Several can be pinned at once, each placed where it covers none of the others or their nodes, and one that fits nowhere is left out of the frame. It shows the tooltip given with Tooltip, or for a TextNode.Truncate node cut to fit, its full text, even inside a node with NoTooltip, as the app asked for it. Text that fits, and a flow without a tooltip, show nothing. Use it to show the full text of a row the app has selected, which bloom does not know of.
Source Files
ΒΆ
Directories
ΒΆ
| Path | Synopsis |
|---|---|
|
_examples
module
|
|
|
Package anim animates numbers in a Bubble Tea model: a Value eases or springs toward a target, and a Presence is a value from 0 to 1 for showing and hiding something, such as a dialog.
|
Package anim animates numbers in a Bubble Tea model: a Value eases or springs toward a target, and a Presence is a value from 0 to 1 for showing and hiding something, such as a dialog. |
|
Package canvas holds the cell grids the layout engine composites: a Canvas of cells, parsed once from styled strings and cached by Cache, copied onto a frame with Canvas.Blit, and handed to effects as a Surface.
|
Package canvas holds the cell grids the layout engine composites: a Canvas of cells, parsed once from styled strings and cached by Cache, copied onto a frame with Canvas.Blit, and handed to effects as a Surface. |
|
Package fig renders text in FIGlet and TOIlet fonts: large letters made of ordinary characters, as bloom nodes or as plain strings.
|
Package fig renders text in FIGlet and TOIlet fonts: large letters made of ordinary characters, as bloom nodes or as plain strings. |
|
fonts
Package fonts holds FIGlet and TOIlet fonts for package fig: figlet's standard fonts, TOIlet's, and the fonts people use most, found by how often public code on GitHub asks for them.
|
Package fonts holds FIGlet and TOIlet fonts for package fig: figlet's standard fonts, TOIlet's, and the fonts people use most, found by how often public code on GitHub asks for them. |
|
fonts/internal/gen
command
Command gen builds package fonts from manifest.json: it downloads each font from the commit the manifest pins, checks it against the manifest's SHA-256, adds an SPDX-License-Identifier comment line to the fonts whose license is known, and writes the fonts gzipped, with fonts.gen.go and LICENSES.md.
|
Command gen builds package fonts from manifest.json: it downloads each font from the commit the manifest pins, checks it against the manifest's SHA-256, adds an SPDX-License-Identifier comment line to the fonts whose license is known, and writes the fonts gzipped, with fonts.gen.go and LICENSES.md. |
|
Package flex shares a fixed number of terminal cells between tracks, the rows or columns of a container, using integer arithmetic only.
|
Package flex shares a fixed number of terminal cells between tracks, the rows or columns of a container, using integer arithmetic only. |
|
Package fx has cell effects: functions that transform a node's rendered cells, or the frame beneath a dialog, for a progress value.
|
Package fx has cell effects: functions that transform a node's rendered cells, or the frame beneath a dialog, for a progress value. |
|
internal
|
|
|
anchor
Package anchor places a box against a side or corner of another, as a layer anchored to a node is, flipping it to the opposite side when it does not fit on the one asked for, or, with Scene.Fit, on whichever side hides the least of what is drawn on screen.
|
Package anchor places a box against a side or corner of another, as a layer anchored to a node is, flipping it to the opposite side when it does not fit on the one asked for, or, with Scene.Fit, on whichever side hides the least of what is drawn on screen. |
|
escape
Package escape tells apart the escape sequences in text that are safe to decode and to draw from those that are not.
|
Package escape tells apart the escape sequences in text that are safe to decode and to draw from those that are not. |
|
gen
command
Command gen writes nodes.gen.go in package bloom: the builder methods the node types share, such as ID and On, for each type listed in builders.go, and nodeMeta, which reads the meta of any of them.
|
Command gen writes nodes.gen.go in package bloom: the builder methods the node types share, such as ID and On, for each type listed in builders.go, and nodeMeta, which reads the meta of any of them. |
|
linebuf
Package linebuf keeps the lines of text a viewport shows, and works out what it draws of them: how wide each line is, the rows it wraps to, and the cells of a row as a string that draws them, as fast as a line of a log a million lines long needs.
|
Package linebuf keeps the lines of text a viewport shows, and works out what it draws of them: how wide each line is, the rows it wraps to, and the cells of a row as a string that draws them, as fast as a line of a log a million lines long needs. |
|
memo
Package memo keeps a value for each box of a tree, by its index, from one frame to the next, for boxes that tend to stay the same.
|
Package memo keeps a value for each box of a tree, by its index, from one frame to the next, for boxes that tend to stay the same. |
|
motion
Package motion tracks the layout animations of boxes with IDs from one frame to the next: boxes gliding to where layout puts them, and boxes moving there with effects.
|
Package motion tracks the layout animations of boxes with IDs from one frame to the next: boxes gliding to where layout puts them, and boxes moving there with effects. |
|
same
Package same tells whether the values a frame was drawn from are the same as the last frame's, so that what was worked out from them can be kept.
|
Package same tells whether the values a frame was drawn from are the same as the last frame's, so that what was worked out from them can be kept. |
|
textsel
Package textsel works out the text of cells selected with the mouse: the words of a row, the text of rows of cells, and how the rows of wrapped text join again once copied; where the ends of a selection are among the leaves of text it runs through and the lists between them, how many clicks a press is, and how selected cells are drawn.
|
Package textsel works out the text of cells selected with the mouse: the words of a row, the text of rows of cells, and how the rows of wrapped text join again once copied; where the ends of a selection are among the leaves of text it runs through and the lists between them, how many clicks a press is, and how selected cells are drawn. |
|
Package on makes mouse handlers for bloom nodes, attached with their On method:
|
Package on makes mouse handlers for bloom nodes, attached with their On method: |