Skip to content

Commit 2cfff5a

Browse files
committed
feat: disable prograss bar if terminal is serial port
1 parent 1774062 commit 2cfff5a

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/main.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ use crate::config::Config;
5555
use crate::error::Chain;
5656
use crate::install_progress::osc94_progress;
5757
use crate::subcommand::*;
58+
use crate::utils::is_not_normal_terminal;
5859

5960
static NOT_DISPLAY_ABORT: AtomicBool = AtomicBool::new(false);
6061
static LOCKED: AtomicBool = AtomicBool::new(false);
@@ -432,8 +433,11 @@ fn try_main(
432433
) -> Result<i32, OutputError> {
433434
init_color_formatter(&oma, &config);
434435

435-
let no_progress =
436-
oma.global.no_progress || !is_terminal() || oma.global.debug || oma.global.dry_run;
436+
let no_progress = oma.global.no_progress
437+
|| !is_terminal()
438+
|| oma.global.debug
439+
|| oma.global.dry_run
440+
|| is_not_normal_terminal();
437441

438442
let code = match oma.subcmd {
439443
Some(subcmd) => subcmd.execute(&config, no_progress),

src/utils.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,32 @@ pub fn is_ssh_from_loginctl() -> bool {
295295
false
296296
}
297297

298+
pub fn is_not_normal_terminal() -> bool {
299+
let p = match std::fs::read_link("/proc/self/fd/0") {
300+
Ok(p) => p,
301+
Err(e) => {
302+
debug!("Failed to read symlink /proc/self/fd/0: {e}");
303+
return true;
304+
}
305+
};
306+
307+
debug!("tty device is: {}", p.display());
308+
309+
let p = p.to_string_lossy();
310+
311+
if p.starts_with("/dev/pts") {
312+
debug!("tty device is pts");
313+
return false;
314+
} else if let Some(suffix) = p.strip_prefix("/dev/tty")
315+
&& suffix.chars().next().is_some_and(|c| c.is_ascii_digit())
316+
{
317+
debug!("tty device is pure tty");
318+
return false;
319+
}
320+
321+
true
322+
}
323+
298324
/// oma display normal message
299325
#[macro_export]
300326
macro_rules! msg {

0 commit comments

Comments
 (0)