Skip to content

Commit 66c54d1

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

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,28 @@ pub fn is_ssh_from_loginctl() -> bool {
295295
false
296296
}
297297

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

0 commit comments

Comments
 (0)