secrets: polish key manager and docs

This commit is contained in:
2026-06-01 07:19:28 +09:00
parent cc2c9a2973
commit 7ddf74570a
2 changed files with 33 additions and 7 deletions
+31 -3
View File
@@ -239,16 +239,44 @@ pub async fn launch() -> ExitCode {
type UiResult<T> = Result<T, Box<dyn std::error::Error>>;
struct TerminalRestoreGuard {
active: bool,
}
impl TerminalRestoreGuard {
fn new() -> Self {
Self { active: true }
}
fn restore(mut self) {
self.cleanup();
self.active = false;
}
fn cleanup(&mut self) {
let _ = execute!(io::stdout(), crossterm::cursor::Show, LeaveAlternateScreen);
let _ = disable_raw_mode();
}
}
impl Drop for TerminalRestoreGuard {
fn drop(&mut self) {
if self.active {
self.cleanup();
}
}
}
fn run(store: SecretStore) -> UiResult<()> {
enable_raw_mode()?;
let guard = TerminalRestoreGuard::new();
let mut stdout = io::stdout();
execute!(stdout, EnterAlternateScreen, crossterm::cursor::Hide)?;
let backend = CrosstermBackend::new(stdout);
let mut terminal = Terminal::new(backend)?;
let result = run_loop(&mut terminal, store);
let mut stdout = io::stdout();
let _ = execute!(stdout, crossterm::cursor::Show, LeaveAlternateScreen);
let _ = disable_raw_mode();
drop(terminal);
guard.restore();
result
}