uncurses/ansi/inband.rs
1//! In-band terminal resize reports for DEC private mode 2048.
2//!
3//! ## Category
4//!
5//! This module encodes a terminal-to-application resize notification as an
6//! XTWINOPS-shaped CSI `t` sequence carrying cell and pixel dimensions.
7//!
8//! ## CSI format
9//!
10//! The emitted format is `ESC [ 48 ; height_cells ; width_cells ; height_px ; width_px t`.
11//! Dimensions are decimal integers and are written exactly as provided.
12//!
13//! ## Mode interaction
14//!
15//! Applications request these reports by enabling
16//! [`Mode::IN_BAND_RESIZE`](crate::ansi::mode::Mode::IN_BAND_RESIZE), DEC private
17//! mode 2048. This module only encodes the report payload.
18
19use std::io::{self, Write};
20
21/// Encode an in-band resize report as `ESC [ 48 ; <height_cells> ; <width_cells> ; <height_pixels> ; <width_pixels> t`.
22///
23/// The report is intended for applications that enabled [`Mode::IN_BAND_RESIZE`](crate::ansi::mode::Mode::IN_BAND_RESIZE). All dimensions are emitted as decimal `u16` values.
24pub fn write_in_band_resize<W: Write>(
25 w: &mut W,
26 height_cells: u16,
27 width_cells: u16,
28 height_pixels: u16,
29 width_pixels: u16,
30) -> io::Result<()> {
31 write!(
32 w,
33 "\x1b[48;{height_cells};{width_cells};{height_pixels};{width_pixels}t",
34 )
35}
36
37#[cfg(test)]
38mod tests {
39 use super::*;
40
41 #[test]
42 fn test_in_band_resize() {
43 let mut buf = Vec::new();
44 write_in_band_resize(&mut buf, 24, 80, 480, 800).unwrap();
45 assert_eq!(buf, b"\x1b[48;24;80;480;800t");
46 }
47}