hexyl icon indicating copy to clipboard operation
hexyl copied to clipboard

Consider changing the `brightblack` color and glyph of NULL bytes

Open bitraid opened this issue 1 year ago • 6 comments

I have a couple of issues with the display of the offset and NULL bytes. They are not such a big deal for me, because I do a manual build and I apply a patch to fix them, but I thought of bringing them up anyway, for the benefit of other users with similar terminal configurations.

  • The first one, involves the color. brightblack is the background color of the Solarized Dark color scheme, so it becomes invisible on terminals with that configuration. This is a very popular color scheme, and I’m surprised that it hasn’t been brought up already. I would suggest to be changed to blue, which is a more compatible foreground color, and it’s not used for something else.

  • The second, has to do with the choice of the display character for NULL bytes. The "diamond operator" (U+22C4) is not a very common symbol, and it's not present in some popular fonts, like Terminus and Adobe Source Code Pro, so a fallback font is used and it doesn’t look nice. I think a better choice would be a more common symbol, like "subscript zero" (U+2080).

bitraid avatar Dec 30 '24 11:12 bitraid

Sounds reasonable, thank you. How does that look like (for different terminal schemes)?

sharkdp avatar Jan 04 '25 15:01 sharkdp

Thanks.

I took a few screenshots of foot terminal, showcasing 8 color schemes and 3 fonts:

  • Solarized Dark, Terminus hexyl-solarized-dark-terminus

  • Solarized Light, Terminus hexyl-solarized-light-terminus

  • Dracula, Source Code Pro hexyl-dracula-source-code-pro

  • Gruvbox Dark, Source Code Pro hexyl-gruvbox-dark-source-code-pro

  • Gruvbox Light, Source Code Pro hexyl-gruvbox-light-source-code-pro

  • Monokai Pro, Nimbus Mono hexyl-monokai-pro-nimbus-mono

  • Nord, Nimbus Mono hexyl-nord-nimbus-mono

  • XTerm, Nimbus Mono hexyl-xterm-nimbus-mono

I applied this patch (doesn't include the test change):

diff --git a/src/colors.rs b/src/colors.rs
index b76e641..eb5ea0a 100644
--- a/src/colors.rs
+++ b/src/colors.rs
@@ -1,7 +1,7 @@
 use owo_colors::{colors, Color};
 
-pub const COLOR_NULL: &[u8] = colors::BrightBlack::ANSI_FG.as_bytes();
-pub const COLOR_OFFSET: &[u8] = colors::BrightBlack::ANSI_FG.as_bytes();
+pub const COLOR_NULL: &[u8] = colors::Blue::ANSI_FG.as_bytes();
+pub const COLOR_OFFSET: &[u8] = colors::Blue::ANSI_FG.as_bytes();
 pub const COLOR_ASCII_PRINTABLE: &[u8] = colors::Cyan::ANSI_FG.as_bytes();
 pub const COLOR_ASCII_WHITESPACE: &[u8] = colors::Green::ANSI_FG.as_bytes();
 pub const COLOR_ASCII_OTHER: &[u8] = colors::Green::ANSI_FG.as_bytes();
@@ -24,12 +24,12 @@ pub const CP437: [char; 256] = [
     // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     //
-    // modified to use the ⋄ character instead of ␀
+    // modified to use the ₀ character instead of ␀
 
     // use https://en.wikipedia.org/w/index.php?title=Code_page_437&oldid=978947122
     // not ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/PC/CP437.TXT
     // because we want the graphic versions of 01h–1Fh + 7Fh
-    '⋄','☺','☻','♥','♦','♣','♠','•','◘','○','◙','♂','♀','♪','♫','☼',
+    '₀','☺','☻','♥','♦','♣','♠','•','◘','○','◙','♂','♀','♪','♫','☼',
     '►','◄','↕','‼','¶','§','▬','↨','↑','↓','→','←','∟','↔','▲','▼',
     ' ','!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/',
     '0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?',
diff --git a/src/lib.rs b/src/lib.rs
index bae2945..10d6b81 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -27,7 +27,7 @@ pub enum ByteCategory {
 #[derive(Copy, Clone, Debug, Default, ValueEnum)]
 #[non_exhaustive]
 pub enum CharacterTable {
-    /// Show printable ASCII characters as-is, '⋄' for NULL bytes, ' ' for
+    /// Show printable ASCII characters as-is, '₀' for NULL bytes, ' ' for
     /// space, '_' for other ASCII whitespace, '•' for other ASCII characters,
     /// and '×' for non-ASCII bytes.
     #[default]
@@ -96,7 +96,7 @@ impl Byte {
         use crate::ByteCategory::*;
         match character_table {
             CharacterTable::Default => match self.category() {
-                Null => '⋄',
+                Null => '₀',
                 AsciiPrintable => self.0 as char,
                 AsciiWhitespace if self.0 == 0x20 => ' ',
                 AsciiWhitespace => '_',
diff --git a/src/main.rs b/src/main.rs
index 2e32cff..eef9dd8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -494,7 +494,7 @@ fn print_color_table() -> io::Result<()> {
 
     // NULL bytes
     stdout.write_all(COLOR_NULL)?;
-    writeln!(stdout, "⋄ NULL bytes (0x00)")?;
+    writeln!(stdout, "₀ NULL bytes (0x00)")?;
     stdout.write_all(COLOR_RESET)?;
 
     // ASCII printable

bitraid avatar Jan 04 '25 19:01 bitraid

I really like how brightblack makes the zero characters fade into the background on my current terminal scheme:

image

But it obviously looks very bad on other terminal schemes. It vanishes for solarized dark, as you mentioned. And it has high contrast (which is the opposite of what I'd like to have) for light color themes.

I think the only reasonable way forward is to add themes, even if don't really want to. Maybe we can start with something like dark (auto), light, high-contrast to begin with? Or maybe it would be better to let users control single colors, as in --set-color null <ansi code>?

sharkdp avatar Mar 02 '25 18:03 sharkdp

I like the idea of having the option to set each color. There aren't many items to configure anyway (maybe include the border, too). Even better would be to also have the option for setting the glyph of each non-printable character type.

bitraid avatar Mar 02 '25 19:03 bitraid

I'm also okay with changing the 0 character without making it configurable, for now. I'm not sure I like subscript 0. It's not vertically centered and looks a bit off.

sharkdp avatar Mar 02 '25 19:03 sharkdp

I'm not a big fan of it, either - I chose it mostly because it looks like 0. I recently switched to U+2027 ("hyphenation point" - it is a little thicker than middle dot).

bitraid avatar Mar 02 '25 19:03 bitraid