diff --git a/src/tty/mod.rs b/src/tty/mod.rs index d4bceb6c2..abc02ccec 100644 --- a/src/tty/mod.rs +++ b/src/tty/mod.rs @@ -1,5 +1,8 @@ //! This module implements and describes common TTY methods & traits +/// Unsupported Terminals that don't support RAW mode +const UNSUPPORTED_TERM: [&str; 3] = ["dumb", "cons25", "emacs"]; + use crate::config::{Behavior, BellStyle, ColorMode, Config}; use crate::highlight::Highlighter; use crate::keys::KeyEvent; @@ -200,6 +203,22 @@ pub trait Term { fn set_cursor_visibility(&mut self, visible: bool) -> Result>; } +/// Check TERM environment variable to see if current term is in our +/// unsupported list +fn is_unsupported_term() -> bool { + match std::env::var("TERM") { + Ok(term) => { + for iter in &UNSUPPORTED_TERM { + if (*iter).eq_ignore_ascii_case(&term) { + return true; + } + } + false + } + Err(_) => false, + } +} + // If on Windows platform import Windows TTY module // and re-export into mod.rs scope #[cfg(all(windows, not(target_arch = "wasm32")))] @@ -218,3 +237,15 @@ pub use self::unix::*; mod test; #[cfg(any(test, target_arch = "wasm32"))] pub use self::test::*; + +#[cfg(test)] +mod test_ { + #[test] + fn test_unsupported_term() { + std::env::set_var("TERM", "xterm"); + assert!(!super::is_unsupported_term()); + + std::env::set_var("TERM", "dumb"); + assert!(super::is_unsupported_term()); + } +} diff --git a/src/tty/unix.rs b/src/tty/unix.rs index 0ef853921..1c25bbb07 100644 --- a/src/tty/unix.rs +++ b/src/tty/unix.rs @@ -34,9 +34,6 @@ use crate::layout::{Layout, Position, Unit}; use crate::line_buffer::LineBuffer; use crate::{error, Cmd, ReadlineError, Result}; -/// Unsupported Terminals that don't support RAW mode -const UNSUPPORTED_TERM: [&str; 3] = ["dumb", "cons25", "emacs"]; - const BRACKETED_PASTE_ON: &str = "\x1b[?2004h"; const BRACKETED_PASTE_OFF: &str = "\x1b[?2004l"; @@ -70,22 +67,6 @@ fn get_win_size(fd: RawFd) -> (Unit, Unit) { } } -/// Check TERM environment variable to see if current term is in our -/// unsupported list -fn is_unsupported_term() -> bool { - match std::env::var("TERM") { - Ok(term) => { - for iter in &UNSUPPORTED_TERM { - if (*iter).eq_ignore_ascii_case(&term) { - return true; - } - } - false - } - Err(_) => false, - } -} - /// Return whether or not STDIN, STDOUT or STDERR is a TTY fn is_a_tty(fd: RawFd) -> bool { isatty(fd).unwrap_or(false) @@ -1357,7 +1338,7 @@ impl Term for PosixTerminal { false, ) }; - let unsupported = is_unsupported_term(); + let unsupported = super::is_unsupported_term(); let sigwinch = if !unsupported && is_in_a_tty && is_out_a_tty { Some(SigWinCh::install_sigwinch_handler()?) } else { @@ -1686,15 +1667,6 @@ mod test { assert_eq!(0, pos.row); } - #[test] - fn test_unsupported_term() { - std::env::set_var("TERM", "xterm"); - assert!(!super::is_unsupported_term()); - - std::env::set_var("TERM", "dumb"); - assert!(super::is_unsupported_term()); - } - #[test] fn test_send() { fn assert_send() {} diff --git a/src/tty/windows.rs b/src/tty/windows.rs index 1d843f8ef..dc714031e 100644 --- a/src/tty/windows.rs +++ b/src/tty/windows.rs @@ -718,9 +718,8 @@ impl Term for Console { }) } - /// Checking for an unsupported TERM in windows is a no-op fn is_unsupported(&self) -> bool { - false + super::is_unsupported_term() } fn is_input_tty(&self) -> bool {