Debian Codegraph @

Xtermina/examples/window-title.rs

raw symbols SCIP
1 use std::io::{self, Write as _};
2
3 use termina::{
4 escape::{
5 csi::{self, Csi},
6 osc::Osc,
7 },
8 PlatformTerminal, Terminal as _,
9 };
10
11 fn main() -> io::Result<()> {
12 let mut terminal = PlatformTerminal::new()?;
13 terminal.enter_raw_mode()?;
14
15 write!(
16 terminal,
17 "{}{}{}{}Check the window/tab title of your terminal. Press any key to exit. ",
18 Csi::Mode(csi::Mode::SetDecPrivateMode(csi::DecPrivateMode::Code(
19 csi::DecPrivateModeCode::ClearAndEnableAlternateScreen
20 ))),
21 // Save the current title to the terminal's stack.
22 Csi::Window(Box::new(csi::Window::PushIconAndWindowTitle)),
23 Osc::SetIconNameAndWindowTitle("Hello, world! - termina"),
24 Csi::Cursor(csi::Cursor::Position {
25 line: Default::default(),
26 col: Default::default(),
27 }),
28 )?;
29 terminal.flush()?;
30 let _ = terminal.read(|event| matches!(event, termina::Event::Key(_)));
31
32 write!(
33 terminal,
34 "{}{}",
35 // Restore the title from the terminal's stack.
36 Csi::Window(Box::new(csi::Window::PopIconAndWindowTitle)),
37 Csi::Mode(csi::Mode::ResetDecPrivateMode(csi::DecPrivateMode::Code(
38 csi::DecPrivateModeCode::ClearAndEnableAlternateScreen,
39 ))),
40 )?;
41
42 Ok(())
43 }