diff --git a/src/main.rs b/src/main.rs index 767ce60..2c3bfb1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,6 +20,7 @@ use crossterm::{ }; use event::Event; use greetd_ipc::Request; +use power::PowerPostAction; use tokio::sync::RwLock; use tui::{backend::CrosstermBackend, Terminal}; @@ -91,12 +92,21 @@ async fn run() -> Result<(), Box> { } Some(Event::PowerCommand(command)) => { - power::run(&greeter, command).await; + if let PowerPostAction::ClearScreen = power::run(&greeter, command).await { + execute!(io::stdout(), LeaveAlternateScreen)?; + terminal.set_cursor(1, 1)?; + terminal.clear()?; + disable_raw_mode()?; + + break; + } } _ => {} } } + + Ok(()) } async fn exit(greeter: &mut Greeter, status: AuthStatus) { diff --git a/src/power.rs b/src/power.rs index 58a7a95..e542c7b 100644 --- a/src/power.rs +++ b/src/power.rs @@ -60,7 +60,12 @@ pub async fn power(greeter: &mut Greeter, option: PowerOption) { } } -pub async fn run(greeter: &Arc>, mut command: Command) { +pub enum PowerPostAction { + Noop, + ClearScreen, +} + +pub async fn run(greeter: &Arc>, mut command: Command) -> PowerPostAction { greeter.write().await.mode = Mode::Processing; let message = match command.output().await { @@ -81,6 +86,12 @@ pub async fn run(greeter: &Arc>, mut command: Command) { let mut greeter = greeter.write().await; - greeter.mode = mode; - greeter.message = message; + if message.is_none() { + PowerPostAction::ClearScreen + } else { + greeter.mode = mode; + greeter.message = message; + + PowerPostAction::Noop + } }