Skip to main content

Module cursor

Module cursor 

Source
Expand description

Cursor save/restore strategy for inline mode robustness.

This module implements a layered cursor save/restore strategy to handle the variety of terminal behaviors. Inline mode requires saving cursor position before drawing UI and restoring after.

§Strategy Layers

  1. DEC (preferred): ESC 7 / ESC 8 (DECSC/DECRC)

    • Most widely supported on modern terminals
    • Saves cursor position, attributes, and charset
    • Works in tmux/screen with passthrough
  2. ANSI (fallback): CSI s / CSI u

    • Alternative when DEC has issues
    • Only saves cursor position (not attributes)
    • May conflict with some terminal modes
  3. Emulated (last resort): Track position and use CSI row;col H

    • Works everywhere that supports CUP
    • Requires tracking cursor position throughout
    • More overhead but guaranteed to work

§Example

use ftui_core::cursor::{CursorManager, CursorSaveStrategy};
use ftui_core::terminal_capabilities::TerminalCapabilities;

let caps = TerminalCapabilities::detect();
let mut cursor = CursorManager::new(CursorSaveStrategy::detect(&caps));

// In your render loop:
let mut output = Vec::new();
cursor.save(&mut output, (10, 5))?;  // Save at column 10, row 5
// ... draw UI ...
cursor.restore(&mut output)?;

Structs§

CursorManager
Manages cursor save/restore operations.

Enums§

CursorSaveStrategy
Strategy for cursor save/restore operations.

Functions§

hide
Hide the cursor.
move_to
Move cursor to a specific position.
show
Show the cursor.