OpenTUI 0.9.1
createCliRenderer() returns before the terminal answers its startup queries, and an answer can change the width method. Up to 0.9.0, text created before that answer kept the startup guess. In tmux inside GNU Screen over ssh, a textarea put its cursor at cell 4 after 👍🏽 while the terminal drew the emoji in 2 cells, and selections and colors could land on other text.
In 0.9.1, a renderer whose width method changes measures the text in its scene again: Text, Code, Input, Textarea, TextTable, and Markdown tables. Cursors, selections, marks, colors, and undo points stay on their text. Applications that use these renderables need no changes.
A TextBuffer or EditBuffer that you create yourself keeps its width method. Pass true as the new third argument of create() to make it follow the renderer that shows it. Only one renderer at a time can show such a buffer. For a buffer that you draw outside a scene, call setWidthMethod() when the capabilities change:
import { CliRenderEvents, TextBuffer, createCliRenderer } from "@opentui/core"
const renderer = await createCliRenderer()
const widthMethod = renderer.capabilities?.unicode ?? "unicode"
const shown = TextBuffer.create(widthMethod, renderer.nativeScene, true)
const offscreen = TextBuffer.create(widthMethod, renderer.nativeScene)
renderer.on(CliRenderEvents.CAPABILITIES, (capabilities) => {
if (capabilities) offscreen.setWidthMethod(capabilities.unicode)
})
Breaking changes
- native: The
reservedfield ofot_edit_buffer_optionsis nowflags. C code that names the field must rename it; code that zeroes the struct compiles unchanged. See C. (#2148)
Added
- core:
TextBuffer.create()andEditBuffer.create()take an optionalfollowSessionWidthargument. A second renderer that shows a following buffer throws aNativeErrorwithNativeStatus.WrongSession. See Editing buffers and views. (#2148) - core:
TextBuffer.setWidthMethod()changes the width method of a buffer that you draw outside a scene, andTextBufferView.setSelectionColors()recolors the current selection without moving it. See Editing buffers and views. (#2148, #2149) - native: The C side of the same features: the
OT_EDIT_BUFFER_FOLLOW_SESSION_WIDTHflag,ot_text_buffer_set_width_method, and theOT_SCENE_TEXT_SELECTION_COLORSoperation. See C. (#2148, #2149) - native:
link.execan linkopentui-static.libinto Windows MSVC executables, which also needntdll,user32,bcrypt, andlegacy_stdio_definitions. See C. (#2140)
Changed
- native: The release archives and npm packages also ship
LICENSE-ZIG,LICENSE-LLVM,LICENSE-MINGW-W64,LICENSE-GDTOA, andLICENSE-YOGA. See C. (#2140)
Fixed
- core: Text, Code, Input, Textarea,
TextTable, and Markdown tables created before the terminal replies now measure with the width method from the replies. See Text and terminal cells. (#2148, #2149) - native: In an auto-detected remote session,
TMUXor aTERMthat starts withtmuxholds back the startup Kitty graphics query, which tmux showed as the pane title. See Terminal capabilities. (#2143)
API changes#
@opentui/core#
Added
method FFIRenderLib.contextTextBufferSetWidthMethod(context: NativeContextHandle, text: ContextTextBufferHandle, widthMethod: WidthMethod): voidprotected method Renderable.setBuiltinLifecyclePass(pass: (() => void) | null): voidmethod TextBuffer.setWidthMethod(widthMethod: WidthMethod): voidmethod TextBufferView.setSelectionColors(bgColor?: RGBA, fgColor?: RGBA): voidproperty NativeContextEditBufferOptions.followSessionWidth?: boolean
Changed
static method EditBuffer.create(widthMethod: WidthMethod, source: NativeResourceOwner): EditBufferstatic method EditBuffer.create(widthMethod: WidthMethod, source: NativeResourceOwner, followSessionWidth?: boolean): EditBufferstatic method TextBuffer.create(widthMethod: WidthMethod, source: NativeResourceOwner): TextBufferstatic method TextBuffer.create(widthMethod: WidthMethod, source: NativeResourceOwner, followSessionWidth?: boolean): TextBufferproperty NativeSceneTextSelectionOptions.operation: "reset" | "set" | "update"property NativeSceneTextSelectionOptions.operation: "reset" | "set" | "update" | "colors"
opentui.h#
Added
const OT_EDIT_BUFFER_FOLLOW_SESSION_WIDTH = 1const OT_SCENE_TEXT_SELECTION_COLORS = 3field ot_edit_buffer_options.flags: uint32_t, offset 12function ot_text_buffer_set_width_method(ot_context *, const ot_handle *, uint32_t width_method): ot_status
Removed
field ot_edit_buffer_options.reserved: uint32_t, offset 12