Skip to content

Commit

Permalink
Add check for latency detection failure #288
Browse files Browse the repository at this point in the history
  • Loading branch information
dalance committed Mar 2, 2023
1 parent 6a43ea2 commit 8e328ed
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ libc = "0.2"
once_cell = "1.17.1"
serde = "1.0"
serde_derive = "1.0"
termbg = "0.4.1"
termbg = "0.4.3"
toml = "0.7"
unicode-width = "0.1"

Expand Down
5 changes: 3 additions & 2 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,15 @@ pub fn get_theme(opt: &Opt, config: &Config) -> ConfigTheme {
ConfigTheme::Auto => {
if atty::is(Stream::Stdout) && atty::is(Stream::Stderr) && atty::is(Stream::Stdin) {
let minimum_timeout = Duration::from_millis(100);
let timeout = if let Ok(latency) = termbg::latency(Duration::from_millis(10000)) {
let timeout = if let Ok(latency) = termbg::latency(Duration::from_millis(1000)) {
if latency * 2 > minimum_timeout {
latency * 2
} else {
minimum_timeout
}
} else {
minimum_timeout
// If latency detection failed, fallback to dark theme
return ConfigTheme::Dark;
};

if let Ok(theme) = termbg::theme(timeout) {
Expand Down

0 comments on commit 8e328ed

Please sign in to comment.