diff options
Diffstat (limited to 'crates/typst-cli/src/terminal.rs')
| -rw-r--r-- | crates/typst-cli/src/terminal.rs | 53 |
1 files changed, 1 insertions, 52 deletions
diff --git a/crates/typst-cli/src/terminal.rs b/crates/typst-cli/src/terminal.rs index da0eb9d7..cf2906eb 100644 --- a/crates/typst-cli/src/terminal.rs +++ b/crates/typst-cli/src/terminal.rs @@ -1,11 +1,8 @@ use std::io::{self, IsTerminal, Write}; -use std::sync::atomic::{AtomicBool, Ordering}; use codespan_reporting::term::termcolor; -use ecow::eco_format; use once_cell::sync::Lazy; use termcolor::{ColorChoice, WriteColor}; -use typst::diag::StrResult; use crate::ARGS; @@ -18,7 +15,6 @@ pub fn out() -> TermOut { /// The stuff that has to be shared between instances of [`TermOut`]. struct TermOutInner { stream: termcolor::StandardStream, - in_alternate_screen: AtomicBool, } impl TermOutInner { @@ -32,10 +28,7 @@ impl TermOutInner { }; let stream = termcolor::StandardStream::stderr(color_choice); - TermOutInner { - stream, - in_alternate_screen: AtomicBool::new(false), - } + TermOutInner { stream } } } @@ -48,24 +41,6 @@ pub struct TermOut { } impl TermOut { - /// Initialize a handler that listens for Ctrl-C signals. - /// This is used to exit the alternate screen that might have been opened. - pub fn init_exit_handler(&mut self) -> StrResult<()> { - // We can safely ignore the error as the only thing this handler would do - // is leave an alternate screen if none was opened; not very important. - let mut term_out = self.clone(); - ctrlc::set_handler(move || { - let _ = term_out.leave_alternate_screen(); - - // Exit with the exit code standard for Ctrl-C exits[^1]. - // There doesn't seem to be another standard exit code for Windows, - // so we just use the same one there. - // [^1]: https://tldp.org/LDP/abs/html/exitcodes.html - std::process::exit(128 + 2); - }) - .map_err(|err| eco_format!("failed to initialize exit handler ({err})")) - } - /// Clears the entire screen. pub fn clear_screen(&mut self) -> io::Result<()> { // We don't want to clear anything that is not a TTY. @@ -90,32 +65,6 @@ impl TermOut { } Ok(()) } - - /// Enters the alternate screen if none was opened already. - pub fn enter_alternate_screen(&mut self) -> io::Result<()> { - if self.inner.stream.supports_color() - && !self.inner.in_alternate_screen.load(Ordering::Acquire) - { - let mut stream = self.inner.stream.lock(); - write!(stream, "\x1B[?1049h")?; - stream.flush()?; - self.inner.in_alternate_screen.store(true, Ordering::Release); - } - Ok(()) - } - - /// Leaves the alternate screen if it is already open. - pub fn leave_alternate_screen(&mut self) -> io::Result<()> { - if self.inner.stream.supports_color() - && self.inner.in_alternate_screen.load(Ordering::Acquire) - { - let mut stream = self.inner.stream.lock(); - write!(stream, "\x1B[?1049l")?; - stream.flush()?; - self.inner.in_alternate_screen.store(false, Ordering::Release); - } - Ok(()) - } } impl Write for TermOut { |
