patch_to_ansi: Convert a screen patch to ANSI escape sequences

View source: R/renderer.R

patch_to_ansiR Documentation

Convert a screen patch to ANSI escape sequences

Description

Each run becomes a cursor movement followed by the run's characters. An SGR (style) sequence is emitted only when the style differs from the previous cell. The output always ends with a style reset.

Usage

patch_to_ansi(patch, color_mode = "truecolor")

Arguments

patch

A patch from diff_screen().

color_mode

One of "truecolor", "256", "16" or "none".

Value

A single string.

Examples

a <- screen_buffer(10, 1)
b <- a$copy()
b$put_text(1, 1, "hi", fg = "red")
patch_to_ansi(diff_screen(a, b))

termr documentation built on Oct. 21, 2026, 5:13 p.m.