Skip to content

Commit

Permalink
fix: try to fix terminal nothing after oma history exit
Browse files Browse the repository at this point in the history
  • Loading branch information
eatradish committed May 7, 2024
1 parent 335435f commit 991289f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::ffi::CString;
use std::io;
use std::io::{self, stdout, Write};
use std::path::PathBuf;

use std::process::{exit, Command};
Expand All @@ -18,6 +18,7 @@ mod egg;
use anyhow::anyhow;

use clap::ArgMatches;
use crossterm::terminal::disable_raw_mode;
use error::OutputError;
use oma_console::writer::{writeln_inner, MessageType, Writer};
use oma_console::WRITER;
Expand Down Expand Up @@ -544,6 +545,12 @@ async fn find_another_oma_inner() -> Result<(), OutputError> {
Ok(())
}

#[macro_export]
#[doc(hidden)]
macro_rules! csi {
($( $l:expr ),*) => { concat!("\x1B[", $( $l ),*) };
}

fn single_handler() {
// Kill subprocess
let subprocess_pid = SUBPROCESS.load(Ordering::Relaxed);
Expand All @@ -559,6 +566,12 @@ fn single_handler() {
unlock_oma().expect("Failed to unlock instance.");
}

// 该终端安全退出方法来自 ratatui `restore_terminal`
disable_raw_mode().ok();
let mut f = stdout();
f.write_all(csi!("?1049l").as_bytes()).ok();
f.flush().ok();

// Show cursor before exiting.
// This is not a big deal so we won't panic on this.
let _ = WRITER.show_cursor();
Expand Down
1 change: 0 additions & 1 deletion src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ fn review_msg<W: Write>(printer: &mut PagerPrinter<W>, pager_name: Option<&str>)

printer.print("").ok();
printer.print(format!("{}\n", fl!("review-msg"))).ok();
// let _ = writeln!(out, "{}\n", fl!("review-msg"));
printer
.print(format!(
"{}\n",
Expand Down

0 comments on commit 991289f

Please sign in to comment.