These docs describe the main branch, including unreleased changes. Read the 0.9.1 docs.

OpenTUI 0.9.1

npmGitHub release

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 reserved field of ot_edit_buffer_options is now flags. C code that names the field must rename it; code that zeroes the struct compiles unchanged. See C. (#2148)

Added

  • core: TextBuffer.create() and EditBuffer.create() take an optional followSessionWidth argument. A second renderer that shows a following buffer throws a NativeError with NativeStatus.WrongSession. See Editing buffers and views. (#2148)
  • core: TextBuffer.setWidthMethod() changes the width method of a buffer that you draw outside a scene, and TextBufferView.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_WIDTH flag, ot_text_buffer_set_width_method, and the OT_SCENE_TEXT_SELECTION_COLORS operation. See C. (#2148, #2149)
  • native: link.exe can link opentui-static.lib into Windows MSVC executables, which also need ntdll, user32, bcrypt, and legacy_stdio_definitions. See C. (#2140)

Changed

  • native: The release archives and npm packages also ship LICENSE-ZIG, LICENSE-LLVM, LICENSE-MINGW-W64, LICENSE-GDTOA, and LICENSE-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, TMUX or a TERM that starts with tmux holds 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): void
  • protected method Renderable.setBuiltinLifecyclePass(pass: (() => void) | null): void
  • method TextBuffer.setWidthMethod(widthMethod: WidthMethod): void
  • method TextBufferView.setSelectionColors(bgColor?: RGBA, fgColor?: RGBA): void
  • property NativeContextEditBufferOptions.followSessionWidth?: boolean

Changed

  • static method EditBuffer.create(widthMethod: WidthMethod, source: NativeResourceOwner): EditBufferstatic method EditBuffer.create(widthMethod: WidthMethod, source: NativeResourceOwner, followSessionWidth?: boolean): EditBuffer
  • static method TextBuffer.create(widthMethod: WidthMethod, source: NativeResourceOwner): TextBufferstatic method TextBuffer.create(widthMethod: WidthMethod, source: NativeResourceOwner, followSessionWidth?: boolean): TextBuffer
  • property NativeSceneTextSelectionOptions.operation: "reset" | "set" | "update"property NativeSceneTextSelectionOptions.operation: "reset" | "set" | "update" | "colors"

opentui.h#

Added

  • const OT_EDIT_BUFFER_FOLLOW_SESSION_WIDTH = 1
  • const OT_SCENE_TEXT_SELECTION_COLORS = 3
  • field ot_edit_buffer_options.flags: uint32_t, offset 12
  • function 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