mirror of
https://github.com/sharkdp/hexyl.git
synced 2026-10-30 09:05:54 +00:00
Enable custom colors with environment variables (#248)
* Enable custom colors with environment variables * Rename HEXYL_XYZ env vars to HEXYL_COLOR_XYZ
This commit is contained in:
1 parent
6220cae644
commit
9ef7c346dd
7 files changed
+268
-32
No files matched your search
+13
-13
@@ -84,11 +84,11 @@ impl Byte {
|
||||
fn color(self) -> &'static [u8] {
|
||||
use crate::ByteCategory::*;
|
||||
match self.category() {
|
||||
Null => COLOR_NULL,
|
||||
AsciiPrintable => COLOR_ASCII_PRINTABLE,
|
||||
AsciiWhitespace => COLOR_ASCII_WHITESPACE,
|
||||
AsciiOther => COLOR_ASCII_OTHER,
|
||||
NonAscii => COLOR_NONASCII,
|
||||
Null => COLOR_NULL.as_bytes(),
|
||||
AsciiPrintable => COLOR_ASCII_PRINTABLE.as_bytes(),
|
||||
AsciiWhitespace => COLOR_ASCII_WHITESPACE.as_bytes(),
|
||||
AsciiOther => COLOR_ASCII_OTHER.as_bytes(),
|
||||
NonAscii => COLOR_NONASCII.as_bytes(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -440,14 +440,14 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
|
||||
.as_bytes(),
|
||||
)?;
|
||||
if self.show_color {
|
||||
self.writer.write_all(COLOR_OFFSET)?;
|
||||
self.writer.write_all(COLOR_OFFSET.as_bytes())?;
|
||||
}
|
||||
if self.show_position_panel {
|
||||
match self.squeezer {
|
||||
Squeezer::Print => {
|
||||
self.writer.write_all(b"*")?;
|
||||
if self.show_color {
|
||||
self.writer.write_all(COLOR_RESET)?;
|
||||
self.writer.write_all(COLOR_RESET.as_bytes())?;
|
||||
}
|
||||
self.writer.write_all(b" ")?;
|
||||
}
|
||||
@@ -462,7 +462,7 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
|
||||
.write_all(self.byte_hex_panel_g[byte as usize].as_bytes())?;
|
||||
}
|
||||
if self.show_color {
|
||||
self.writer.write_all(COLOR_RESET)?;
|
||||
self.writer.write_all(COLOR_RESET.as_bytes())?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -494,7 +494,7 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
|
||||
}
|
||||
if i == 8 * self.panels - 1 {
|
||||
if self.show_color {
|
||||
self.writer.write_all(COLOR_RESET)?;
|
||||
self.writer.write_all(COLOR_RESET.as_bytes())?;
|
||||
self.curr_color = None;
|
||||
}
|
||||
self.writer.write_all(
|
||||
@@ -505,7 +505,7 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
|
||||
)?;
|
||||
} else if i % 8 == 7 {
|
||||
if self.show_color {
|
||||
self.writer.write_all(COLOR_RESET)?;
|
||||
self.writer.write_all(COLOR_RESET.as_bytes())?;
|
||||
self.curr_color = None;
|
||||
}
|
||||
self.writer.write_all(
|
||||
@@ -531,12 +531,12 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
|
||||
Squeezer::Print => {
|
||||
if !self.show_position_panel && i == 0 {
|
||||
if self.show_color {
|
||||
self.writer.write_all(COLOR_OFFSET)?;
|
||||
self.writer.write_all(COLOR_OFFSET.as_bytes())?;
|
||||
}
|
||||
self.writer
|
||||
.write_all(self.byte_char_panel[b'*' as usize].as_bytes())?;
|
||||
if self.show_color {
|
||||
self.writer.write_all(COLOR_RESET)?;
|
||||
self.writer.write_all(COLOR_RESET.as_bytes())?;
|
||||
}
|
||||
} else if i % (self.group_size as usize) == 0 {
|
||||
self.writer.write_all(b" ")?;
|
||||
@@ -562,7 +562,7 @@ impl<'a, Writer: Write> Printer<'a, Writer> {
|
||||
if i % 8 == 7 {
|
||||
if self.show_color {
|
||||
self.curr_color = None;
|
||||
self.writer.write_all(COLOR_RESET)?;
|
||||
self.writer.write_all(COLOR_RESET.as_bytes())?;
|
||||
}
|
||||
self.writer.write_all(b" ")?;
|
||||
// byte is last in last panel
|
||||
|
||||
Reference in new issue
Block a user