bloom

package module
v0.0.0-alpha.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 33 Imported by: 3 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README ΒΆ

banner

πŸ”— Table of Contents

✨ Features

bloom is a layout, compositing, and animation engine for Bubble Tea programs. Describe your view as a tree of rows, columns, and layers, built from your model every frame, and bloom sizes it to the terminal, draws dialogs and toasts on top, animates what changes, and tells you what the mouse is over.

[!WARNING] bloom is still pre-1.0. Its API may change drastically until the v1.0.0 release, so expect breaking changes between versions, and pin the version you use.

  • βœ” Layout without the math: Row, Column, Grid, and Wrap, with Fixed, Fill, Grow, Percent, and natural-size slots, Min/Max, gaps, alignment, and justification. No more measuring rendered strings and subtracting borders on every resize.
  • βœ” Responsive by priority: panels marked Collapsible drop out when the terminal is too small, lowest priority first, components can build a different layout for the space they're given, and MinSize shows a "window too small" note in place of a layout that can't fit.
  • βœ” Real layers: Overlay draws dialogs, dropdowns, popovers, and toasts over the screen, anchored to a corner or to another node, with backdrops, drop shadows, and modal input.
  • βœ” Mouse handlers: clicks, double clicks, the wheel, hover, and drags go to handlers on the nodes they belong to, like bloom.Text(name).On(on.Click(m.open)). Hover styles and drag capture are built in.
  • βœ” Focus: tab order from the layout, styles for the focused node, the real terminal cursor, and focus scopes that keep tab inside a dialog until it closes.
  • βœ” Tooltips: Tooltip("Deploy") on any node, and text cut short with "…" unfolds in place under the pointer, with placement that hides the least of the screen, a status line sink, and keyboard access through focus and pinning.
  • βœ” Animation kept in your model: eased and spring values, presences for showing and hiding (with ShowFor for toasts that hide themselves), sequences of steps, and automatic layout animation with Animate().
  • βœ” 25+ cell effects: Fade, Slide, Iris, Unfold, Decode, Glitch, and more as transitions; Dim, Desaturate, Recolor, and Spotlight as backdrops; Shake, Shimmer, Roll, and Burst for feedback; Chase, Pulse, Comet, and March for looping borders; and combinators to stagger, delay, reverse, and ease them. Or write your own.
  • βœ” Borders that do more: put titles, clickable tabs, icon buttons, and counters on a box's border with Edge, plus draggable scrollbars that only show up when there's more to scroll.
  • βœ” Viewports for a lot of text: Viewport shows a Buffer of lines, such as a log of a million, drawing only those in sight, with wrapping, following the end, line numbers, search marks, and selection.
  • βœ” Loading placeholders: Skeleton(8, 0, 5, 11) draws shimmering bars in place of content that's still loading, a line for each line of the content, so nothing jumps when it arrives.
  • βœ” FIGlet text: package fig draws big text in 67 bundled FIGlet and TOIlet fonts, laid out as C figlet does, with gradients and other paints, smaller fonts as space runs short, and letters animated one at a time with bloom's effects and layout animation.
  • βœ” Works with existing components: anything with a View() string method, including Bubbles components, is a leaf in the tree.
  • βœ” Fast: strings are parsed once, Lip Gloss renders are cached, and unchanged frames aren't composited again. A 200Γ—60 dashboard animating a dialog over a dimmed backdrop takes about 0.45ms a frame.

βš™ Usage

Take a look at the official documentation for tutorials, guides, and reference, starting with building your first layout. The documentation is also available for LLMs and agents as llms.txt and llms-full.txt, and every page has a markdown version.

func (m *model) View() tea.View {
	v := m.ui.View(m.width, m.height, bloom.Overlay(
		bloom.Column(
			bloom.Fill(bloom.Row(
				bloom.Fixed(24, m.sidebar).Collapsible(1),
				bloom.Fill(m.reader).Min(40),
			)),
			m.statusbar,
		),
		bloom.Layer(m.dialog).
			Modal().
			Backdrop(fx.Dim{Amount: 0.5}).
			Presence(m.dialogAnim, fx.Fade{}, fx.Slide{From: bloom.Bottom}),
		bloom.Layer(m.toast).
			Anchor(bloom.End, bloom.End).
			Presence(m.toastAnim, fx.Slide{From: bloom.Right}),
	))
	v.AltScreen = true
	return v
}

The model keeps a *bloom.Root from bloom.New(), returns m.ui.Init() from Init, and passes every message to m.ui.Update. Build your first layout walks through a complete program, and Add bloom to an existing program converts one you already have.

Runnable programs, from a basic layout to a 120 FPS dashboard, are in _examples. Run one with go run ./forms from that directory.

go get -u bloomfx.dev/bloom@latest

bloom needs Go 1.27 or newer, Bubble Tea v2 (charm.land/bubbletea/v2), and Lip Gloss v2 (charm.land/lipgloss/v2). It isn't built for Bubble Tea v1; see Installation.

  • bubbletint: hundreds of terminal color themes for Bubble Tea and Lip Gloss, which work directly in bloom's styles and effects.
  • steep: a test harness that runs terminal programs, including Bubble Tea programs, in an emulated terminal, used for bloom's own end-to-end tests. Docs are at getsteep.dev.

πŸ™‹β™‚ Support & Assistance

  • ❀ Please review the Code of Conduct for guidelines on ensuring everyone has the best experience interacting with the community.
  • πŸ™‹β™‚ Take a look at the support document on guidelines for tips on how to ask the right questions.
  • 🐞 For all features/bugs/issues/questions/etc, head over here.

🀝 Contributing

  • ❀ Please review the Code of Conduct for guidelines on ensuring everyone has the best experience interacting with the community.
  • πŸ“‹ Please review the contributing doc for submitting issues/a guide on submitting pull requests and helping out.
  • πŸ— For anything security related, please review this repositories security policy.

βš– License

MIT License

Copyright (c) 2026 Liam Stanley <liam@liam.sh>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Also located here

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 ΒΆ

View Source
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.

View Source
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 ΒΆ

View Source
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 ΒΆ

func Debug(w, h int, c Child) string

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 ΒΆ

func MarkMatches(re *regexp.Regexp, style lipgloss.Style) func(line int, text string) []Mark

MarkMatches returns a function for ViewportNode.Marks that marks every match of re in style. A nil re marks nothing.

func Render ΒΆ

func Render(w, h int, c Child) string

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 ΒΆ

func ThrottleMouse(every time.Duration) func(tea.Model, tea.Msg) tea.Msg

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.

const (
	// Stretch makes a child as big as the space it is in. It is the default
	// for children of a row or column.
	Stretch Align = iota
	// Start puts a child at the top or left.
	Start
	// Center puts a child in the middle.
	Center
	// End puts a child at the bottom or right.
	End
)

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 ΒΆ

func Box(style lipgloss.Style, child Child) BoxNode

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 ΒΆ

func (n BoxNode) BorderFx(t float64, effects ...fx.Effect) BoxNode

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 ΒΆ

func (n BoxNode) Edge(side Direction, align Align, child Child) BoxNode

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 ΒΆ

func (n BoxNode) EdgeAt(side Direction, at int, child Child) BoxNode

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) Focusable ΒΆ

func (n BoxNode) Focusable() BoxNode

Focusable makes the box one that Focus can move to.

func (BoxNode) HoverStyle ΒΆ

func (n BoxNode) HoverStyle(style lipgloss.Style) BoxNode

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 ΒΆ

func (n BoxNode) ID(id ID) BoxNode

ID sets the ID that focus and Frame.Rect refer to the box by.

func (BoxNode) Layout ΒΆ

func (n BoxNode) Layout(Context) Child

Layout implements Child, returning the box itself: bloom lays it out without calling it.

func (BoxNode) NoTooltip ΒΆ

func (n BoxNode) NoTooltip() BoxNode

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 ΒΆ

func (n BoxNode) On(handlers ...on.Handler) BoxNode

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 ΒΆ

func (n BoxNode) Selectable() BoxNode

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 ΒΆ

func (n BoxNode) Tooltip(text string, opts ...TipOption) BoxNode

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 ΒΆ

func (n BoxNode) TooltipOpen(open bool) BoxNode

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 ΒΆ

func NewBuffer(s string) *Buffer

NewBuffer returns a buffer holding s, as Buffer.SetContent sets it.

func (*Buffer) Append ΒΆ

func (b *Buffer) Append(lines ...string)

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 ΒΆ

func (b *Buffer) Clamp(p Pos) Pos

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) Clear ΒΆ

func (b *Buffer) Clear()

Clear removes every line.

func (*Buffer) Delete ΒΆ

func (b *Buffer) Delete(from, to Pos) Change

Delete removes the text from from up to to, as Buffer.Replace removes it, and returns the change.

func (*Buffer) Edit ΒΆ

func (b *Buffer) Edit(edits ...Edit) Change

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) End ΒΆ

func (b *Buffer) End() Pos

End returns the end of the buffer's text: the end of its last line.

func (*Buffer) Find ΒΆ

func (b *Buffer) Find(re *regexp.Regexp, line, at int) (Match, bool)

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 ΒΆ

func (b *Buffer) FindBefore(re *regexp.Regexp, line, at int) (Match, bool)

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 ΒΆ

func (b *Buffer) Insert(at Pos, text string) Change

Insert puts text at at, as Buffer.Replace puts it in, and returns the change.

func (*Buffer) Len ΒΆ

func (b *Buffer) Len() int

Len returns the number of lines.

func (*Buffer) Line ΒΆ

func (b *Buffer) Line(i int) string

Line returns line i as it was given, with its styles, or "" when there is no such line.

func (*Buffer) Next ΒΆ

func (b *Buffer) Next(p Pos) Pos

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 ΒΆ

func (b *Buffer) NextWord(p Pos) Pos

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 ΒΆ

func (b *Buffer) Offset(p Pos) int

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 ΒΆ

func (b *Buffer) PosOf(offset int) Pos

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 ΒΆ

func (b *Buffer) Prev(p Pos) Pos

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 ΒΆ

func (b *Buffer) PrevWord(p Pos) Pos

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 ΒΆ

func (b *Buffer) Replace(from, to Pos, text string) Change

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 ΒΆ

func (b *Buffer) Restore(s Snapshot)

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 ΒΆ

func (b *Buffer) Rev() uint64

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 ΒΆ

func (b *Buffer) SetContent(s string)

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 ΒΆ

func (b *Buffer) SetLines(lines ...string)

SetLines replaces the buffer's lines with lines. A line holding newlines is split at them.

func (*Buffer) SetWordChars ΒΆ

func (b *Buffer) SetWordChars(chars string)

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 ΒΆ

func (b *Buffer) Snapshot() 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) String ΒΆ

func (b *Buffer) String() string

String returns the buffer's lines, joined with newlines.

func (*Buffer) Text ΒΆ

func (b *Buffer) Text(i int) string

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 ΒΆ

func (b *Buffer) TextIn(from, to Pos) string

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 ΒΆ

func (b *Buffer) WordAt(p Pos) (from, to Pos, ok bool)

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 ΒΆ

func (c Change) End() Pos

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 ΒΆ

func (c Change) Map(p Pos) Pos

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 ΒΆ

func (c Change) MapAfter(p Pos) Pos

MapAfter is Change.Map, but a position where text was put in goes after that text, as a caret where text is typed does.

func (Change) MapRange ΒΆ

func (c Change) MapRange(r Range) Range

MapRange returns where range r is after the change, its ends mapped so that text put in at either end is left out of it, and a caret, an empty range, mapped as Change.Map maps a position. EndOfRow is kept.

type Child ΒΆ

type Child interface {
	Layout(ctx Context) 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 ΒΆ

func (c Context) Frame() *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 ΒΆ

func (c Context) Height() int

Height returns the height available. Once layout is done it is the exact height the component was given.

func (Context) Side ΒΆ

func (c Context) Side() (Direction, bool)

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) Size ΒΆ

func (c Context) Size() Size

Size returns the space available, its width and height together.

func (Context) Width ΒΆ

func (c Context) Width() int

Width returns the width available. Once layout is done it is the exact width the component was given.

func (Context) WidthMethod ΒΆ

func (ctx Context) WidthMethod() ansi.Method

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 ΒΆ

type Direction = fx.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 ΒΆ

type Edit struct {
	From, To Pos
	Text     string
}

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 Column ΒΆ

func Column(children ...Child) FlexNode

Column lays children out top to bottom.

func Row ΒΆ

func Row(children ...Child) FlexNode

Row lays children out left to right.

func (FlexNode) Align ΒΆ

func (n FlexNode) Align(a Align) FlexNode

Align sets where children go on the cross axis. The default is Stretch.

func (FlexNode) Focusable ΒΆ

func (n FlexNode) Focusable() FlexNode

Focusable makes the row or column one that Focus can move to.

func (FlexNode) Gap ΒΆ

func (n FlexNode) Gap(cells int) FlexNode

Gap puts n cells between children.

func (FlexNode) ID ΒΆ

func (n FlexNode) ID(id ID) FlexNode

ID sets the ID that focus and Frame.Rect refer to the row or column by.

func (FlexNode) Justify ΒΆ

func (n FlexNode) Justify(j flex.Justify) FlexNode

Justify sets where children go on the main axis when none of them grow.

func (FlexNode) Layout ΒΆ

func (n FlexNode) Layout(Context) Child

Layout implements Child, returning the row or column itself: bloom lays it out without calling it.

func (FlexNode) NoTooltip ΒΆ

func (n FlexNode) NoTooltip() FlexNode

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 ΒΆ

func (n FlexNode) On(handlers ...on.Handler) FlexNode

On adds mouse handlers to the node, made by package on. They take events on the gaps between children too.

func (FlexNode) Selectable ΒΆ

func (n FlexNode) Selectable() FlexNode

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 ΒΆ

func (n FlexNode) Tooltip(text string, opts ...TipOption) FlexNode

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 ΒΆ

func (n FlexNode) TooltipOpen(open bool) FlexNode

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) Clear ΒΆ

func (f *Focus) Clear()

Clear removes the focus.

func (*Focus) Current ΒΆ

func (f *Focus) Current() ID

Current returns the ID of the focused node, or "" when no node is focused.

func (*Focus) Is ΒΆ

func (f *Focus) Is(id ID) bool

Is reports whether the node with ID id is focused.

func (*Focus) Next ΒΆ

func (f *Focus) Next(frame *Frame) bool

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 ΒΆ

func (f *Focus) Prev(frame *Frame) bool

Prev focuses the previous node that can be focused, as Focus.Next does.

func (*Focus) Push ΒΆ

func (f *Focus) Push(scope ID)

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) Scope ΒΆ

func (f *Focus) Scope() ID

Scope returns the ID of the innermost scope pushed, or "".

func (*Focus) Set ΒΆ

func (f *Focus) Set(id ID)

Set focuses the node with ID id. Setting "" clears the focus.

func (*Focus) Update ΒΆ

func (f *Focus) Update(msg tea.Msg, frame *Frame) (tea.Cmd, bool)

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.

func (*Focus) Within ΒΆ

func (f *Focus) Within(frame *Frame, scope ID) bool

Within reports whether the focused node is inside the scope with ID scope in frame.

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 ΒΆ

func Solve(w, h int, c Child) *Frame

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 ΒΆ

func (f *Frame) Hit(x, y int) []ID

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 ΒΆ

func (f *Frame) List(id ID) (ListView, bool)

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 ΒΆ

func (f *Frame) Rect(id ID) (image.Rectangle, bool)

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 ΒΆ

func (f *Frame) Truncated(id ID) bool

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 ΒΆ

func Grid(cols int, children ...Child) GridNode

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) Focusable ΒΆ

func (n GridNode) Focusable() GridNode

Focusable makes the grid one that Focus can move to.

func (GridNode) Gap ΒΆ

func (n GridNode) Gap(x, y int) GridNode

Gap sets the horizontal and vertical space between cells.

func (GridNode) ID ΒΆ

func (n GridNode) ID(id ID) GridNode

ID sets the ID that focus and Frame.Rect refer to the grid by.

func (GridNode) Layout ΒΆ

func (n GridNode) Layout(Context) Child

Layout implements Child, returning the grid itself: bloom lays it out without calling it.

func (GridNode) NoTooltip ΒΆ

func (n GridNode) NoTooltip() GridNode

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) On ΒΆ

func (n GridNode) On(handlers ...on.Handler) GridNode

On adds mouse handlers to the grid, made by package on.

func (GridNode) Selectable ΒΆ

func (n GridNode) Selectable() GridNode

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 ΒΆ

func (n GridNode) Tooltip(text string, opts ...TipOption) GridNode

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 ΒΆ

func (n GridNode) TooltipOpen(open bool) GridNode

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 ΒΆ

func NewID(name string) ID

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 ΒΆ

func (id ID) IsZero() bool

IsZero reports whether id is the empty ID, the zero value of ID, which names no node.

func (ID) Sub ΒΆ

func (id ID) Sub[P string | int](part P) ID

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 ΒΆ

func Layer(child Child) LayerNode

Layer returns a layer showing child at its natural size, in the middle of its overlay.

func (LayerNode) Anchor ΒΆ

func (n LayerNode) Anchor(x, y Align) LayerNode

Anchor sets where the layer goes in its overlay on each axis.

func (LayerNode) AnchorTo ΒΆ

func (n LayerNode) AnchorTo(id ID, side Direction) LayerNode

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 ΒΆ

func (n LayerNode) Animate(opts ...anim.Option) LayerNode

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 ΒΆ

func (n LayerNode) Backdrop(effects ...fx.Effect) LayerNode

Backdrop applies effects to everything drawn beneath the layer, with the layer's transition progress as their strength.

func (LayerNode) Float ΒΆ

func (n LayerNode) Float() LayerNode

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) Focusable ΒΆ

func (n LayerNode) Focusable() LayerNode

Focusable makes the layer one that Focus can move to.

func (LayerNode) ID ΒΆ

func (n LayerNode) ID(id ID) LayerNode

ID sets the ID that focus, layout animation, anchoring, and Frame.Rect refer to the layer by.

func (LayerNode) Layout ΒΆ

func (n LayerNode) Layout(Context) Child

Layout implements Child, returning the layer itself: bloom lays it out without calling it.

func (LayerNode) Margin ΒΆ

func (n LayerNode) Margin(cells int) LayerNode

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 ΒΆ

func (n LayerNode) Modal() LayerNode

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 ΒΆ

func (n LayerNode) MoveWith(effects ...fx.Effect) LayerNode

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 ΒΆ

func (n LayerNode) NoTooltip() LayerNode

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) Offset ΒΆ

func (n LayerNode) Offset(x, y int) LayerNode

Offset moves the layer from where it is anchored.

func (LayerNode) On ΒΆ

func (n LayerNode) On(handlers ...on.Handler) LayerNode

On adds mouse handlers to the layer, made by package on.

func (LayerNode) Place ΒΆ

func (n LayerNode) Place(r image.Rectangle) LayerNode

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 ΒΆ

func (n LayerNode) Presence(p anim.Presence, effects ...fx.Effect) LayerNode

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 ΒΆ

func (n LayerNode) Selectable() LayerNode

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 ΒΆ

func (n LayerNode) Shadow(x, y int, effects ...fx.Effect) LayerNode

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 ΒΆ

func (n LayerNode) Size(w, h int) LayerNode

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 ΒΆ

func (n LayerNode) Tooltip(text string, opts ...TipOption) LayerNode

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 ΒΆ

func (n LayerNode) TooltipOpen(open bool) LayerNode

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 ΒΆ

func (n LayerNode) Transition(t float64, effects ...fx.Effect) LayerNode

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 ΒΆ

func (n LayerNode) Transparent() LayerNode

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 ΒΆ

type LayoutFunc func(ctx Context) Child

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))
})

func (LayoutFunc) Layout ΒΆ

func (f LayoutFunc) Layout(ctx Context) Child

Layout implements Child, calling f.

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 ΒΆ

func List(count int, item func(i int) Child) ListNode

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) Focusable ΒΆ

func (n ListNode) Focusable() ListNode

Focusable makes the list one that Focus can move to.

func (ListNode) Gap ΒΆ

func (n ListNode) Gap(cells int) ListNode

Gap puts n cells between items.

func (ListNode) ID ΒΆ

func (n ListNode) ID(id ID) ListNode

ID sets the ID that focus, Frame.Rect, Frame.List, and ScrollbarOf refer to the list by.

func (ListNode) ItemText ΒΆ

func (n ListNode) ItemText(text func(i int) string) ListNode

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 ΒΆ

func (n ListNode) Keep(i int) ListNode

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 ΒΆ

func (n ListNode) Layout(Context) Child

Layout implements Child, returning the list itself: bloom lays it out without calling it.

func (ListNode) NoTooltip ΒΆ

func (n ListNode) NoTooltip() ListNode

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) Offset ΒΆ

func (n ListNode) Offset(i int) ListNode

Offset sets the first item shown.

func (ListNode) On ΒΆ

func (n ListNode) On(handlers ...on.Handler) ListNode

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 ΒΆ

func (n ListNode) Selectable() ListNode

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 ΒΆ

func (n ListNode) Tooltip(text string, opts ...TipOption) ListNode

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 ΒΆ

func (n ListNode) TooltipOpen(open bool) ListNode

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 ΒΆ

type Measurer interface {
	Measure(avail Size) Size
}

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 ΒΆ

func WithClickDelay(enabled bool) Option

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 ΒΆ

func WithClipboard(write func(text string) error) Option

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 ΒΆ

func WithClock(now func() time.Time) Option

WithClock sets the clock for layout animations and for telling double clicks apart, for tests. It must not be nil.

func WithColors ΒΆ

func WithColors(fg, bg color.Color) Option

WithColors sets the terminal's default colors, for effects that blend colors, until the terminal reports its own (see Root.Init).

func WithCopyFlash ΒΆ

func WithCopyFlash(enabled bool) Option

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 ΒΆ

func WithFPS(n int) Option

WithFPS sets the layout animation tick rate, defaulting to 60. Values below one use one frame per second.

func WithFocus ΒΆ

func WithFocus(f *Focus) Option

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 ΒΆ

func WithSelectionStyle(style lipgloss.Style) Option

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 ΒΆ

func WithTooltips(t Tooltips) Option

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 ΒΆ

func WithUnfocusedFPS(n int) Option

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 ΒΆ

func WithWidthMethod(method ansi.Method) Option

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 ΒΆ

func WithWordChars(chars string) Option

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.

func (Pos) Before ΒΆ

func (p Pos) Before(q Pos) bool

Before reports whether p comes before q.

func (Pos) Compare ΒΆ

func (p Pos) Compare(q Pos) int

Compare returns -1 when p comes before q, 1 when it comes after, and 0 when they are the same.

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 ΒΆ

func (r Range) Collapse() Range

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) Empty ΒΆ

func (r Range) Empty() bool

Empty reports whether the range holds no text, as a caret does.

func (Range) From ΒΆ

func (r Range) From() Pos

From returns the end of the range that comes first.

func (Range) To ΒΆ

func (r Range) To() Pos

To returns the end of the range that comes last.

func (Range) WithHead ΒΆ

func (r Range) WithHead(p Pos) Range

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 New ΒΆ

func New(opts ...Option) *Root

New returns a Root.

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 ΒΆ

func (r *Root) Click(id ID) (tea.Cmd, bool)

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 ΒΆ

func (r *Root) ClickAt(x, y int) tea.Cmd

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 ΒΆ

func (r *Root) CopySelection() tea.Cmd

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 ΒΆ

func (r *Root) EnableTooltips(on bool)

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 ΒΆ

func (r *Root) Frame() *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 ΒΆ

func (r *Root) Init() tea.Cmd

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 ΒΆ

func (r *Root) Render(w, h int, c Child) string

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 ΒΆ

func (r *Root) SelectAll(id ID) bool

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 ΒΆ

func (r *Root) Selection() (string, bool)

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 ΒΆ

func (r *Root) SetTooltips(t Tooltips)

SetTooltips replaces the configuration of tooltips, such as for a new theme, without turning them on or off.

func (*Root) Tooltip ΒΆ

func (r *Root) Tooltip() (string, bool)

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 ΒΆ

func (r *Root) Update(msg tea.Msg) tea.Cmd

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 ΒΆ

func (r *Root) View(w, h int, c Child) tea.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 ΒΆ

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 ΒΆ

func Measure(w, h int, c Child) Size

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 ΒΆ

func Auto(child Child) SlotNode

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 Fill ΒΆ

func Fill(child Child) SlotNode

Fill places child in an equal share of the space left by its siblings.

func Fixed ΒΆ

func Fixed(n int, child Child) SlotNode

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 ΒΆ

func Grow(weight int, child Child) SlotNode

Grow places child in a share of the space left by its siblings, weighted against the other growing children's weights.

func Percent ΒΆ

func Percent(p int, child Child) SlotNode

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) Align ΒΆ

func (n SlotNode) Align(a Align) SlotNode

Align overrides the container's cross-axis alignment for this slot.

func (SlotNode) Animate ΒΆ

func (n SlotNode) Animate(opts ...anim.Option) SlotNode

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 ΒΆ

func (n SlotNode) Collapsible(priority int) SlotNode

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) Focusable ΒΆ

func (n SlotNode) Focusable() SlotNode

Focusable makes the slot one that Focus can move to.

func (SlotNode) ID ΒΆ

func (n SlotNode) ID(id ID) SlotNode

ID sets the ID that focus, layout animation, and Frame.Rect refer to the slot by.

func (SlotNode) Layout ΒΆ

func (n SlotNode) Layout(Context) Child

Layout implements Child, returning the slot itself: bloom lays it out without calling it.

func (SlotNode) Max ΒΆ

func (n SlotNode) Max(cells int) SlotNode

Max sets the largest size the slot grows to on the main axis.

func (SlotNode) Min ΒΆ

func (n SlotNode) Min(cells int) SlotNode

Min sets the smallest size the slot shrinks to on the main axis.

func (SlotNode) MoveWith ΒΆ

func (n SlotNode) MoveWith(effects ...fx.Effect) SlotNode

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 ΒΆ

func (n SlotNode) NoTooltip() SlotNode

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) On ΒΆ

func (n SlotNode) On(handlers ...on.Handler) SlotNode

On adds mouse handlers to the slot, made by package on.

func (SlotNode) Scope ΒΆ

func (n SlotNode) Scope() SlotNode

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 ΒΆ

func (n SlotNode) Selectable() SlotNode

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 ΒΆ

func (n SlotNode) Tooltip(text string, opts ...TipOption) SlotNode

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 ΒΆ

func (n SlotNode) TooltipOpen(open bool) SlotNode

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) Len ΒΆ

func (s Snapshot) Len() int

Len returns the number of lines.

func (Snapshot) Line ΒΆ

func (s Snapshot) Line(i int) string

Line returns line i as it was given, with its styles, or "" when there is no such line.

func (Snapshot) Lines ΒΆ

func (s Snapshot) Lines() iter.Seq2[int, string]

Lines returns an iterator over the lines, as they were given, with their styles, and their numbers.

func (Snapshot) String ΒΆ

func (s Snapshot) String() string

String returns the lines, joined with newlines.

func (Snapshot) Text ΒΆ

func (s Snapshot) Text(i int) string

Text returns the text of line i without its styles, as Buffer.Text does, or "" when there is no such line.

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 ΒΆ

func Text(s string) TextNode

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 ΒΆ

func (n TextNode) Cursor(c *tea.Cursor) TextNode

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) Focusable ΒΆ

func (n TextNode) Focusable() TextNode

Focusable makes the node one that Focus can move to.

func (TextNode) HoverStyle ΒΆ

func (n TextNode) HoverStyle(style lipgloss.Style) TextNode

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 ΒΆ

func (n TextNode) ID(id ID) TextNode

ID sets the ID that focus and Frame.Rect refer to the node by.

func (TextNode) Layout ΒΆ

func (n TextNode) Layout(Context) Child

Layout implements Child, returning the node itself: bloom lays it out without calling it.

func (TextNode) NoTooltip ΒΆ

func (n TextNode) NoTooltip() TextNode

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 ΒΆ

func (n TextNode) NoWrap() TextNode

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) On ΒΆ

func (n TextNode) On(handlers ...on.Handler) TextNode

On adds mouse handlers to the node, made by package on.

func (TextNode) Selectable ΒΆ

func (n TextNode) Selectable() TextNode

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 ΒΆ

func (n TextNode) Style(style lipgloss.Style) TextNode

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 ΒΆ

func (n TextNode) Tooltip(text string, opts ...TipOption) TextNode

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 ΒΆ

func (n TextNode) TooltipOpen(open bool) TextNode

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 ΒΆ

func (n TextNode) Truncate() TextNode

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 ΒΆ

func (n TextNode) Trusted() TextNode

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 ΒΆ

func TipDelay(d time.Duration) TipOption

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 ΒΆ

func TipSide(side Direction) TipOption

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.

func TipStyle ΒΆ

func TipStyle(style lipgloss.Style) TipOption

TipStyle draws the tooltip with style, in place of the Tooltips Style.

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 ΒΆ

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 ΒΆ

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 ΒΆ

func Present(p anim.Presence, child Child, effects ...fx.Effect) TransitionNode

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 ΒΆ

func View(v Viewer) ViewNode

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.

func (ViewNode) Layout ΒΆ

func (n ViewNode) Layout(Context) Child

Layout implements Child, returning the node itself.

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 ΒΆ

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 WrapMode ΒΆ

type WrapMode uint8

WrapMode is how a Viewport fits lines wider than it is.

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 ΒΆ

func Wrap(children ...Child) WrapNode

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) Focusable ΒΆ

func (n WrapNode) Focusable() WrapNode

Focusable makes the flow one that Focus can move to.

func (WrapNode) Gap ΒΆ

func (n WrapNode) Gap(x, y int) WrapNode

Gap sets the horizontal space between children and vertical space between lines.

func (WrapNode) ID ΒΆ

func (n WrapNode) ID(id ID) WrapNode

ID sets the ID that focus and Frame.Rect refer to the flow by.

func (WrapNode) Layout ΒΆ

func (n WrapNode) Layout(Context) Child

Layout implements Child, returning the flow itself: bloom lays it out without calling it.

func (WrapNode) NoTooltip ΒΆ

func (n WrapNode) NoTooltip() WrapNode

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) On ΒΆ

func (n WrapNode) On(handlers ...on.Handler) WrapNode

On adds mouse handlers to the flow, made by package on.

func (WrapNode) Selectable ΒΆ

func (n WrapNode) Selectable() WrapNode

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 ΒΆ

func (n WrapNode) Tooltip(text string, opts ...TipOption) WrapNode

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 ΒΆ

func (n WrapNode) TooltipOpen(open bool) WrapNode

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.

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.
fig
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:

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL