mux: grey out the terminal contents when tardy

The predictive echo feels pretty reasonable, but if the connection
is having problems and we're showing the tardiness indicator, the
echo can give the impression that your input is going to get processed.
That may not be (usually is not!) the case.

This commit makes it a bit more visually distinctive that something
isn't right by greying out the color palette in that case.

refs: https://github.com/wez/wezterm/issues/127
This commit is contained in:
Wez Furlong committed 2020-03-14 08:57:35 -07:00
1 parent 382b8f53dd
commit 013288b1ef
5 files changed
+68 -12

No files matched your search

Generated
+1
View File
@@ -2958,6 +2958,7 @@ dependencies = [
"log",
"num",
"ordered-float",
"palette",
"pretty_assertions",
"serde",
"serde_derive",
+22 -11
View File
@@ -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 {
+1 -1
View File
@@ -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
+1
View File
@@ -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"]}
+43
View File
@@ -7,6 +7,16 @@ pub use termwiz::color::{AnsiColor, ColorAttribute, RgbColor, RgbaTuple};
#[derive(Clone)]
pub struct Palette256(pub [RgbColor; 256]);
impl std::iter::FromIterator<RgbColor> for Palette256 {
fn from_iter<I: IntoIterator<Item = RgbColor>>(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::<u8>::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 {