sharkdp / hexyl

A command-line hex viewer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there a cheat sheet anywhere telling what color correlates to category of byte?

MichaelBonnet opened this issue · comments

Obviously the color highlighting is wonderful, but I'm not knowledgeable enough to know what color denotes what.

Good point. We should add a simple table to the README.

Until then, you can look at these parts:

hexyl/src/lib.rs

Lines 15 to 20 in 9602667

const COLOR_NULL: Color = Fixed(242); // grey
const COLOR_OFFSET: Color = Fixed(242); // grey
const COLOR_ASCII_PRINTABLE: Color = Color::Cyan;
const COLOR_ASCII_WHITESPACE: Color = Color::Green;
const COLOR_ASCII_OTHER: Color = Color::Purple;
const COLOR_NONASCII: Color = Color::Yellow;

hexyl/src/lib.rs

Lines 34 to 58 in 9602667

fn category(self) -> ByteCategory {
if self.0 == 0x00 {
ByteCategory::Null
} else if self.0.is_ascii_graphic() {
ByteCategory::AsciiPrintable
} else if self.0.is_ascii_whitespace() {
ByteCategory::AsciiWhitespace
} else if self.0.is_ascii() {
ByteCategory::AsciiOther
} else {
ByteCategory::NonAscii
}
}
fn color(self) -> &'static Color {
use crate::ByteCategory::*;
match self.category() {
Null => &COLOR_NULL,
AsciiPrintable => &COLOR_ASCII_PRINTABLE,
AsciiWhitespace => &COLOR_ASCII_WHITESPACE,
AsciiOther => &COLOR_ASCII_OTHER,
NonAscii => &COLOR_NONASCII,
}
}

And Rusts documentation for some of these methods, e.g. https://doc.rust-lang.org/std/primitive.char.html#method.is_ascii_graphic

@sharkdp On a similar note. Is there a way to customize the colors? I suppose I could just tweak it in source.

@sharkdp On a similar note. Is there a way to customize the colors? I suppose I could just tweak it in source.

there is no way to do that right now.