mirror of
https://github.com/apognu/tuigreet.git
synced 2024-09-11 07:25:29 +03:00
Clear screen and reset cursor on power command.
This commit is contained in:
parent
71cf19e233
commit
7c1ddad35c
12
src/main.rs
12
src/main.rs
@ -20,6 +20,7 @@ use crossterm::{
|
||||
};
|
||||
use event::Event;
|
||||
use greetd_ipc::Request;
|
||||
use power::PowerPostAction;
|
||||
use tokio::sync::RwLock;
|
||||
use tracing_appender::non_blocking::WorkerGuard;
|
||||
use tui::{backend::CrosstermBackend, Terminal};
|
||||
@ -100,12 +101,21 @@ async fn run() -> Result<(), Box<dyn Error>> {
|
||||
}
|
||||
|
||||
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) {
|
||||
|
13
src/power.rs
13
src/power.rs
@ -60,7 +60,12 @@ pub async fn power(greeter: &mut Greeter, option: PowerOption) {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn run(greeter: &Arc<RwLock<Greeter>>, mut command: Command) {
|
||||
pub enum PowerPostAction {
|
||||
Noop,
|
||||
ClearScreen,
|
||||
}
|
||||
|
||||
pub async fn run(greeter: &Arc<RwLock<Greeter>>, mut command: Command) -> PowerPostAction {
|
||||
tracing::info!("executing power command: {:?}", command);
|
||||
|
||||
greeter.write().await.mode = Mode::Processing;
|
||||
@ -85,6 +90,12 @@ pub async fn run(greeter: &Arc<RwLock<Greeter>>, mut command: Command) {
|
||||
|
||||
let mut greeter = greeter.write().await;
|
||||
|
||||
if message.is_none() {
|
||||
PowerPostAction::ClearScreen
|
||||
} else {
|
||||
greeter.mode = mode;
|
||||
greeter.message = message;
|
||||
|
||||
PowerPostAction::Noop
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user