github anomalyco/opentui v0.8.0
Release v0.8.0

4 hours ago

Most of 0.8.0 makes each frame cheaper. In 0.7.0, every frame cleared and repainted the whole screen and compared every row with the terminal, even when only a spinner had moved. Now an unchanged frame paints nothing, and a frame with a small change repaints only the rows around it. In OpenCode, a frame with a spinner or a streamed line does about a twentieth of the cell operations it did.

ScrollBox now scrolls and follows new content in native code. Animations share one clock: before, an app with several animations could draw twice as many frames as the animations needed.

The native input parser is still opt-in. It now keeps a mouse wheel report that a slow link splits, which the default parser can type into the focused input as text. To try it, set OTUI_NATIVE_INPUT_PARSER=1, or pass experimental_nativeInput: true to the renderer.

Wide emoji sequences, such as a family emoji in tmux, draw at their full width, and long wrapped or highlighted lines draw their last rows as fast as their first.

In 0.7.0, a ScrollBox was twelve scene nodes. It kept its scroll position in four copies, followed its sticky edge through a six-flag state machine, and learned its range from two separate resize hooks. Because the viewport size and the content size came from different hooks, a frame in which the box and its content grew together reset the position to 0. Vertical viewport padding left the last rows out of reach, and the scrollbar thumb was half a cell until the first terminal resize. In 0.8.0, a ScrollBox is one box with a native scroll control. After each layout solve, native code computes the range, follows the sticky edge, clamps the offset, and shows or hides the bars, all from one layout. Following new content no longer needs a round trip to JavaScript.

That change has a cost for code that reached into the parts. wrapper, viewport, content, and the two scrollbars are now views of the native state, not renderables. They still have geometry, colors, padding, and their events, but they have no children of their own. Children of a ScrollBox report the ScrollBox as their parent, and a press on a scrollbar targets the ScrollBox. Code that compared a node with the content part now compares it with the ScrollBox itself:

// 0.7.0
if (node === scroll.content) return
// 0.8.0
if (node === scroll) return

With the scroll state in native code, a scroll can also wait for layout. Before, an app that loaded older messages above the reader and then corrected the position had to wait two animation frames, and the reader saw one frame at the old position. Now scrollTo and scrollBy apply again after the next frame's layout, and anchor holds a row in place while the content above it changes. Release the anchor in afterLayout, so that the frame that lays out the new rows still holds the place:

const release = scrollbox.anchor(firstVisibleRow)
await loadOlderMessages()
scrollbox.afterLayout(release)

In an OpenCode transcript, this took the shifted frames during a backfill from 1 to 0, and the in-between frames over 6 message jumps from 6 to 0.

An animation slower than the renderer, such as a spinner, used to have two options. It could set live: true, which runs the loop at targetFps and keeps renderer.idle() from resolving. Or it could run its own timer that calls requestRender(). With timers, every component gets its own frames, so three components at 20, 12.5, and 10 fps drew 40 frames per second. renderer.onAnimationTick puts every subscriber on one clock. Due times are multiples of 1000 / fps, so equal rates tick together. Each frame, whatever its cause, also runs every tick that is due within its tolerance. The same three components now draw 20 frames per second, and OpenCode during an agent turn draws 26 instead of 52 to 55:

const frames = ["⠋", "⠙", "⠹", "⠸"]
let i = 0
const stop = renderer.onAnimationTick(12.5, () => {
  spinner.content = frames[i++ % frames.length]
})

A renderable can set animationFps instead. React components use useAnimationTick, and Solid components use onAnimationTick.

Before 0.8.0, OpenTUI wrapped every frame in synchronized output (CSI ? 2026 h … CSI ? 2026 l), even when the terminal never reported mode 2026. Over a slow link, those wrappers cost bytes on every frame. A tmux between the app and the link redraws each line that an update touched when the update ends, so a streaming scene sent 64 KB/s instead of 41 KB/s. On a 48 KB/s SSH link, that is a lag of 2.0 s instead of 75 ms. The new default, synchronizedOutput: "auto", removes the wrapper in a remote session once the startup replies arrive, but only when the terminal did not report mode 2026, or when the app writes to process.stdout inside tmux, screen, or Zellij on its own host. In the multiplexer case, OpenTUI gives up whole frames to save bytes, so tmux can show partial frames. If you want whole frames on a slow link, set synchronizedOutput: "always".

Breaking changes

  • core: The wrapper, viewport, content, verticalScrollBar, and horizontalScrollBar of a ScrollBox are facade objects (ScrollBoxWrapper, ScrollBoxViewport, ScrollBoxContent, ScrollBoxBar), not renderables. Children report the ScrollBox as their parent, so compare a node with the ScrollBox, not with scroll.content. See ScrollBox. (#1805)
  • core: ScrollBox scrollbars have no slider, startArrow, or endArrow, overflow is always "hidden", getChildrenCount() counts the rows, and primaryAxis follows the content direction. ScrollBox ignores renderable options on its parts outside each part's supported color, layout, padding, bar, and callback fields, and viewport padding that is not whole cells throws. See ScrollBox. (#1805)
  • core: RenderContext requires the clock and onAnimationTick fields, so a custom RenderContext must implement them. The renderer and the scrollback snapshot context supply both. See Custom renderables. (#1814, #1803)
  • core: The protected Renderable._hasFocusedDescendant field is removed, so a subclass that reads it gets undefined. Read hasFocusedDescendant instead, and use FFIRenderLib.contextDrawSceneBody() instead of contextDrawSceneText(). See Custom renderables. (#1778)
  • native: OT_SCENE_RECORD_SCENE_TEXT is now OT_SCENE_RECORD_SCENE_BODY, and ot_buffer_draw_scene_text is now ot_buffer_draw_scene_body, with the same value and layout. The reserved field of ot_scene_stats is now damage_rows. See C. (#1778, #1783)
  • native: In the Zig module, a CliRenderer exists only as the renderer of a Session, and Context.drawSceneText and drawSceneTextOn are now drawSceneBody and drawSceneBodyOn. BufferedOutput and the standalone create, render, and setup calls are removed, so render through a Session. See Zig. (#1806, #1778)

Added

  • core: renderer.onAnimationTick(fps, callback, { tolerance }) runs callbacks on one shared animation clock, so animations at different rates share frames. Renderable.animationFps ticks the protected onAnimationTick() of a node while it is drawn, and a Timeline with a frameRate below targetFps ticks on the clock. See Animation and Timeline. (#1803)
  • react: useAnimationTick(fps, callback, options?) subscribes a component to the shared animation clock and commits state updates from the callback in the tick's frame. An undefined rate pauses it. See React bindings. (#1803)
  • solid: onAnimationTick(fps, callback, options?) subscribes a component to the shared animation clock, and fps can be an Accessor<number | undefined> that returns undefined to pause it. See Solid bindings. (#1803)
  • core: ScrollBoxRenderable.anchor(node) keeps a row at its place in the viewport through layout changes, and afterLayout(callback) runs once after the next frame's layout and before it paints. scrollChildIntoView() accepts a node, an align of "nearest", "start", or "end", and an inset. See ScrollBox. (#1811)
  • core: ScrollBoxRenderable.scrollX and scrollY read and update which axes scroll after construction. See ScrollBox. (#1805)
  • core: The test renderer option nativeSceneVerify, on by default, compares each frame that retained paint skips or repaints in part with a full repaint, and it throws on a mismatch. See Testing. (#1783)
  • core: Rex gets OSC 8 hyperlinks when its XTVERSION reply or TERM names rex or xterm-rex. See Terminal capabilities. (#1819)
  • native: A box can be a native scroll node. ot_scene_set_scroll, ot_scene_scroll_to, ot_scene_get_scroll, ot_scene_scroll_request, and ot_scene_set_scroll_arrow configure, scroll, and read it, and OT_SCENE_HOOK_SCROLL asks for an OT_SCENE_FRAME_SCROLL request when its state changes. See Frames and output. (#1798, #1811)
  • native: ot_scene_stats.damage_rows counts the rows that a frame diffs, and the new OT_SCENE_FULL_PATH_* bits give the reason for a full repaint. OT_SCENE_DEBUG_VERIFY compares retained frames with a full repaint. See Frames and output. (#1783, #1808)
  • native: OT_EDIT_POSITION_END and OT_EDIT_POSITION_PREV_CHAR, also NativeEditPositionQuery.End and PrevChar in Core, read the end of the text and the position that Left moves to. They do not move the cursor. See C. (#1848)
  • native: OT_INPUT_EXPECT_SENTINEL holds split terminal replies while the host waits for a DA1 reply. OT_TERMINAL_REPLY_SENTINEL, OT_TERMINAL_SYNC_ALWAYS, OT_TERMINAL_SYNC_NEVER, and OT_TERMINAL_HOST_MULTIPLEXER set the reply sentinel and the synchronized-output policy of a Session. See Host I/O and time. (#1793, #1816, #1851)

Changed

  • core: The new synchronizedOutput option defaults to "auto", which removes the synchronized-output wrapper in some remote sessions after the startup replies arrive. Set "always" for the old behavior, or "never" to never wrap a frame. See Renderer. (#1851)
  • core: The renderer applies capability replies whenever they arrive, and it emits capabilities and repaints only when the capabilities change. After startup, handlers added with addInputHandler no longer see these replies, and the theme mode follows each OSC 11 reply. See Terminal capabilities. (#1807)
  • core: With the native input parser, the renderer ends each batch of terminal queries with DA1 and holds split replies until the DA1 reply comes, so the focused input no longer gets reply text over a slow link. The startup window closes after one round trip instead of 5 s, and with both parsers a pixel-size query without a reply ends after 5 s. See Terminal capabilities. (#1816, #1793)
  • core: An unchanged scene frame paints nothing, and a frame with a small change clears and repaints only bands around its damaged rows, also when paint hooks draw it. An OpenCode frame at 160×48 does about 1,000 to 1,600 cell operations instead of about 28,000. See Rendering pipeline. (#1783, #1808, #1810, #1804, #1839, #1840)
  • core: Scenes with hooks or a ScrollBox keep their preparation across frames, and feedback visits only the nodes that can send a request or that changed. The order of update calls between nodes whose replies race is not specified. See Rendering pipeline. (#1802, #1809)
  • core: drawFrameBuffer() copies a source without respectAlpha at full opacity, also when the screen or the source holds a grapheme or a link, so transparent source cells show as holes. A transparent box border of space glyphs keeps the glyph below it in every case. See Buffer API. (#1810)
  • core: Siblings with the same zIndex paint in attachment order. A child whose zIndex changes and then goes back to its old value gets its original paint position back. See Renderables. (#1812)
  • core: A ScrollBox scrolls and follows new content in native code, so an append to a 1,000-row sticky ScrollBox sends no request to the host. A held scrollbar arrow repeats on the renderer's clock, so a custom Clock drives it. See ScrollBox. (#1805, #1814)
  • core: scrollTo() and scrollBy() scroll at once and again after the next frame's layout, so a scroll made in the same tick as a content change uses the new layout. scrollTo(scrollHeight) and scrollTo(Infinity) stay at the end after the content grows. See ScrollBox. (#1811)
  • core: Each row of a long wrapped line, or of a long highlighted line, finds its first cluster and its style span by binary search. The bottom 30 rows of a 131,072-column highlighted line take 480 steps instead of 1.9 million. See Code. (#1781, #1796)
  • core: Release builds allocate native memory through libc, which reuses freed memory. A Context with 200 streamed text buffers (7.7 MB live) holds about 11 MB instead of 105 MB. See Resources and ownership. (#1795)
  • solid: @opentui/solid and @opentui/keymap accept solid-js ^1.9.12 as a peer dependency instead of 1.9.12 alone. See Solid bindings. (#1786)

Fixed

  • core: A ScrollBox keeps its position when it and its content grow in the same frame, and vertical viewport padding no longer hides the last rows. The thumb is proportional to the viewport from the first frame, and scrollbar onChange options run. See ScrollBox. (#1805, #1798)
  • core: A host clipboard that read once no longer keeps an idle Wayland connection that collects unread offers. On Hyprland, those offers froze the desktop for up to 10 s or more when the process exited or the next paste read them. See Clipboard. (#1825)
  • core: The host clipboard tries Wayland again after an unsupported connection, and on WSL it also tries /mnt/wslg/runtime-dir/$WAYLAND_DISPLAY. On WSLg, a read that loses focus to another window maps a new helper surface, at most two times, instead of failing. See Clipboard. (#1845, #1849)
  • core: The Wayland clipboard works with libwayland-client 1.10 and later, not only 1.20 and later. On Ubuntu 20.04 and Debian 11, image paste no longer falls back to X11 without a message. See Clipboard. (#1846)
  • core: After the X server or XWayland restarts, the X11 clipboard connects again, so operations no longer fail until the app restarts. On WSL, a zero-byte X11 result ends the read as empty. See Clipboard. (#1844)
  • core: On Windows and macOS, a running clipboard operation settles at its deadline or on cancel. Before, a read with timeoutMs: 1000 that an unresponsive owner blocked took 17.3 s. See Clipboard. (#1847)
  • core: A change to syntaxStyle or fg of a MarkdownRenderable restyles list markers, and with internalBlockMode: "top-level" it also restyles list items and table cells. Before, they kept the old theme's colors. See Markdown. (#1841)
  • core: When a clip, the buffer edge, or a text view's edge cuts a wide glyph, each visible cell draws as a space in the glyph's style. Before, the cell showed what was behind the text, and at a view's left edge a cut wide glyph or tab shifted the rest of the line left. See Text and terminal cells. (#1838)
  • core: Under wcwidth, a cluster can span up to 16 cells, so ZWJ families of 6 or 8 cells no longer leave blanks or stale cells. A wider cluster draws as blank cells of its width, and OSC 66 explicit width is capped at 7 cells and padded with spaces. See Text and terminal cells. (#1779)
  • core: Streamed or edited text measures, wraps, draws, and deletes like the same text loaded in one piece, also when an append or edit splits a grapheme. After such an edit, the cursor goes after the joined grapheme and extmarks shift by the change in width. See Editing buffers and views. (#1782, #1848)
  • core: A box title is placed against the box's own edges, so a box at a negative x or past the right edge of the screen shows its title in the correct place. See Box. (#1797)
  • core: TimeToFirstDrawRenderable and LineNumberRenderable at a fractional position no longer fail the frame, and both draw correctly with buffered: true. See TimeToFirstDraw and Line number gutter. (#1826)
  • core: A subclass that calls super.renderSelf() on an ArrowRenderable at a fractional position no longer fails the frame, super.renderSelf() on a SliderRenderable matches native thumbs at negative fractional positions, and a buffered BoxRenderable, SliderRenderable, or ArrowRenderable draws at its own origin instead of shifted. See Custom renderables. (#1799, #1778)
  • core: With the native input parser, a UTF-8 character that a pause splits waits for its other bytes, and so does a mouse report cut after ESC [. Before, ✓ arrived as Alt keys and a wheel notch typed <64;87;26M. 8-bit Meta input now reads as UTF-8. See Keyboard input. (#1791, #1794)
  • solid: Conditional content that switches off and back on no longer leaves an empty text node in its place. See Solid bindings. (#1786)

Security

  • solid: @opentui/solid uses babel-preset-solid 1.9.16. Solid releases before 1.9.16 depend on Seroval versions with a critical advisory (GHSA-p6vx-979v-rg4c), so install solid-js 1.9.16 or later. See Solid bindings. (#1786)

API changes and documentation: https://opentui.com/docs/releases/0.8.0

What's Changed

  • native: skip unchanged scene frames and diff only damaged rows by @simonklee in #1783
  • native: allocate release Contexts through libc by @simonklee in #1795
  • solid: update Solid to resolve Seroval security warnings by @mihaellenic in #1786
  • native: search for the first render cluster of each wrapped row by @simonklee in #1781
  • native: let one cell span up to 16 cells for wide wcwidth clusters by @simonklee in #1779
  • native: wait for a mouse report after a timed-out ESC [ by @simonklee in https://github.com//pull/1794
  • native: keep a UTF-8 character that a pause splits by @simonklee in #1791
  • native: record a box's native body; drop the TS painter by @simonklee in #1778
  • native: scroll control with native offset, sticky edge and scrollbars by @simonklee in #1798
  • native: keep scene preparation across frames with hooks and viewports by @simonklee in #1802
  • core: share one animation clock between components by @simonklee in #1803
  • native: keep chunk boundaries on grapheme boundaries by @simonklee in #1782
  • native: hold split terminal replies while a DA1 sentinel is out by @simonklee in #1793
  • native: search for the style span of each drawn row by @simonklee in #1796
  • native: place a box title against the box, not its visible part by @simonklee in #1797
  • core: record slider and arrow native bodies by @simonklee in #1799
  • native: compare scene records while recording them by @simonklee in #1804
  • native: count a scroll node's fill rows in its paint record by @simonklee in #1813
  • native: delete the legacy terminal and output paths by @simonklee in #1806
  • core: apply terminal replies that arrive late by @simonklee in #1807
  • core: make ScrollBox a facade over the native scroll control by @simonklee in #1805
  • native: fingerprint paint-hook recordings and bound the rows they write by @simonklee in #1808
  • native: switch on a scene record command enum by @simonklee in #1817
  • native: run feedback only where a hook can request or something changed by @simonklee in #1809
  • core: schedule the ScrollBox arrow repeat on the renderer clock by @simonklee in #1814
  • core: end terminal reply waits at their DA1 reply by @simonklee in #1816
  • docs: name RenderContext.clock in the 0.5.14 migration list by @simonklee in #1818
  • native: clear and repaint only damaged row bands by @simonklee in #1810
  • native: paint equal-z siblings in attachment order by @simonklee in #1812
  • native: count arrow text rows in the paint record by @simonklee in #1815
  • native: pass every parent when feedback skips a clean root by @simonklee in #1820
  • ci: run Linux jobs on GitHub-hosted runners by @simonklee in #1821
  • native: resolve scroll requests and anchors after layout by @simonklee in #1811
  • ci: run Linux jobs on Blacksmith again by @simonklee in #1822
  • ci: add working Zig and Bun caches and Blacksmith checkout by @simonklee in #1823
  • docs: redraw the ScrollBox visuals with the native thumb by @simonklee in #1832
  • feat(native): detect Rex terminal hyperlink support by @manishprivet in #1819
  • core: assert both parsers in the lone UTF-8 lead byte test by @simonklee in #1827
  • core: truncate host paint positions in two controls by @simonklee in #1826
  • native: close the idle Wayland clipboard connection by @JosXa in #1825
  • ci: run input tests with the native input parser by @simonklee in #1830
  • core: pin the replay differential's input rows in parser tests by @simonklee in #1835
  • native: draw the visible cells of a wide glyph that an edge cuts by @simonklee in #1838
  • native: paint frames without hooks straight from the member list by @simonklee in #1839
  • native: skip the target read for non-space transparent borders by @simonklee in #1840
  • native: marshal Wayland requests without libwayland 1.20 by @simonklee in #1846
  • core: measure extmarks edits without moving the cursor by @simonklee in #1848
  • native: retry an unsupported Wayland clipboard connection by @simonklee in #1845
  • native: restart a WSLg clipboard read when focus leaves its helper by @simonklee in #1849
  • fix(core): restyle markdown lists on style changes in top-level block mode by @jlongster in #1841
  • native: reconnect the X11 clipboard after a connection failure by @simonklee in #1844
  • native: settle a running clipboard operation at its deadline by @simonklee in #1847
  • native: drop the sync envelope for remote terminals that pay for it by @simonklee in #1851

New Contributors

Full Changelog: v0.7.0...v0.8.0

Don't miss a new opentui release

NewReleases is sending notifications on new releases.