rush_sync_server/ui/
terminal.rs1use crate::core::constants::APP_TITLE;
2use crate::core::prelude::*;
3use crate::i18n::get_translation;
4use crossterm::{
5 cursor, execute,
6 style::ResetColor,
7 terminal::{
8 self, disable_raw_mode, enable_raw_mode, ClearType, EnterAlternateScreen,
9 LeaveAlternateScreen,
10 },
11};
12use std::io::Stdout;
13
14pub struct TerminalManager {
15 stdout: Stdout,
16}
17
18impl TerminalManager {
19 pub async fn new() -> Result<Self> {
20 let stdout = io::stdout();
21 Ok(Self { stdout })
22 }
23
24 pub async fn setup(&mut self) -> Result<()> {
25 enable_raw_mode()?;
26
27 execute!(
28 self.stdout,
29 terminal::Clear(ClearType::All),
30 EnterAlternateScreen,
31 terminal::DisableLineWrap,
32 terminal::SetTitle(APP_TITLE),
33 cursor::Hide
34 )?;
35 log::info!("{}", get_translation("terminal.setup.done", &[]));
36
37 Ok(())
38 }
39
40 pub async fn cleanup(&mut self) -> Result<()> {
41 disable_raw_mode()?;
43
44 execute!(
46 self.stdout,
47 terminal::Clear(ClearType::All), LeaveAlternateScreen,
49 terminal::EnableLineWrap,
50 cursor::Show,
51 ResetColor,
52 cursor::MoveTo(0, 0)
53 )?;
54
55 self.stdout.flush()?;
57
58 log::info!("{}", get_translation("terminal.cleanup.done", &[]));
59
60 Ok(())
61 }
62}