diff --git a/Cargo.lock b/Cargo.lock index be1a1fc89..b4b861c43 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2958,6 +2958,7 @@ dependencies = [ "log", "num", "ordered-float", + "palette", "pretty_assertions", "serde", "serde_derive", diff --git a/src/server/tab/clienttab.rs b/src/server/tab/clienttab.rs index ddaf99fad..890ba76fd 100644 --- a/src/server/tab/clienttab.rs +++ b/src/server/tab/clienttab.rs @@ -252,20 +252,31 @@ impl Tab for ClientTab { } fn palette(&self) -> ColorPalette { - let config = configuration(); + let tardy = self.renderable.borrow().inner.borrow().is_tardy(); - if let Some(scheme_name) = config.color_scheme.as_ref() { - if let Some(palette) = config.color_schemes.get(scheme_name) { - return palette.clone().into(); + let palette = || { + let config = configuration(); + + if let Some(scheme_name) = config.color_scheme.as_ref() { + if let Some(palette) = config.color_schemes.get(scheme_name) { + return palette.clone().into(); + } } - } - config - .colors - .as_ref() - .cloned() - .map(Into::into) - .unwrap_or_else(ColorPalette::default) + config + .colors + .as_ref() + .cloned() + .map(Into::into) + .unwrap_or_else(ColorPalette::default) + }; + + let palette = palette(); + if tardy { + palette.grey_out() + } else { + palette + } } fn domain_id(&self) -> DomainId { diff --git a/src/server/tab/renderable.rs b/src/server/tab/renderable.rs index 23952b4a4..2f6367fee 100644 --- a/src/server/tab/renderable.rs +++ b/src/server/tab/renderable.rs @@ -118,7 +118,7 @@ impl RenderableInner { /// indicator. If we're past our poll interval and more recently /// tried to send something than receive something, the UI is worth /// showing. - fn is_tardy(&self) -> bool { + pub fn is_tardy(&self) -> bool { let elapsed = self.last_recv_time.elapsed(); if elapsed > self.poll_interval.max(Duration::from_secs(3)) { self.last_send_time > self.last_recv_time diff --git a/term/Cargo.toml b/term/Cargo.toml index c9c729073..cc0e58f66 100644 --- a/term/Cargo.toml +++ b/term/Cargo.toml @@ -11,6 +11,7 @@ image = "0.21" log = "0.4" num = "0.2" ordered-float = "1.0" +palette = "0.5" unicode-segmentation = "1.5" unicode-width = "0.1" serde = {version="1.0", features = ["rc"]} diff --git a/term/src/color.rs b/term/src/color.rs index 9ddc78f30..fe6cbdfb2 100644 --- a/term/src/color.rs +++ b/term/src/color.rs @@ -7,6 +7,16 @@ pub use termwiz::color::{AnsiColor, ColorAttribute, RgbColor, RgbaTuple}; #[derive(Clone)] pub struct Palette256(pub [RgbColor; 256]); +impl std::iter::FromIterator for Palette256 { + fn from_iter>(iter: I) -> Self { + let mut colors = [RgbColor::default(); 256]; + for (s, d) in iter.into_iter().zip(colors.iter_mut()) { + *d = s; + } + Self(colors) + } +} + #[derive(Clone, Debug)] pub struct ColorPalette { pub colors: Palette256, @@ -20,6 +30,24 @@ pub struct ColorPalette { pub scrollbar_thumb: RgbColor, } +/// Adjust the color to make it appear disabled. +/// This is not defined on RgbColor itself in order +/// to avoid termwiz requiring a dep on the palette crate. +fn grey_out(color: RgbColor) -> RgbColor { + use palette::{Blend, Lch, Saturate, Srgba}; + let color = Srgba::new(color.red, color.green, color.blue, 0xff); + let color: Srgba = color.into_format(); + let color = color.into_linear(); + + let desaturated = Lch::from(color).desaturate(0.2); + + let tint = Srgba::new(0.2, 0.2, 0.2, 0.6).into_linear(); + let result = Srgba::from_linear(tint.over(desaturated.into())); + let result = Srgba::::from_format(result); + + RgbColor::new(result.red, result.green, result.blue) +} + impl fmt::Debug for Palette256 { fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { // If we wanted to dump all of the entries, we'd use this: @@ -47,6 +75,21 @@ impl ColorPalette { | ColorAttribute::TrueColorWithDefaultFallback(color) => color, } } + + /// Returns a greyed out version of the whole palette + pub fn grey_out(&self) -> Self { + Self { + colors: self.colors.0.iter().map(|&c| grey_out(c)).collect(), + foreground: grey_out(self.foreground), + background: grey_out(self.background), + cursor_fg: grey_out(self.cursor_fg), + cursor_bg: grey_out(self.cursor_bg), + cursor_border: grey_out(self.cursor_border), + selection_fg: grey_out(self.selection_fg), + selection_bg: grey_out(self.selection_bg), + scrollbar_thumb: grey_out(self.scrollbar_thumb), + } + } } impl Default for ColorPalette {