diff --git a/CHANGELOG.md b/CHANGELOG.md index c068f8c45..07af60137 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [Unreleased](https://github.com/dalance/procs/compare/v0.11.6...Unreleased) - ReleaseDate +* [Fixed] crash at piped/redirected [#146](https://github.com/dalance/procs/issues/146) * [Added] elapsed time [#120](https://github.com/dalance/procs/issues/120) * [Added] completion file message [#130](https://github.com/dalance/procs/issues/130) diff --git a/src/util.rs b/src/util.rs index 6b766f8fd..592439897 100644 --- a/src/util.rs +++ b/src/util.rs @@ -249,14 +249,19 @@ pub fn get_theme(opt: &Opt, config: &Config) -> ConfigTheme { }; match theme { ConfigTheme::Auto => { - let timeout = Duration::from_millis(100); - if let Ok(theme) = termbg::theme(timeout) { - match theme { - termbg::Theme::Dark => ConfigTheme::Dark, - termbg::Theme::Light => ConfigTheme::Light, + if console::user_attended() { + let timeout = Duration::from_millis(100); + if let Ok(theme) = termbg::theme(timeout) { + match theme { + termbg::Theme::Dark => ConfigTheme::Dark, + termbg::Theme::Light => ConfigTheme::Light, + } + } else { + // If termbg failed, fallback to dark theme + ConfigTheme::Dark } } else { - // If termbg failed, fallback to dark theme + // If piped or redirected, fallback to dark theme ConfigTheme::Dark } }