| 1 | use std::io::{self, Write as _}; |
| 2 | |
| 3 | use termina::{ |
| 4 | escape::{ |
| 5 | csi::{self, Csi}, |
| 6 | osc::{DynamicColorNumber, Osc}, |
| 7 | }, |
| 8 | style::RgbColor, |
| 9 | PlatformTerminal, Terminal as _, |
| 10 | }; |
| 11 | |
| 12 | fn main() -> io::Result<()> { |
| 13 | let mut terminal = PlatformTerminal::new()?; |
| 14 | terminal.enter_raw_mode()?; |
| 15 | |
| 16 | write!( |
| 17 | terminal, |
| 18 | "{}{}{}{}Check the green background/blue foreground of your terminal. Press any key to exit.", |
| 19 | Csi::Mode(csi::Mode::SetDecPrivateMode(csi::DecPrivateMode::Code( |
| 20 | csi::DecPrivateModeCode::ClearAndEnableAlternateScreen |
| 21 | ))), |
| 22 | Osc::ChangeDynamicColors(DynamicColorNumber::TextForegroundColor, vec![RgbColor::new(128, 128, 255).into()]), |
| 23 | Osc::ChangeDynamicColors(DynamicColorNumber::TextBackgroundColor, vec![RgbColor::new(0, 64, 0).into()]), |
| 24 | Csi::Cursor(csi::Cursor::default_position()), |
| 25 | )?; |
| 26 | terminal.flush()?; |
| 27 | let _ = terminal.read(|event| matches!(event, termina::Event::Key(_))); |
| 28 | |
| 29 | write!( |
| 30 | terminal, |
| 31 | "{}{}{}", |
| 32 | Csi::Mode(csi::Mode::ResetDecPrivateMode(csi::DecPrivateMode::Code( |
| 33 | csi::DecPrivateModeCode::ClearAndEnableAlternateScreen, |
| 34 | ))), |
| 35 | Osc::ResetDynamicColor(DynamicColorNumber::TextForegroundColor), |
| 36 | Osc::ResetDynamicColor(DynamicColorNumber::TextBackgroundColor), |
| 37 | )?; |
| 38 | |
| 39 | Ok(()) |
| 40 | } |