Skip to content

Migrating to v1

Each identifier removed before v1, and what to use instead. The - BREAKING: entries under Removed in CHANGELOG.md list the same removals. No deprecated identifier is exported at v1.0.0.

WithInput, WithOutput and WithErrOutput now take any io.Reader or io.Writer, file or not, so the separate options for non-file streams are gone. Option defaults are in program.md.

Use WithInput. Given a reader that is not an *os.File, WithInput behaves as WithInputReader did: Run needs no terminal and doesn’t switch raw mode, and the Program quits when the reader returns io.EOF (TestWithInputPlainReaderNeedsNoTerminal). Given an *os.File, WithInput reads it as a terminal, and Run fails with a “not a terminal” error if it isn’t one (TestWithInputFileIsReadAsATerminal). To read a file as a plain stream instead, wrap it so it is no longer an *os.File, as the WithInput godoc shows (struct{ io.Reader }{f}).

A reader that also implements io.Closer is closed when the Program quits. WithInputCloser names a different closer to use instead.

Use WithOutput. A writer that is not an *os.File, such as a bytes.Buffer, has no terminal size: the Program assumes 80x24 and never queries or resizes it. A ResizeMsg can still deliver another size.

Use WithErrOutput, which sets where Eprintln writes (default os.Stderr). Any io.Writer receives the text as it is.

Use WithCellRenderer(false). The cell renderer is the default, and WithCellRenderer(false) selects the line renderer. See rendering.md for how the two differ.

Components (packages autocomplete, commandpalette)

Section titled “Components (packages autocomplete, commandpalette)”

autocomplete.Model.Init, commandpalette.Model.Init

Section titled “autocomplete.Model.Init, commandpalette.Model.Init”

Use Focus, which returns the same Cmd (the one that starts the cursor blink). A component has no Init; only a program’s root model does. Focus has a pointer receiver, so call it on an addressable Model: cmd := m.Focus().

Use an ansi.Measurer. ansi.ClusterMeasurer(false) counts each rune on its own and ansi.ClusterMeasurer(true) treats a grapheme cluster as one unit; call its Width, Truncate and TrimLeftWidth where you called the package-level functions. A Program’s own answer is Program.Measurer(), and every ResizeMsg carries it. To turn clusters off for a whole process, set TUI_NO_CLUSTERS=1 in the environment before the first width is measured; there is no function to change the default at run time.

Text fields (packages textinput, textarea)

Section titled “Text fields (packages textinput, textarea)”

Use tui.WithOutput to direct the Program’s output. Copy and Cut now always return tui.WriteClipboard, which has the Program write the OSC 52 sequence and keep the text, and Paste returns tui.PasteCopied, which delivers that text as a PasteEvent. There is no field to set.

Two things differ from a Model with ClipboardWrite set. Copy and Cut return a Cmd, so a parent must return it from its own Update. And the copy buffer belongs to the Program, not the Model, so two fields in one Program share it: what one copies the other pastes. A test that read the sequence from the function now runs the Cmd in a Program and reads that Program’s output.

The chart functions moved to widgets/chart with the same signatures. Change the import and the package qualifier; nothing else changes.

BarItem, BarChart, Gauge, HeatMap, LineChart, Sparkline, SparklineWith

Section titled “BarItem, BarChart, Gauge, HeatMap, LineChart, Sparkline, SparklineWith”

Use chart.BarItem, chart.BarChart, chart.Gauge, chart.HeatMap, chart.LineChart, chart.Sparkline and chart.SparklineWith, imported from github.com/ows4444/tui/widgets/chart. widgets.BarItem was an alias for chart.BarItem, so a value of one is a value of the other.

The string join and grid helpers are replaced by Nodes. Wrap each pre-rendered string in layout.Block to make it a Node, then compose Nodes with Row, Column and GridNode. ExampleCrossAlign and ExampleGridNode in layout/example_test.go show the replacements in use, and layout.md covers sizing with FlexChild.

Box, Overlay and JoinHorizontalJustify still work on strings and are not removed.

Use layout.Row(gap, children...), with one FlexChild per block.

Use layout.BoxNode(box, layout.Block(content)), or BoxNode with any Node as the child, and draw it with layout.Draw (or place it in a layout). The method is unexported, not deleted: BoxNode draws through it, so the cells are the ones Box.Render gave. A box with a Width, a Height or a title now takes the room it asks for, as the changelog says under Changed.

Use layout.Row and set CrossAlign on each FlexChild: CrossStart, CrossCenter or CrossEnd. The zero value, CrossStretch, stretches the child to the row’s full height.

Use layout.Column(gap, children...), with one FlexChild per block.

Use layout.Column and set CrossAlign on each FlexChild, as for JoinHorizontalAlign. In a Column the cross axis is horizontal, so CrossStart keeps a child at its own width, flush left (ExampleColumn_crossStart).

Use layout.Row. Sizing that was set per item now goes in each child’s FlexChild fields (Basis, BasisLen, Grow, Shrink, Min, Max).

Use layout.FlexChild. The zero FlexChild is sized to its content and neither grows nor shrinks; layout.Fill(n) makes a child take the space left over.

Use layout.GridNode(tracks, gap, cells...). It takes one Track per column and fills cells row by row. GridNodeGaps gives rows and columns different gaps.

Use layout.GridNode. A Track with Grow > 0 shares the grid’s leftover width by weight, on top of the column’s content width.

Use layout.Track. The zero Track sizes the column to its widest cell, Size > 0 fixes the width, and Grow > 0 shares leftover width.