Skip to content

Commit 9bfbab6

Browse files
committed
refactor: inline is_a_dumb_terminal in is_dumb
1 parent 854c535 commit 9bfbab6

4 files changed

Lines changed: 15 additions & 26 deletions

File tree

src/term.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use alloc::sync::Arc;
22
use core::fmt::{Debug, Display};
3+
use std::env;
34
use std::io::{self, Read, Write};
45
#[cfg(any(unix, all(target_os = "wasi", target_env = "p1")))]
56
use std::os::fd::{AsRawFd, RawFd};
@@ -576,7 +577,16 @@ impl Term {
576577
/// Native windows terminals typically do not set the `TERM` environment variable.
577578
#[inline]
578579
pub fn is_dumb() -> bool {
579-
is_a_dumb_terminal()
580+
#[cfg(unix)]
581+
let default = true;
582+
583+
#[cfg(not(unix))]
584+
let default = false;
585+
586+
match env::var("TERM") {
587+
Ok(term) => term == "dumb",
588+
Err(_) => default,
589+
}
580590
}
581591

582592
/// A fast way to check if the application has a user attended for stdout.

src/unix_term.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::os::fd::{AsRawFd, RawFd};
99
#[cfg(not(target_os = "macos"))]
1010
use std::sync::OnceLock;
1111

12+
use crate::is_dumb;
1213
use crate::kb::Key;
1314
use crate::term::Term;
1415

@@ -21,13 +22,6 @@ pub(crate) fn is_a_terminal(out: &impl AsRawFd) -> bool {
2122
unsafe { libc::isatty(out.as_raw_fd()) != 0 }
2223
}
2324

24-
pub(crate) fn is_a_dumb_terminal() -> bool {
25-
match env::var("TERM") {
26-
Ok(term) => term == "dumb",
27-
Err(_) => true,
28-
}
29-
}
30-
3125
pub(crate) fn is_a_color_terminal(out: &Term) -> bool {
3226
if !is_a_terminal(out) {
3327
return false;
@@ -37,7 +31,7 @@ pub(crate) fn is_a_color_terminal(out: &Term) -> bool {
3731
return false;
3832
}
3933

40-
!is_a_dumb_terminal()
34+
!is_dumb()
4135
}
4236

4337
pub(crate) fn is_a_true_color_terminal(out: &Term) -> bool {

src/wasm_term.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ pub(crate) fn is_a_terminal(_out: &Term) -> bool {
2121
}
2222
}
2323

24-
#[inline]
25-
pub(crate) fn is_a_dumb_terminal() -> bool {
26-
false
27-
}
28-
2924
#[inline]
3025
pub(crate) fn is_a_color_terminal(_out: &Term) -> bool {
3126
// We currently never report color terminals. For discussion see

src/windows_term/mod.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ use windows_sys::Win32::System::Console::{
2424
};
2525
use windows_sys::Win32::UI::Input::KeyboardAndMouse::VIRTUAL_KEY;
2626

27-
use crate::common_term;
2827
use crate::kb::Key;
2928
use crate::term::{Term, TermTarget};
29+
use crate::{common_term, is_dumb};
3030

3131
#[cfg(feature = "windows-console-colors")]
3232
mod colors;
@@ -59,16 +59,6 @@ pub(crate) fn is_a_terminal(out: &Term) -> bool {
5959
msys_tty_on(out)
6060
}
6161

62-
pub(crate) fn is_a_dumb_terminal() -> bool {
63-
// Native windows terminals typically do not set the TERM.
64-
// We can only assume that if it is explicitly set to `dumb` then it is a dumb terminal.
65-
// Otherwise, we assume it is not.
66-
match env::var("TERM") {
67-
Ok(term) => term == "dumb",
68-
Err(_) => false,
69-
}
70-
}
71-
7262
pub(crate) fn is_a_color_terminal(out: &Term) -> bool {
7363
if !is_a_terminal(out) {
7464
return false;
@@ -77,7 +67,7 @@ pub(crate) fn is_a_color_terminal(out: &Term) -> bool {
7767
return false;
7868
}
7969
if msys_tty_on(out) {
80-
return !is_a_dumb_terminal();
70+
return !is_dumb();
8171
}
8272
enable_ansi_on(out)
8373
}

0 commit comments

Comments
 (0)