From dbe786701cd0a2dfe4e3e623b4998404a42f7c2e Mon Sep 17 00:00:00 2001 From: joveian <1261914+joveian@users.noreply.github.com> Date: Mon, 30 Oct 2023 12:29:32 -0700 Subject: [PATCH 1/3] Fix lines in kitty terminal with text_fg_override_threshold set The kitty terminal has a new setting text_fg_override_threshold that checks the luminosity difference between the text and background and if it is above the set percentage turns the text black or white to get the best possible visibility. pastel currently uses a unicode half block character and sets both forground and background to the same color in the color patch. This patch changes this to be a space with both forground and background colors set to the same color (only becuase I don't know enough rust to figure out how to just set background color :/). Possibly this could cause trouble with some background transparency settings, although if so the current situation might as well to a lesser extent. I'm not sure how to make using text color work reliably with text_fg_override_threshold so I think a command line option to use one or the other would be needed there unless another drawing option is used. There are two other ways to draw on kitty that could be considered. The graphics protocol allow arbitrary images to be displayed and is supported by a few other terminals. kitty also supports using colors with DECCARA, although I don't know if any other terminals support this. In any case, with this patch it works for me and I checked that it still works on alacritty as well. --- src/cli/hdcanvas.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/cli/hdcanvas.rs b/src/cli/hdcanvas.rs index 93334cae..d0327adc 100644 --- a/src/cli/hdcanvas.rs +++ b/src/cli/hdcanvas.rs @@ -85,11 +85,20 @@ impl Canvas { let p_bottom = self.pixel(2 * i_div_2 + 1, j); match (p_top, p_bottom) { - (Some(top), Some(bottom)) => write!( - out, - "{}", - self.brush.paint("▀", top.ansi_style().on(bottom)) - )?, + (Some(top), Some(bottom)) => + if top == bottom { + write!( + out, + "{}", + self.brush.paint(" ", top.ansi_style().on(bottom)) + )? + } else { + write!( + out, + "{}", + self.brush.paint("▀", top.ansi_style().on(bottom)) + )? + }, (Some(top), None) => write!(out, "{}", self.brush.paint("▀", top))?, (None, Some(bottom)) => write!(out, "{}", self.brush.paint("▄", bottom))?, (None, None) => write!(out, " ")?, From 0e3d89eec60e2bce9d18f2d8b1fd4849adaa7d7f Mon Sep 17 00:00:00 2001 From: joveian <1261914+joveian@users.noreply.github.com> Date: Mon, 30 Oct 2023 13:18:48 -0700 Subject: [PATCH 2/3] cargo fmt --- src/cli/hdcanvas.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cli/hdcanvas.rs b/src/cli/hdcanvas.rs index d0327adc..64ebe030 100644 --- a/src/cli/hdcanvas.rs +++ b/src/cli/hdcanvas.rs @@ -85,7 +85,7 @@ impl Canvas { let p_bottom = self.pixel(2 * i_div_2 + 1, j); match (p_top, p_bottom) { - (Some(top), Some(bottom)) => + (Some(top), Some(bottom)) => { if top == bottom { write!( out, @@ -98,7 +98,8 @@ impl Canvas { "{}", self.brush.paint("▀", top.ansi_style().on(bottom)) )? - }, + } + } (Some(top), None) => write!(out, "{}", self.brush.paint("▀", top))?, (None, Some(bottom)) => write!(out, "{}", self.brush.paint("▄", bottom))?, (None, None) => write!(out, " ")?, From 414736b42861a928ce01e335a52a9c3295146dfd Mon Sep 17 00:00:00 2001 From: joveian <1261914+joveian@users.noreply.github.com> Date: Thu, 2 Nov 2023 06:17:41 -0700 Subject: [PATCH 3/3] Add comment about kitty's text_fg_override_threshold --- src/cli/hdcanvas.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cli/hdcanvas.rs b/src/cli/hdcanvas.rs index 64ebe030..e3257abe 100644 --- a/src/cli/hdcanvas.rs +++ b/src/cli/hdcanvas.rs @@ -75,6 +75,13 @@ impl Canvas { } } + // The kitty terminal has a feature text_fg_override_threshold that + // checks the difference in luminosity between text and background and + // changes the text to black or white to make it readable if the + // luminosity difference percentage is below the specified threshold. + // Using block characters for graphics display can trigger this, causing + // black or white lines or blocks, if the color is the same or too close. + // The checkerboard should be ok unless the theshold is set fairly high. pub fn print(&self, out: &mut dyn Write) -> Result<()> { for i_div_2 in 0..self.height / 2 { for j in 0..self.width {