ElixirOpentui.ANSI (ElixirOpentui v0.2.0)

Copy Markdown View Source

ANSI escape sequence generation.

Converts Buffer cells and diffs into terminal escape sequences. Pure module — no side effects. All functions return iodata.

Summary

Functions

Begin synchronized update — terminal buffers output until end_sync_update.

Generate OSC 52 sequence to copy text to the system clipboard.

Default Kitty keyboard flags: disambiguate (1) + alternate keys (4) = 5.

Disable xterm modifyOtherKeys mode.

Enable xterm modifyOtherKeys mode 2 (fallback for non-Kitty terminals).

End synchronized update — terminal flushes buffered output.

Build a complete frame output: hide cursor, render, show cursor.

Move cursor to (x, y). 1-indexed for ANSI.

Pop Kitty keyboard flags from the terminal's stack.

Push Kitty keyboard flags onto the terminal's stack.

Query DECRQM for a private mode. Response: \e[?{mode};{status}$y

Query current Kitty keyboard flags. Terminal responds with \e[?{flags}u.

Render only the diff changes between two buffers.

Render an entire buffer to ANSI iodata (for initial draw or full redraw).

Set the Kitty keyboard flags for the current top-of-stack entry (no push/pop).

Generate SGR sequence from a cell map.

Functions

begin_sync_update()

@spec begin_sync_update() :: iodata()

Begin synchronized update — terminal buffers output until end_sync_update.

clear_line()

@spec clear_line() :: iodata()

clear_screen()

@spec clear_screen() :: iodata()

copy_to_clipboard(text, selection \\ "c")

@spec copy_to_clipboard(String.t(), String.t()) :: iodata()

Generate OSC 52 sequence to copy text to the system clipboard.

The terminal intercepts this sequence and copies the decoded text. Uses BEL (\a) terminator — more compatible than ST (\e\) which breaks in screen and older tmux versions.

default_kitty_flags()

@spec default_kitty_flags() :: non_neg_integer()

Default Kitty keyboard flags: disambiguate (1) + alternate keys (4) = 5.

disable_modify_other_keys()

@spec disable_modify_other_keys() :: iodata()

Disable xterm modifyOtherKeys mode.

disable_mouse()

@spec disable_mouse() :: iodata()

disable_paste()

@spec disable_paste() :: iodata()

enable_modify_other_keys()

@spec enable_modify_other_keys() :: iodata()

Enable xterm modifyOtherKeys mode 2 (fallback for non-Kitty terminals).

enable_mouse()

@spec enable_mouse() :: iodata()

enable_paste()

@spec enable_paste() :: iodata()

end_sync_update()

@spec end_sync_update() :: iodata()

End synchronized update — terminal flushes buffered output.

enter_alt_screen()

@spec enter_alt_screen() :: iodata()

frame(content)

@spec frame(iodata()) :: iodata()

Build a complete frame output: hide cursor, render, show cursor.

hide_cursor()

@spec hide_cursor() :: iodata()

leave_alt_screen()

@spec leave_alt_screen() :: iodata()

move_to(x, y)

@spec move_to(non_neg_integer(), non_neg_integer()) :: iodata()

Move cursor to (x, y). 1-indexed for ANSI.

pop_kitty_keyboard()

@spec pop_kitty_keyboard() :: iodata()

Pop Kitty keyboard flags from the terminal's stack.

push_kitty_keyboard(flags \\ default_kitty_flags())

@spec push_kitty_keyboard(non_neg_integer()) :: iodata()

Push Kitty keyboard flags onto the terminal's stack.

query_decrqm(mode)

@spec query_decrqm(non_neg_integer()) :: iodata()

Query DECRQM for a private mode. Response: \e[?{mode};{status}$y

query_kitty_keyboard()

@spec query_kitty_keyboard() :: iodata()

Query current Kitty keyboard flags. Terminal responds with \e[?{flags}u.

render_diff(changes)

@spec render_diff([
  {non_neg_integer(), non_neg_integer(), ElixirOpentui.Buffer.cell()}
]) :: iodata()

Render only the diff changes between two buffers.

render_full(buf)

@spec render_full(ElixirOpentui.Buffer.t()) :: iodata()

Render an entire buffer to ANSI iodata (for initial draw or full redraw).

reset()

@spec reset() :: iodata()

set_kitty_keyboard(flags)

@spec set_kitty_keyboard(non_neg_integer()) :: iodata()

Set the Kitty keyboard flags for the current top-of-stack entry (no push/pop).

\e[={flags}u replaces the current entry's flags directly. Sending set_kitty_keyboard(0) before pop_kitty_keyboard() ensures keyboard enhancements are disabled even if the pop doesn't take effect.

sgr(map)

@spec sgr(map()) :: iodata()

Generate SGR sequence from a cell map.

sgr(fg, bg, bold, italic, underline, strikethrough, dim \\ false, inverse \\ false, blink \\ false, hidden \\ false)

Generate SGR (Select Graphic Rendition) sequence for a cell's style.

show_cursor()

@spec show_cursor() :: iodata()