Skip to main content

Module terminal_writer

Module terminal_writer 

Source
Expand description

Terminal output coordinator with inline mode support.

The TerminalWriter is the component that makes inline mode work. It:

  • Serializes log writes and UI presents (one-writer rule)
  • Implements the cursor save/restore contract
  • Manages scroll regions (when optimization enabled)
  • Ensures single buffered write per operation

§Screen Modes

  • Inline Mode: Preserves terminal scrollback. UI is rendered at the bottom, logs scroll normally above. Uses cursor save/restore.

  • AltScreen Mode: Uses alternate screen buffer. Full-screen UI, no scrollback preservation.

§Inline Mode Contract

  1. Cursor is saved before any UI operation
  2. UI region is cleared and redrawn
  3. Cursor is restored after UI operation
  4. Log writes go above the UI region
  5. Terminal state is restored on drop

§Usage

use ftui_runtime::{TerminalWriter, ScreenMode, UiAnchor};
use ftui_render::buffer::Buffer;
use ftui_core::terminal_capabilities::TerminalCapabilities;

// Create writer for inline mode with 10-row UI
let mut writer = TerminalWriter::new(
    std::io::stdout(),
    ScreenMode::Inline { ui_height: 10 },
    UiAnchor::Bottom,
    TerminalCapabilities::detect(),
);

// Write logs (goes to scrollback above UI)
writer.write_log("Starting...\n")?;

// Present UI
let buffer = Buffer::new(80, 10);
writer.present_ui(&buffer, None, true)?;

Structs§

PresentTimings
RuntimeDiffConfig
Runtime-level configuration for diff strategy selection.
TerminalWriter
Unified terminal output coordinator.

Enums§

ScreenMode
Screen mode determines whether we use alternate screen or inline mode.
UiAnchor
Where the UI region is anchored in inline mode.

Functions§

inline_active_widgets
Read the current number of active inline-mode terminal writers.