uncurses/ansi/title.rs
1//! Window title and icon-name OSC sequences.
2//!
3//! ## Category
4//!
5//! OSC 0, OSC 1, and OSC 2 update the terminal window title and/or icon name.
6//!
7//! ## OSC framing
8//!
9//! Writers use the 7-bit OSC introducer and `ST` terminator (`ESC \\`):
10//! `ESC ] <code> ; <text> ESC \\`.
11//!
12//! ## Mode interaction
13//!
14//! Title controls are not gated by an ANSI/DEC mode. The payload is emitted
15//! verbatim, so callers should avoid embedding string terminators in the text.
16
17use std::io::{self, Write};
18
19/// Set the window title and icon name with `ESC ] 0 ; <title> ESC \`.
20///
21/// OSC 0 sets both the icon name and the window title. `title` is emitted
22/// verbatim and the sequence uses `ST` (`ESC \`) termination.
23pub fn write_window_title_and_icon<W: Write>(w: &mut W, title: &str) -> io::Result<()> {
24 write!(w, "\x1b]0;{title}\x1b\\")
25}
26
27/// Set the icon name with `ESC ] 1 ; <name> ESC \`.
28///
29/// `name` is emitted verbatim and the sequence uses `ST` (`ESC \`) termination.
30pub fn write_icon_name<W: Write>(w: &mut W, name: &str) -> io::Result<()> {
31 write!(w, "\x1b]1;{name}\x1b\\")
32}
33
34/// Set window title (OSC 2).
35pub fn write_window_title<W: Write>(w: &mut W, title: &str) -> io::Result<()> {
36 write!(w, "\x1b]2;{title}\x1b\\")
37}