From 6a230d34a4681aebfe90a738a253dca22aea694b Mon Sep 17 00:00:00 2001 From: Sharif Haason Date: Tue, 13 Jun 2023 14:47:44 -0400 Subject: [PATCH 01/18] Implement character table control and codepage 437 option --- src/lib.rs | 72 +++++++++++++++++++++++++++++++++++++++++++++-------- src/main.rs | 25 ++++++++++++++++++- 2 files changed, 86 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1c0c62e..e52e182 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,6 +21,29 @@ const COLOR_ASCII_OTHER: &[u8] = colors::Green::ANSI_FG.as_bytes(); const COLOR_NONASCII: &[u8] = colors::Yellow::ANSI_FG.as_bytes(); const COLOR_RESET: &[u8] = colors::Default::ANSI_FG.as_bytes(); +#[rustfmt::skip] +const CP437: [char; 256] = [ + // 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',':',';','<','=','>','?', + '@','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O', + 'P','Q','R','S','T','U','V','W','X','Y','Z','[','\\',']','^','_', + '`','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o', + 'p','q','r','s','t','u','v','w','x','y','z','{','|','}','~','⌂', + 'Ç','ü','é','â','ä','à','å','ç','ê','ë','è','ï','î','ì','Ä','Å', + 'É','æ','Æ','ô','ö','ò','û','ù','ÿ','Ö','Ü','¢','£','¥','₧','ƒ', + 'á','í','ó','ú','ñ','Ñ','ª','º','¿','⌐','¬','½','¼','¡','«','»', + '░','▒','▓','│','┤','╡','╢','╖','╕','╣','║','╗','╝','╜','╛','┐', + '└','┴','┬','├','─','┼','╞','╟','╚','╔','╩','╦','╠','═','╬','╧', + '╨','╤','╥','╙','╘','╒','╓','╫','╪','┘','┌','█','▄','▌','▐','▀', + 'α','ß','Γ','π','Σ','σ','µ','τ','Φ','Θ','Ω','δ','∞','φ','ε','∩', + '≡','±','≥','≤','⌠','⌡','÷','≈','°','∙','·','√','ⁿ','²','■',' ', +]; + #[derive(Copy, Clone)] pub enum ByteCategory { Null, @@ -30,6 +53,12 @@ pub enum ByteCategory { NonAscii, } +#[derive(Copy, Clone)] +pub enum CharTable { + AsciiOnly, + CP437, +} + #[derive(Copy, Clone)] pub enum Endianness { Little, @@ -74,17 +103,27 @@ impl Byte { } } - fn as_char(self) -> char { + fn as_char(self, char_table: CharTable) -> char { use crate::ByteCategory::*; - - match self.category() { - Null => '⋄', - AsciiPrintable => self.0 as char, - AsciiWhitespace if self.0 == 0x20 => ' ', - AsciiWhitespace => '_', - AsciiOther => '•', - NonAscii => '×', + match char_table { + CharTable::AsciiOnly => match self.category() { + Null => '⋄', + AsciiPrintable => self.0 as char, + AsciiWhitespace if self.0 == 0x20 => ' ', + AsciiWhitespace => '_', + AsciiOther => '•', + NonAscii => '×', + }, + CharTable::CP437 => CP437[self.0.to_ne_bytes()[0] as usize], } + // match self.category() { + // Null => '⋄', + // AsciiPrintable => self.0 as char, + // AsciiWhitespace if self.0 == 0x20 => ' ', + // AsciiWhitespace => '_', + // AsciiOther => '•', + // NonAscii => '×', + // } } } @@ -167,6 +206,7 @@ pub struct PrinterBuilder<'a, Writer: Write> { group_size: u8, base: Base, endianness: Endianness, + char_table: CharTable, } impl<'a, Writer: Write> PrinterBuilder<'a, Writer> { @@ -182,6 +222,7 @@ impl<'a, Writer: Write> PrinterBuilder<'a, Writer> { group_size: 1, base: Base::Hexadecimal, endianness: Endianness::Big, + char_table: CharTable::AsciiOnly, } } @@ -230,6 +271,11 @@ impl<'a, Writer: Write> PrinterBuilder<'a, Writer> { self } + pub fn char_table(mut self, char_table: CharTable) -> Self { + self.char_table = char_table; + self + } + pub fn build(self) -> Printer<'a, Writer> { Printer::new( self.writer, @@ -242,6 +288,7 @@ impl<'a, Writer: Write> PrinterBuilder<'a, Writer> { self.group_size, self.base, self.endianness, + self.char_table, ) } } @@ -285,6 +332,7 @@ impl<'a, Writer: Write> Printer<'a, Writer> { group_size: u8, base: Base, endianness: Endianness, + char_table: CharTable, ) -> Printer<'a, Writer> { Printer { idx: 0, @@ -304,7 +352,7 @@ impl<'a, Writer: Write> Printer<'a, Writer> { }) .collect(), byte_char_panel: (0u8..=u8::MAX) - .map(|i| format!("{}", Byte(i).as_char())) + .map(|i| format!("{}", Byte(i).as_char(char_table))) .collect(), byte_hex_panel_g: (0u8..=u8::MAX).map(|i| format!("{i:02x}")).collect(), squeezer: if use_squeeze { @@ -732,6 +780,7 @@ mod tests { 1, Base::Hexadecimal, Endianness::Big, + CharTable::AsciiOnly, ); printer.print_all(input).unwrap(); @@ -787,6 +836,7 @@ mod tests { 1, Base::Hexadecimal, Endianness::Big, + CharTable::AsciiOnly, ); printer.display_offset(0xdeadbeef); @@ -821,6 +871,7 @@ mod tests { 1, Base::Hexadecimal, Endianness::Big, + CharTable::AsciiOnly, ); printer.print_all(input).unwrap(); @@ -881,6 +932,7 @@ mod tests { 1, Base::Hexadecimal, Endianness::Big, + CharTable::AsciiOnly, ); printer.print_all(input).unwrap(); diff --git a/src/main.rs b/src/main.rs index 5e022f3..02ecf0b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,7 @@ use thiserror::Error as ThisError; use terminal_size::terminal_size; -use hexyl::{Base, BorderStyle, Endianness, Input, PrinterBuilder}; +use hexyl::{Base, BorderStyle, CharTable, Endianness, Input, PrinterBuilder}; #[cfg(test)] mod tests; @@ -212,6 +212,17 @@ fn run() -> Result<()> { .hide(true) .help("An alias for '--endianness=little'."), ) + .arg( + Arg::new("character_table") + .long("character_table") + .value_name("FORMAT") + .value_parser(["codepage-437", "ascii-only"]) + .help( + "The character table that should be used. 'ascii-only' \ + will show dots for non-ASCII characters, and 'codepage-437 \ + will use Code page 437 for those characters." + ), + ) .arg( Arg::new("base") .short('b') @@ -469,6 +480,17 @@ fn run() -> Result<()> { ("big", _) => Endianness::Big, _ => unreachable!(), }; + + let char_table = match matches + .get_one::("character_table") + .unwrap_or(&String::from("ascii-only")) + .as_ref() + { + "ascii-only" => CharTable::AsciiOnly, + "codepage-437" => CharTable::CP437, + _ => unreachable!(), + }; + let stdout = io::stdout(); let mut stdout_lock = BufWriter::new(stdout.lock()); @@ -482,6 +504,7 @@ fn run() -> Result<()> { .group_size(group_size) .with_base(base) .endianness(endianness) + .char_table(char_table) .build(); printer.display_offset(skip_offset + display_offset); printer.print_all(&mut reader).map_err(|e| anyhow!(e))?; From 4e663576189b24d0652128bdb22daef963ab1eec Mon Sep 17 00:00:00 2001 From: Sharif Haason Date: Tue, 13 Jun 2023 14:49:52 -0400 Subject: [PATCH 02/18] Use hyphens instead of underscores --- src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 02ecf0b..66b1a32 100644 --- a/src/main.rs +++ b/src/main.rs @@ -213,8 +213,8 @@ fn run() -> Result<()> { .help("An alias for '--endianness=little'."), ) .arg( - Arg::new("character_table") - .long("character_table") + Arg::new("character-table") + .long("character-table") .value_name("FORMAT") .value_parser(["codepage-437", "ascii-only"]) .help( @@ -482,7 +482,7 @@ fn run() -> Result<()> { }; let char_table = match matches - .get_one::("character_table") + .get_one::("character-table") .unwrap_or(&String::from("ascii-only")) .as_ref() { From c4f91959efc0b67f6b944fb6e7212073ed091d3b Mon Sep 17 00:00:00 2001 From: Sharif Haason Date: Tue, 13 Jun 2023 16:38:55 -0400 Subject: [PATCH 03/18] Add default value for character table --- src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 66b1a32..7cee640 100644 --- a/src/main.rs +++ b/src/main.rs @@ -217,6 +217,7 @@ fn run() -> Result<()> { .long("character-table") .value_name("FORMAT") .value_parser(["codepage-437", "ascii-only"]) + .default_value("ascii-only") .help( "The character table that should be used. 'ascii-only' \ will show dots for non-ASCII characters, and 'codepage-437 \ @@ -483,7 +484,7 @@ fn run() -> Result<()> { let char_table = match matches .get_one::("character-table") - .unwrap_or(&String::from("ascii-only")) + .unwrap() .as_ref() { "ascii-only" => CharTable::AsciiOnly, From 0c192e979bbc56f55cd510583331d8a7cc333f73 Mon Sep 17 00:00:00 2001 From: Sharif Haason Date: Tue, 13 Jun 2023 16:39:50 -0400 Subject: [PATCH 04/18] Make `CharTable` non-exhaustive --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index e52e182..feb0b02 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -54,6 +54,7 @@ pub enum ByteCategory { } #[derive(Copy, Clone)] +#[non_exhaustive] pub enum CharTable { AsciiOnly, CP437, From 29e3350e690795b19e6abe7a911f48001909470c Mon Sep 17 00:00:00 2001 From: Sharif Haason Date: Tue, 13 Jun 2023 16:41:34 -0400 Subject: [PATCH 05/18] Rename `CharTable` to `CharacterTable` --- src/lib.rs | 32 ++++++++++++++++---------------- src/main.rs | 10 +++++----- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index feb0b02..dd5d6b8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -55,7 +55,7 @@ pub enum ByteCategory { #[derive(Copy, Clone)] #[non_exhaustive] -pub enum CharTable { +pub enum CharacterTable { AsciiOnly, CP437, } @@ -104,10 +104,10 @@ impl Byte { } } - fn as_char(self, char_table: CharTable) -> char { + fn as_char(self, character_table: CharacterTable) -> char { use crate::ByteCategory::*; - match char_table { - CharTable::AsciiOnly => match self.category() { + match character_table { + CharacterTable::AsciiOnly => match self.category() { Null => '⋄', AsciiPrintable => self.0 as char, AsciiWhitespace if self.0 == 0x20 => ' ', @@ -115,7 +115,7 @@ impl Byte { AsciiOther => '•', NonAscii => '×', }, - CharTable::CP437 => CP437[self.0.to_ne_bytes()[0] as usize], + CharacterTable::CP437 => CP437[self.0.to_ne_bytes()[0] as usize], } // match self.category() { // Null => '⋄', @@ -207,7 +207,7 @@ pub struct PrinterBuilder<'a, Writer: Write> { group_size: u8, base: Base, endianness: Endianness, - char_table: CharTable, + character_table: CharacterTable, } impl<'a, Writer: Write> PrinterBuilder<'a, Writer> { @@ -223,7 +223,7 @@ impl<'a, Writer: Write> PrinterBuilder<'a, Writer> { group_size: 1, base: Base::Hexadecimal, endianness: Endianness::Big, - char_table: CharTable::AsciiOnly, + character_table: CharacterTable::AsciiOnly, } } @@ -272,8 +272,8 @@ impl<'a, Writer: Write> PrinterBuilder<'a, Writer> { self } - pub fn char_table(mut self, char_table: CharTable) -> Self { - self.char_table = char_table; + pub fn character_table(mut self, character_table: CharacterTable) -> Self { + self.character_table = character_table; self } @@ -289,7 +289,7 @@ impl<'a, Writer: Write> PrinterBuilder<'a, Writer> { self.group_size, self.base, self.endianness, - self.char_table, + self.character_table, ) } } @@ -333,7 +333,7 @@ impl<'a, Writer: Write> Printer<'a, Writer> { group_size: u8, base: Base, endianness: Endianness, - char_table: CharTable, + character_table: CharacterTable, ) -> Printer<'a, Writer> { Printer { idx: 0, @@ -353,7 +353,7 @@ impl<'a, Writer: Write> Printer<'a, Writer> { }) .collect(), byte_char_panel: (0u8..=u8::MAX) - .map(|i| format!("{}", Byte(i).as_char(char_table))) + .map(|i| format!("{}", Byte(i).as_char(character_table))) .collect(), byte_hex_panel_g: (0u8..=u8::MAX).map(|i| format!("{i:02x}")).collect(), squeezer: if use_squeeze { @@ -781,7 +781,7 @@ mod tests { 1, Base::Hexadecimal, Endianness::Big, - CharTable::AsciiOnly, + CharacterTable::AsciiOnly, ); printer.print_all(input).unwrap(); @@ -837,7 +837,7 @@ mod tests { 1, Base::Hexadecimal, Endianness::Big, - CharTable::AsciiOnly, + CharacterTable::AsciiOnly, ); printer.display_offset(0xdeadbeef); @@ -872,7 +872,7 @@ mod tests { 1, Base::Hexadecimal, Endianness::Big, - CharTable::AsciiOnly, + CharacterTable::AsciiOnly, ); printer.print_all(input).unwrap(); @@ -933,7 +933,7 @@ mod tests { 1, Base::Hexadecimal, Endianness::Big, - CharTable::AsciiOnly, + CharacterTable::AsciiOnly, ); printer.print_all(input).unwrap(); diff --git a/src/main.rs b/src/main.rs index 7cee640..8281b55 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,7 @@ use thiserror::Error as ThisError; use terminal_size::terminal_size; -use hexyl::{Base, BorderStyle, CharTable, Endianness, Input, PrinterBuilder}; +use hexyl::{Base, BorderStyle, CharacterTable, Endianness, Input, PrinterBuilder}; #[cfg(test)] mod tests; @@ -482,13 +482,13 @@ fn run() -> Result<()> { _ => unreachable!(), }; - let char_table = match matches + let character_table = match matches .get_one::("character-table") .unwrap() .as_ref() { - "ascii-only" => CharTable::AsciiOnly, - "codepage-437" => CharTable::CP437, + "ascii-only" => CharacterTable::AsciiOnly, + "codepage-437" => CharacterTable::CP437, _ => unreachable!(), }; @@ -505,7 +505,7 @@ fn run() -> Result<()> { .group_size(group_size) .with_base(base) .endianness(endianness) - .char_table(char_table) + .character_table(character_table) .build(); printer.display_offset(skip_offset + display_offset); printer.print_all(&mut reader).map_err(|e| anyhow!(e))?; From e363f2fdc4f783c33355e7489eebd849d6238a94 Mon Sep 17 00:00:00 2001 From: Sharif Haason Date: Tue, 13 Jun 2023 16:42:11 -0400 Subject: [PATCH 06/18] Remove old `as_char` implementation --- src/lib.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index dd5d6b8..4f92e88 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -117,14 +117,6 @@ impl Byte { }, CharacterTable::CP437 => CP437[self.0.to_ne_bytes()[0] as usize], } - // match self.category() { - // Null => '⋄', - // AsciiPrintable => self.0 as char, - // AsciiWhitespace if self.0 == 0x20 => ' ', - // AsciiWhitespace => '_', - // AsciiOther => '•', - // NonAscii => '×', - // } } } From 9362c2313abb1c6fd4aa2e84f08fab1bb6951b0b Mon Sep 17 00:00:00 2001 From: Sharif Haason Date: Tue, 13 Jun 2023 16:46:29 -0400 Subject: [PATCH 07/18] Attribute original author of CP437 --- src/lib.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 4f92e88..378376a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,6 +23,22 @@ const COLOR_RESET: &[u8] = colors::Default::ANSI_FG.as_bytes(); #[rustfmt::skip] const CP437: [char; 256] = [ + // Copyright (c) 2016, Delan Azabani + // + // Permission to use, copy, modify, and/or distribute this software for any + // purpose with or without fee is hereby granted, provided that the above + // copyright notice and this permission notice appear in all copies. + // + // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + // 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 nul + // 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 From 78477a90c988fe2976909472e5b9b8e605a87570 Mon Sep 17 00:00:00 2001 From: sharif <61516383+sharifhsn@users.noreply.github.com> Date: Tue, 13 Jun 2023 15:21:21 -0400 Subject: [PATCH 08/18] Close quotation in help text Co-authored-by: David Peter --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 8281b55..cbf452b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -220,7 +220,7 @@ fn run() -> Result<()> { .default_value("ascii-only") .help( "The character table that should be used. 'ascii-only' \ - will show dots for non-ASCII characters, and 'codepage-437 \ + will show dots for non-ASCII characters, and 'codepage-437' \ will use Code page 437 for those characters." ), ) From 58c8c06317f9a5756a218d54dff0feed141a280c Mon Sep 17 00:00:00 2001 From: Sharif Haason Date: Wed, 14 Jun 2023 11:24:24 -0400 Subject: [PATCH 09/18] =?UTF-8?q?Clarify=20use=20of=20=E2=90=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 378376a..1f7b9a4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,7 +37,7 @@ 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 nul + // 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 From 10ddbbad7d5cb378a49e0dcb1d09a45036bbc375 Mon Sep 17 00:00:00 2001 From: Sharif Haason Date: Wed, 14 Jun 2023 11:26:44 -0400 Subject: [PATCH 10/18] =?UTF-8?q?Use=20U+FB00=20LATIN=20SMALL=20LIGATURE?= =?UTF-8?q?=20FF=20(=EF=AC=80)=20for=20FFh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 1f7b9a4..324821a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,7 +57,7 @@ const CP437: [char; 256] = [ '└','┴','┬','├','─','┼','╞','╟','╚','╔','╩','╦','╠','═','╬','╧', '╨','╤','╥','╙','╘','╒','╓','╫','╪','┘','┌','█','▄','▌','▐','▀', 'α','ß','Γ','π','Σ','σ','µ','τ','Φ','Θ','Ω','δ','∞','φ','ε','∩', - '≡','±','≥','≤','⌠','⌡','÷','≈','°','∙','·','√','ⁿ','²','■',' ', + '≡','±','≥','≤','⌠','⌡','÷','≈','°','∙','·','√','ⁿ','²','■','ff', ]; #[derive(Copy, Clone)] From 19f325a691102fe1608a972ea337b57f15272a1c Mon Sep 17 00:00:00 2001 From: Sharif Haason Date: Wed, 14 Jun 2023 12:15:35 -0400 Subject: [PATCH 11/18] Implement block character table --- src/lib.rs | 297 +++++++++++++++++++++++++++++++++++++++++++++++++--- src/main.rs | 8 +- 2 files changed, 287 insertions(+), 18 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 324821a..5181804 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,6 +20,264 @@ const COLOR_ASCII_WHITESPACE: &[u8] = colors::Green::ANSI_FG.as_bytes(); const COLOR_ASCII_OTHER: &[u8] = colors::Green::ANSI_FG.as_bytes(); const COLOR_NONASCII: &[u8] = colors::Yellow::ANSI_FG.as_bytes(); const COLOR_RESET: &[u8] = colors::Default::ANSI_FG.as_bytes(); +const COLORS_XTERM: [&[u8]; 256] = [ + colors::xterm::UserBlack::ANSI_FG.as_bytes(), + colors::xterm::UserRed::ANSI_FG.as_bytes(), + colors::xterm::UserGreen::ANSI_FG.as_bytes(), + colors::xterm::UserYellow::ANSI_FG.as_bytes(), + colors::xterm::UserBlue::ANSI_FG.as_bytes(), + colors::xterm::UserMagenta::ANSI_FG.as_bytes(), + colors::xterm::UserCyan::ANSI_FG.as_bytes(), + colors::xterm::UserWhite::ANSI_FG.as_bytes(), + colors::xterm::UserBrightBlack::ANSI_FG.as_bytes(), + colors::xterm::UserBrightRed::ANSI_FG.as_bytes(), + colors::xterm::UserBrightGreen::ANSI_FG.as_bytes(), + colors::xterm::UserBrightYellow::ANSI_FG.as_bytes(), + colors::xterm::UserBrightBlue::ANSI_FG.as_bytes(), + colors::xterm::UserBrightMagenta::ANSI_FG.as_bytes(), + colors::xterm::UserBrightCyan::ANSI_FG.as_bytes(), + colors::xterm::UserBrightWhite::ANSI_FG.as_bytes(), + colors::xterm::Black::ANSI_FG.as_bytes(), + colors::xterm::StratosBlue::ANSI_FG.as_bytes(), + colors::xterm::NavyBlue::ANSI_FG.as_bytes(), + colors::xterm::MidnightBlue::ANSI_FG.as_bytes(), + colors::xterm::DarkBlue::ANSI_FG.as_bytes(), + colors::xterm::Blue::ANSI_FG.as_bytes(), + colors::xterm::CamaroneGreen::ANSI_FG.as_bytes(), + colors::xterm::BlueStone::ANSI_FG.as_bytes(), + colors::xterm::OrientBlue::ANSI_FG.as_bytes(), + colors::xterm::EndeavourBlue::ANSI_FG.as_bytes(), + colors::xterm::ScienceBlue::ANSI_FG.as_bytes(), + colors::xterm::BlueRibbon::ANSI_FG.as_bytes(), + colors::xterm::JapaneseLaurel::ANSI_FG.as_bytes(), + colors::xterm::DeepSeaGreen::ANSI_FG.as_bytes(), + colors::xterm::Teal::ANSI_FG.as_bytes(), + colors::xterm::DeepCerulean::ANSI_FG.as_bytes(), + colors::xterm::LochmaraBlue::ANSI_FG.as_bytes(), + colors::xterm::AzureRadiance::ANSI_FG.as_bytes(), + colors::xterm::LightJapaneseLaurel::ANSI_FG.as_bytes(), + colors::xterm::Jade::ANSI_FG.as_bytes(), + colors::xterm::PersianGreen::ANSI_FG.as_bytes(), + colors::xterm::BondiBlue::ANSI_FG.as_bytes(), + colors::xterm::Cerulean::ANSI_FG.as_bytes(), + colors::xterm::LightAzureRadiance::ANSI_FG.as_bytes(), + colors::xterm::DarkGreen::ANSI_FG.as_bytes(), + colors::xterm::Malachite::ANSI_FG.as_bytes(), + colors::xterm::CaribbeanGreen::ANSI_FG.as_bytes(), + colors::xterm::LightCaribbeanGreen::ANSI_FG.as_bytes(), + colors::xterm::RobinEggBlue::ANSI_FG.as_bytes(), + colors::xterm::Aqua::ANSI_FG.as_bytes(), + colors::xterm::Green::ANSI_FG.as_bytes(), + colors::xterm::DarkSpringGreen::ANSI_FG.as_bytes(), + colors::xterm::SpringGreen::ANSI_FG.as_bytes(), + colors::xterm::LightSpringGreen::ANSI_FG.as_bytes(), + colors::xterm::BrightTurquoise::ANSI_FG.as_bytes(), + colors::xterm::Cyan::ANSI_FG.as_bytes(), + colors::xterm::Rosewood::ANSI_FG.as_bytes(), + colors::xterm::PompadourMagenta::ANSI_FG.as_bytes(), + colors::xterm::PigmentIndigo::ANSI_FG.as_bytes(), + colors::xterm::DarkPurple::ANSI_FG.as_bytes(), + colors::xterm::ElectricIndigo::ANSI_FG.as_bytes(), + colors::xterm::ElectricPurple::ANSI_FG.as_bytes(), + colors::xterm::VerdunGreen::ANSI_FG.as_bytes(), + colors::xterm::ScorpionOlive::ANSI_FG.as_bytes(), + colors::xterm::Lilac::ANSI_FG.as_bytes(), + colors::xterm::ScampiIndigo::ANSI_FG.as_bytes(), + colors::xterm::Indigo::ANSI_FG.as_bytes(), + colors::xterm::DarkCornflowerBlue::ANSI_FG.as_bytes(), + colors::xterm::DarkLimeade::ANSI_FG.as_bytes(), + colors::xterm::GladeGreen::ANSI_FG.as_bytes(), + colors::xterm::JuniperGreen::ANSI_FG.as_bytes(), + colors::xterm::HippieBlue::ANSI_FG.as_bytes(), + colors::xterm::HavelockBlue::ANSI_FG.as_bytes(), + colors::xterm::CornflowerBlue::ANSI_FG.as_bytes(), + colors::xterm::Limeade::ANSI_FG.as_bytes(), + colors::xterm::FernGreen::ANSI_FG.as_bytes(), + colors::xterm::SilverTree::ANSI_FG.as_bytes(), + colors::xterm::Tradewind::ANSI_FG.as_bytes(), + colors::xterm::ShakespeareBlue::ANSI_FG.as_bytes(), + colors::xterm::DarkMalibuBlue::ANSI_FG.as_bytes(), + colors::xterm::DarkBrightGreen::ANSI_FG.as_bytes(), + colors::xterm::DarkPastelGreen::ANSI_FG.as_bytes(), + colors::xterm::PastelGreen::ANSI_FG.as_bytes(), + colors::xterm::DownyTeal::ANSI_FG.as_bytes(), + colors::xterm::Viking::ANSI_FG.as_bytes(), + colors::xterm::MalibuBlue::ANSI_FG.as_bytes(), + colors::xterm::BrightGreen::ANSI_FG.as_bytes(), + colors::xterm::DarkScreaminGreen::ANSI_FG.as_bytes(), + colors::xterm::ScreaminGreen::ANSI_FG.as_bytes(), + colors::xterm::DarkAquamarine::ANSI_FG.as_bytes(), + colors::xterm::Aquamarine::ANSI_FG.as_bytes(), + colors::xterm::LightAquamarine::ANSI_FG.as_bytes(), + colors::xterm::Maroon::ANSI_FG.as_bytes(), + colors::xterm::DarkFreshEggplant::ANSI_FG.as_bytes(), + colors::xterm::LightFreshEggplant::ANSI_FG.as_bytes(), + colors::xterm::Purple::ANSI_FG.as_bytes(), + colors::xterm::ElectricViolet::ANSI_FG.as_bytes(), + colors::xterm::LightElectricViolet::ANSI_FG.as_bytes(), + colors::xterm::Brown::ANSI_FG.as_bytes(), + colors::xterm::CopperRose::ANSI_FG.as_bytes(), + colors::xterm::StrikemasterPurple::ANSI_FG.as_bytes(), + colors::xterm::DelugePurple::ANSI_FG.as_bytes(), + colors::xterm::DarkMediumPurple::ANSI_FG.as_bytes(), + colors::xterm::DarkHeliotropePurple::ANSI_FG.as_bytes(), + colors::xterm::Olive::ANSI_FG.as_bytes(), + colors::xterm::ClayCreekOlive::ANSI_FG.as_bytes(), + colors::xterm::DarkGray::ANSI_FG.as_bytes(), + colors::xterm::WildBlueYonder::ANSI_FG.as_bytes(), + colors::xterm::ChetwodeBlue::ANSI_FG.as_bytes(), + colors::xterm::SlateBlue::ANSI_FG.as_bytes(), + colors::xterm::LightLimeade::ANSI_FG.as_bytes(), + colors::xterm::ChelseaCucumber::ANSI_FG.as_bytes(), + colors::xterm::BayLeaf::ANSI_FG.as_bytes(), + colors::xterm::GulfStream::ANSI_FG.as_bytes(), + colors::xterm::PoloBlue::ANSI_FG.as_bytes(), + colors::xterm::LightMalibuBlue::ANSI_FG.as_bytes(), + colors::xterm::Pistachio::ANSI_FG.as_bytes(), + colors::xterm::LightPastelGreen::ANSI_FG.as_bytes(), + colors::xterm::DarkFeijoaGreen::ANSI_FG.as_bytes(), + colors::xterm::VistaBlue::ANSI_FG.as_bytes(), + colors::xterm::Bermuda::ANSI_FG.as_bytes(), + colors::xterm::DarkAnakiwaBlue::ANSI_FG.as_bytes(), + colors::xterm::ChartreuseGreen::ANSI_FG.as_bytes(), + colors::xterm::LightScreaminGreen::ANSI_FG.as_bytes(), + colors::xterm::DarkMintGreen::ANSI_FG.as_bytes(), + colors::xterm::MintGreen::ANSI_FG.as_bytes(), + colors::xterm::LighterAquamarine::ANSI_FG.as_bytes(), + colors::xterm::AnakiwaBlue::ANSI_FG.as_bytes(), + colors::xterm::BrightRed::ANSI_FG.as_bytes(), + colors::xterm::DarkFlirt::ANSI_FG.as_bytes(), + colors::xterm::Flirt::ANSI_FG.as_bytes(), + colors::xterm::LightFlirt::ANSI_FG.as_bytes(), + colors::xterm::DarkViolet::ANSI_FG.as_bytes(), + colors::xterm::BrightElectricViolet::ANSI_FG.as_bytes(), + colors::xterm::RoseofSharonOrange::ANSI_FG.as_bytes(), + colors::xterm::MatrixPink::ANSI_FG.as_bytes(), + colors::xterm::TapestryPink::ANSI_FG.as_bytes(), + colors::xterm::FuchsiaPink::ANSI_FG.as_bytes(), + colors::xterm::MediumPurple::ANSI_FG.as_bytes(), + colors::xterm::Heliotrope::ANSI_FG.as_bytes(), + colors::xterm::PirateGold::ANSI_FG.as_bytes(), + colors::xterm::MuesliOrange::ANSI_FG.as_bytes(), + colors::xterm::PharlapPink::ANSI_FG.as_bytes(), + colors::xterm::Bouquet::ANSI_FG.as_bytes(), + colors::xterm::Lavender::ANSI_FG.as_bytes(), + colors::xterm::LightHeliotrope::ANSI_FG.as_bytes(), + colors::xterm::BuddhaGold::ANSI_FG.as_bytes(), + colors::xterm::OliveGreen::ANSI_FG.as_bytes(), + colors::xterm::HillaryOlive::ANSI_FG.as_bytes(), + colors::xterm::SilverChalice::ANSI_FG.as_bytes(), + colors::xterm::WistfulLilac::ANSI_FG.as_bytes(), + colors::xterm::MelroseLilac::ANSI_FG.as_bytes(), + colors::xterm::RioGrandeGreen::ANSI_FG.as_bytes(), + colors::xterm::ConiferGreen::ANSI_FG.as_bytes(), + colors::xterm::Feijoa::ANSI_FG.as_bytes(), + colors::xterm::PixieGreen::ANSI_FG.as_bytes(), + colors::xterm::JungleMist::ANSI_FG.as_bytes(), + colors::xterm::LightAnakiwaBlue::ANSI_FG.as_bytes(), + colors::xterm::Lime::ANSI_FG.as_bytes(), + colors::xterm::GreenYellow::ANSI_FG.as_bytes(), + colors::xterm::LightMintGreen::ANSI_FG.as_bytes(), + colors::xterm::Celadon::ANSI_FG.as_bytes(), + colors::xterm::AeroBlue::ANSI_FG.as_bytes(), + colors::xterm::FrenchPassLightBlue::ANSI_FG.as_bytes(), + colors::xterm::GuardsmanRed::ANSI_FG.as_bytes(), + colors::xterm::RazzmatazzCerise::ANSI_FG.as_bytes(), + colors::xterm::MediumVioletRed::ANSI_FG.as_bytes(), + colors::xterm::HollywoodCerise::ANSI_FG.as_bytes(), + colors::xterm::DarkPurplePizzazz::ANSI_FG.as_bytes(), + colors::xterm::BrighterElectricViolet::ANSI_FG.as_bytes(), + colors::xterm::TennOrange::ANSI_FG.as_bytes(), + colors::xterm::RomanOrange::ANSI_FG.as_bytes(), + colors::xterm::CranberryPink::ANSI_FG.as_bytes(), + colors::xterm::HopbushPink::ANSI_FG.as_bytes(), + colors::xterm::Orchid::ANSI_FG.as_bytes(), + colors::xterm::LighterHeliotrope::ANSI_FG.as_bytes(), + colors::xterm::MangoTango::ANSI_FG.as_bytes(), + colors::xterm::Copperfield::ANSI_FG.as_bytes(), + colors::xterm::SeaPink::ANSI_FG.as_bytes(), + colors::xterm::CanCanPink::ANSI_FG.as_bytes(), + colors::xterm::LightOrchid::ANSI_FG.as_bytes(), + colors::xterm::BrightHeliotrope::ANSI_FG.as_bytes(), + colors::xterm::DarkCorn::ANSI_FG.as_bytes(), + colors::xterm::DarkTachaOrange::ANSI_FG.as_bytes(), + colors::xterm::TanBeige::ANSI_FG.as_bytes(), + colors::xterm::ClamShell::ANSI_FG.as_bytes(), + colors::xterm::ThistlePink::ANSI_FG.as_bytes(), + colors::xterm::Mauve::ANSI_FG.as_bytes(), + colors::xterm::Corn::ANSI_FG.as_bytes(), + colors::xterm::TachaOrange::ANSI_FG.as_bytes(), + colors::xterm::DecoOrange::ANSI_FG.as_bytes(), + colors::xterm::PaleGoldenrod::ANSI_FG.as_bytes(), + colors::xterm::AltoBeige::ANSI_FG.as_bytes(), + colors::xterm::FogPink::ANSI_FG.as_bytes(), + colors::xterm::ChartreuseYellow::ANSI_FG.as_bytes(), + colors::xterm::Canary::ANSI_FG.as_bytes(), + colors::xterm::Honeysuckle::ANSI_FG.as_bytes(), + colors::xterm::ReefPaleYellow::ANSI_FG.as_bytes(), + colors::xterm::SnowyMint::ANSI_FG.as_bytes(), + colors::xterm::OysterBay::ANSI_FG.as_bytes(), + colors::xterm::Red::ANSI_FG.as_bytes(), + colors::xterm::DarkRose::ANSI_FG.as_bytes(), + colors::xterm::Rose::ANSI_FG.as_bytes(), + colors::xterm::LightHollywoodCerise::ANSI_FG.as_bytes(), + colors::xterm::PurplePizzazz::ANSI_FG.as_bytes(), + colors::xterm::Fuchsia::ANSI_FG.as_bytes(), + colors::xterm::BlazeOrange::ANSI_FG.as_bytes(), + colors::xterm::BittersweetOrange::ANSI_FG.as_bytes(), + colors::xterm::WildWatermelon::ANSI_FG.as_bytes(), + colors::xterm::DarkHotPink::ANSI_FG.as_bytes(), + colors::xterm::HotPink::ANSI_FG.as_bytes(), + colors::xterm::PinkFlamingo::ANSI_FG.as_bytes(), + colors::xterm::FlushOrange::ANSI_FG.as_bytes(), + colors::xterm::Salmon::ANSI_FG.as_bytes(), + colors::xterm::VividTangerine::ANSI_FG.as_bytes(), + colors::xterm::PinkSalmon::ANSI_FG.as_bytes(), + colors::xterm::DarkLavenderRose::ANSI_FG.as_bytes(), + colors::xterm::BlushPink::ANSI_FG.as_bytes(), + colors::xterm::YellowSea::ANSI_FG.as_bytes(), + colors::xterm::TexasRose::ANSI_FG.as_bytes(), + colors::xterm::Tacao::ANSI_FG.as_bytes(), + colors::xterm::Sundown::ANSI_FG.as_bytes(), + colors::xterm::CottonCandy::ANSI_FG.as_bytes(), + colors::xterm::LavenderRose::ANSI_FG.as_bytes(), + colors::xterm::Gold::ANSI_FG.as_bytes(), + colors::xterm::Dandelion::ANSI_FG.as_bytes(), + colors::xterm::GrandisCaramel::ANSI_FG.as_bytes(), + colors::xterm::Caramel::ANSI_FG.as_bytes(), + colors::xterm::CosmosSalmon::ANSI_FG.as_bytes(), + colors::xterm::PinkLace::ANSI_FG.as_bytes(), + colors::xterm::Yellow::ANSI_FG.as_bytes(), + colors::xterm::LaserLemon::ANSI_FG.as_bytes(), + colors::xterm::DollyYellow::ANSI_FG.as_bytes(), + colors::xterm::PortafinoYellow::ANSI_FG.as_bytes(), + colors::xterm::Cumulus::ANSI_FG.as_bytes(), + colors::xterm::White::ANSI_FG.as_bytes(), + colors::xterm::DarkCodGray::ANSI_FG.as_bytes(), + colors::xterm::CodGray::ANSI_FG.as_bytes(), + colors::xterm::LightCodGray::ANSI_FG.as_bytes(), + colors::xterm::DarkMineShaft::ANSI_FG.as_bytes(), + colors::xterm::MineShaft::ANSI_FG.as_bytes(), + colors::xterm::LightMineShaft::ANSI_FG.as_bytes(), + colors::xterm::DarkTundora::ANSI_FG.as_bytes(), + colors::xterm::Tundora::ANSI_FG.as_bytes(), + colors::xterm::ScorpionGray::ANSI_FG.as_bytes(), + colors::xterm::DarkDoveGray::ANSI_FG.as_bytes(), + colors::xterm::DoveGray::ANSI_FG.as_bytes(), + colors::xterm::Boulder::ANSI_FG.as_bytes(), + colors::xterm::Gray::ANSI_FG.as_bytes(), + colors::xterm::LightGray::ANSI_FG.as_bytes(), + colors::xterm::DustyGray::ANSI_FG.as_bytes(), + colors::xterm::NobelGray::ANSI_FG.as_bytes(), + colors::xterm::DarkSilverChalice::ANSI_FG.as_bytes(), + colors::xterm::LightSilverChalice::ANSI_FG.as_bytes(), + colors::xterm::DarkSilver::ANSI_FG.as_bytes(), + colors::xterm::Silver::ANSI_FG.as_bytes(), + colors::xterm::DarkAlto::ANSI_FG.as_bytes(), + colors::xterm::Alto::ANSI_FG.as_bytes(), + colors::xterm::Mercury::ANSI_FG.as_bytes(), + colors::xterm::GalleryGray::ANSI_FG.as_bytes(), +]; #[rustfmt::skip] const CP437: [char; 256] = [ @@ -73,6 +331,7 @@ pub enum ByteCategory { #[non_exhaustive] pub enum CharacterTable { AsciiOnly, + Block, CP437, } @@ -108,15 +367,17 @@ impl Byte { } } - fn color(self) -> &'static [u8] { + fn color(self, character_table: CharacterTable) -> &'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, + match character_table { + CharacterTable::AsciiOnly | CharacterTable::CP437 => match self.category() { + Null => COLOR_NULL, + AsciiPrintable => COLOR_ASCII_PRINTABLE, + AsciiWhitespace => COLOR_ASCII_WHITESPACE, + AsciiOther => COLOR_ASCII_OTHER, + NonAscii => COLOR_NONASCII, + }, + CharacterTable::Block => COLORS_XTERM[self.0 as usize], } } @@ -131,7 +392,8 @@ impl Byte { AsciiOther => '•', NonAscii => '×', }, - CharacterTable::CP437 => CP437[self.0.to_ne_bytes()[0] as usize], + CharacterTable::CP437 => CP437[self.0 as usize], + CharacterTable::Block => '█', } } } @@ -327,6 +589,8 @@ pub struct Printer<'a, Writer: Write> { base_digits: u8, /// Whether to show groups in little or big endian format. endianness: Endianness, + /// The character table to reference for the character panel. + character_table: CharacterTable, } impl<'a, Writer: Write> Printer<'a, Writer> { @@ -380,6 +644,7 @@ impl<'a, Writer: Write> Printer<'a, Writer> { Base::Hexadecimal => 2, }, endianness, + character_table, } } @@ -495,9 +760,11 @@ impl<'a, Writer: Write> Printer<'a, Writer> { Squeezer::Print | Squeezer::Delete => self.writer.write_all(b" ")?, Squeezer::Ignore | Squeezer::Disabled => { if let Some(&b) = self.line_buf.get(i as usize) { - if self.show_color && self.curr_color != Some(Byte(b).color()) { - self.writer.write_all(Byte(b).color())?; - self.curr_color = Some(Byte(b).color()); + if self.show_color + && self.curr_color != Some(Byte(b).color(self.character_table)) + { + self.writer.write_all(Byte(b).color(self.character_table))?; + self.curr_color = Some(Byte(b).color(self.character_table)); } self.writer .write_all(self.byte_char_panel[b as usize].as_bytes())?; @@ -564,9 +831,9 @@ impl<'a, Writer: Write> Printer<'a, Writer> { if i % (self.group_size as usize) == 0 { self.writer.write_all(b" ")?; } - if self.show_color && self.curr_color != Some(Byte(b).color()) { - self.writer.write_all(Byte(b).color())?; - self.curr_color = Some(Byte(b).color()); + if self.show_color && self.curr_color != Some(Byte(b).color(self.character_table)) { + self.writer.write_all(Byte(b).color(self.character_table))?; + self.curr_color = Some(Byte(b).color(self.character_table)); } self.writer .write_all(self.byte_hex_panel[b as usize].as_bytes())?; diff --git a/src/main.rs b/src/main.rs index cbf452b..9117e45 100644 --- a/src/main.rs +++ b/src/main.rs @@ -216,12 +216,13 @@ fn run() -> Result<()> { Arg::new("character-table") .long("character-table") .value_name("FORMAT") - .value_parser(["codepage-437", "ascii-only"]) + .value_parser(["codepage-437", "ascii-only", "block"]) .default_value("ascii-only") .help( "The character table that should be used. 'ascii-only' \ - will show dots for non-ASCII characters, and 'codepage-437' \ - will use Code page 437 for those characters." + will show dots for non-ASCII characters, 'codepage-437' \ + will use Code page 437 for those characters, and 'block' \ + will show unique colored blocks for each byte." ), ) .arg( @@ -489,6 +490,7 @@ fn run() -> Result<()> { { "ascii-only" => CharacterTable::AsciiOnly, "codepage-437" => CharacterTable::CP437, + "block" => CharacterTable::Block, _ => unreachable!(), }; From 8d5b355b76d47fb4de962ecc0f6284c21414d693 Mon Sep 17 00:00:00 2001 From: Sharif Haason Date: Wed, 14 Jun 2023 15:27:05 -0400 Subject: [PATCH 12/18] Correct asterisk colorization --- src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5181804..901145c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -723,8 +723,7 @@ impl<'a, Writer: Write> Printer<'a, Writer> { if self.show_position_panel { match self.squeezer { Squeezer::Print => { - self.writer - .write_all(self.byte_char_panel[b'*' as usize].as_bytes())?; + self.writer.write_all(&[b'*'])?; if self.show_color { self.writer.write_all(COLOR_RESET)?; } From 7ef8e5aae49ec8fd83cf5182afdc064a099881d3 Mon Sep 17 00:00:00 2001 From: Sharif Haason Date: Wed, 14 Jun 2023 15:53:46 -0400 Subject: [PATCH 13/18] Add test for code page 437 --- tests/integration_tests.rs | 59 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index fc10dfa..a44c77c 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -618,3 +618,62 @@ mod base { ); } } + +mod character_table { + use super::hexyl; + use super::PrettyAssert; + + #[test] + fn codepage_437() { + hexyl() + .arg("hello_world_elf64") + .arg("--color=never") + .arg("--character-table=codepage-437") + .assert() + .success() + .pretty_stdout( + "┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐ +│00000000│ 7f 45 4c 46 02 01 01 00 ┊ 00 00 00 00 00 00 00 00 │⌂ELF☻☺☺⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│ +│00000010│ 02 00 3e 00 01 00 00 00 ┊ 00 10 40 00 00 00 00 00 │☻⋄>⋄☺⋄⋄⋄┊⋄►@⋄⋄⋄⋄⋄│ +│00000020│ 40 00 00 00 00 00 00 00 ┊ 28 20 00 00 00 00 00 00 │@⋄⋄⋄⋄⋄⋄⋄┊( ⋄⋄⋄⋄⋄⋄│ +│00000030│ 00 00 00 00 40 00 38 00 ┊ 03 00 40 00 04 00 03 00 │⋄⋄⋄⋄@⋄8⋄┊♥⋄@⋄♦⋄♥⋄│ +│00000040│ 01 00 00 00 04 00 00 00 ┊ 00 00 00 00 00 00 00 00 │☺⋄⋄⋄♦⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│ +│00000050│ 00 00 40 00 00 00 00 00 ┊ 00 00 40 00 00 00 00 00 │⋄⋄@⋄⋄⋄⋄⋄┊⋄⋄@⋄⋄⋄⋄⋄│ +│00000060│ e8 00 00 00 00 00 00 00 ┊ e8 00 00 00 00 00 00 00 │Φ⋄⋄⋄⋄⋄⋄⋄┊Φ⋄⋄⋄⋄⋄⋄⋄│ +│00000070│ 00 10 00 00 00 00 00 00 ┊ 01 00 00 00 05 00 00 00 │⋄►⋄⋄⋄⋄⋄⋄┊☺⋄⋄⋄♣⋄⋄⋄│ +│00000080│ 00 10 00 00 00 00 00 00 ┊ 00 10 40 00 00 00 00 00 │⋄►⋄⋄⋄⋄⋄⋄┊⋄►@⋄⋄⋄⋄⋄│ +│00000090│ 00 10 40 00 00 00 00 00 ┊ 1d 00 00 00 00 00 00 00 │⋄►@⋄⋄⋄⋄⋄┊↔⋄⋄⋄⋄⋄⋄⋄│ +│000000a0│ 1d 00 00 00 00 00 00 00 ┊ 00 10 00 00 00 00 00 00 │↔⋄⋄⋄⋄⋄⋄⋄┊⋄►⋄⋄⋄⋄⋄⋄│ +│000000b0│ 01 00 00 00 06 00 00 00 ┊ 00 20 00 00 00 00 00 00 │☺⋄⋄⋄♠⋄⋄⋄┊⋄ ⋄⋄⋄⋄⋄⋄│ +│000000c0│ 00 20 40 00 00 00 00 00 ┊ 00 20 40 00 00 00 00 00 │⋄ @⋄⋄⋄⋄⋄┊⋄ @⋄⋄⋄⋄⋄│ +│000000d0│ 0e 00 00 00 00 00 00 00 ┊ 0e 00 00 00 00 00 00 00 │♫⋄⋄⋄⋄⋄⋄⋄┊♫⋄⋄⋄⋄⋄⋄⋄│ +│000000e0│ 00 10 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │⋄►⋄⋄⋄⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│ +│000000f0│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│ +│* │ ┊ │ ┊ │ +│00001000│ ba 0e 00 00 00 b9 00 20 ┊ 40 00 bb 01 00 00 00 b8 │║♫⋄⋄⋄╣⋄ ┊@⋄╗☺⋄⋄⋄╕│ +│00001010│ 04 00 00 00 cd 80 b8 01 ┊ 00 00 00 cd 80 00 00 00 │♦⋄⋄⋄═Ç╕☺┊⋄⋄⋄═Ç⋄⋄⋄│ +│00001020│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│ +│* │ ┊ │ ┊ │ +│00002000│ 48 65 6c 6c 6f 2c 20 77 ┊ 6f 72 6c 64 21 0a 00 2e │Hello, w┊orld!◙⋄.│ +│00002010│ 73 68 73 74 72 74 61 62 ┊ 00 2e 74 65 78 74 00 2e │shstrtab┊⋄.text⋄.│ +│00002020│ 64 61 74 61 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │data⋄⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│ +│00002030│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│ +│* │ ┊ │ ┊ │ +│00002060│ 00 00 00 00 00 00 00 00 ┊ 0b 00 00 00 01 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊♂⋄⋄⋄☺⋄⋄⋄│ +│00002070│ 06 00 00 00 00 00 00 00 ┊ 00 10 40 00 00 00 00 00 │♠⋄⋄⋄⋄⋄⋄⋄┊⋄►@⋄⋄⋄⋄⋄│ +│00002080│ 00 10 00 00 00 00 00 00 ┊ 1d 00 00 00 00 00 00 00 │⋄►⋄⋄⋄⋄⋄⋄┊↔⋄⋄⋄⋄⋄⋄⋄│ +│00002090│ 00 00 00 00 00 00 00 00 ┊ 10 00 00 00 00 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊►⋄⋄⋄⋄⋄⋄⋄│ +│000020a0│ 00 00 00 00 00 00 00 00 ┊ 11 00 00 00 01 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊◄⋄⋄⋄☺⋄⋄⋄│ +│000020b0│ 03 00 00 00 00 00 00 00 ┊ 00 20 40 00 00 00 00 00 │♥⋄⋄⋄⋄⋄⋄⋄┊⋄ @⋄⋄⋄⋄⋄│ +│000020c0│ 00 20 00 00 00 00 00 00 ┊ 0e 00 00 00 00 00 00 00 │⋄ ⋄⋄⋄⋄⋄⋄┊♫⋄⋄⋄⋄⋄⋄⋄│ +│000020d0│ 00 00 00 00 00 00 00 00 ┊ 04 00 00 00 00 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊♦⋄⋄⋄⋄⋄⋄⋄│ +│000020e0│ 00 00 00 00 00 00 00 00 ┊ 01 00 00 00 03 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊☺⋄⋄⋄♥⋄⋄⋄│ +│000020f0│ 00 00 00 00 00 00 00 00 ┊ 00 00 00 00 00 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊⋄⋄⋄⋄⋄⋄⋄⋄│ +│00002100│ 0e 20 00 00 00 00 00 00 ┊ 17 00 00 00 00 00 00 00 │♫ ⋄⋄⋄⋄⋄⋄┊↨⋄⋄⋄⋄⋄⋄⋄│ +│00002110│ 00 00 00 00 00 00 00 00 ┊ 01 00 00 00 00 00 00 00 │⋄⋄⋄⋄⋄⋄⋄⋄┊☺⋄⋄⋄⋄⋄⋄⋄│ +│00002120│ 00 00 00 00 00 00 00 00 ┊ │⋄⋄⋄⋄⋄⋄⋄⋄┊ │ +└────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘ +", + ); + } +} From a0a7d6761f4e3292a6d1addd40ef338921522818 Mon Sep 17 00:00:00 2001 From: Sharif Haason Date: Wed, 14 Jun 2023 16:00:47 -0400 Subject: [PATCH 14/18] Refactor color components into new module --- src/colors.rs | 306 +++++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 309 +------------------------------------------------- 2 files changed, 308 insertions(+), 307 deletions(-) create mode 100644 src/colors.rs diff --git a/src/colors.rs b/src/colors.rs new file mode 100644 index 0000000..7a99e71 --- /dev/null +++ b/src/colors.rs @@ -0,0 +1,306 @@ +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_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(); +pub const COLOR_NONASCII: &[u8] = colors::Yellow::ANSI_FG.as_bytes(); +pub const COLOR_RESET: &[u8] = colors::Default::ANSI_FG.as_bytes(); +pub const COLORS_XTERM: [&[u8]; 256] = [ + colors::xterm::UserBlack::ANSI_FG.as_bytes(), + colors::xterm::UserRed::ANSI_FG.as_bytes(), + colors::xterm::UserGreen::ANSI_FG.as_bytes(), + colors::xterm::UserYellow::ANSI_FG.as_bytes(), + colors::xterm::UserBlue::ANSI_FG.as_bytes(), + colors::xterm::UserMagenta::ANSI_FG.as_bytes(), + colors::xterm::UserCyan::ANSI_FG.as_bytes(), + colors::xterm::UserWhite::ANSI_FG.as_bytes(), + colors::xterm::UserBrightBlack::ANSI_FG.as_bytes(), + colors::xterm::UserBrightRed::ANSI_FG.as_bytes(), + colors::xterm::UserBrightGreen::ANSI_FG.as_bytes(), + colors::xterm::UserBrightYellow::ANSI_FG.as_bytes(), + colors::xterm::UserBrightBlue::ANSI_FG.as_bytes(), + colors::xterm::UserBrightMagenta::ANSI_FG.as_bytes(), + colors::xterm::UserBrightCyan::ANSI_FG.as_bytes(), + colors::xterm::UserBrightWhite::ANSI_FG.as_bytes(), + colors::xterm::Black::ANSI_FG.as_bytes(), + colors::xterm::StratosBlue::ANSI_FG.as_bytes(), + colors::xterm::NavyBlue::ANSI_FG.as_bytes(), + colors::xterm::MidnightBlue::ANSI_FG.as_bytes(), + colors::xterm::DarkBlue::ANSI_FG.as_bytes(), + colors::xterm::Blue::ANSI_FG.as_bytes(), + colors::xterm::CamaroneGreen::ANSI_FG.as_bytes(), + colors::xterm::BlueStone::ANSI_FG.as_bytes(), + colors::xterm::OrientBlue::ANSI_FG.as_bytes(), + colors::xterm::EndeavourBlue::ANSI_FG.as_bytes(), + colors::xterm::ScienceBlue::ANSI_FG.as_bytes(), + colors::xterm::BlueRibbon::ANSI_FG.as_bytes(), + colors::xterm::JapaneseLaurel::ANSI_FG.as_bytes(), + colors::xterm::DeepSeaGreen::ANSI_FG.as_bytes(), + colors::xterm::Teal::ANSI_FG.as_bytes(), + colors::xterm::DeepCerulean::ANSI_FG.as_bytes(), + colors::xterm::LochmaraBlue::ANSI_FG.as_bytes(), + colors::xterm::AzureRadiance::ANSI_FG.as_bytes(), + colors::xterm::LightJapaneseLaurel::ANSI_FG.as_bytes(), + colors::xterm::Jade::ANSI_FG.as_bytes(), + colors::xterm::PersianGreen::ANSI_FG.as_bytes(), + colors::xterm::BondiBlue::ANSI_FG.as_bytes(), + colors::xterm::Cerulean::ANSI_FG.as_bytes(), + colors::xterm::LightAzureRadiance::ANSI_FG.as_bytes(), + colors::xterm::DarkGreen::ANSI_FG.as_bytes(), + colors::xterm::Malachite::ANSI_FG.as_bytes(), + colors::xterm::CaribbeanGreen::ANSI_FG.as_bytes(), + colors::xterm::LightCaribbeanGreen::ANSI_FG.as_bytes(), + colors::xterm::RobinEggBlue::ANSI_FG.as_bytes(), + colors::xterm::Aqua::ANSI_FG.as_bytes(), + colors::xterm::Green::ANSI_FG.as_bytes(), + colors::xterm::DarkSpringGreen::ANSI_FG.as_bytes(), + colors::xterm::SpringGreen::ANSI_FG.as_bytes(), + colors::xterm::LightSpringGreen::ANSI_FG.as_bytes(), + colors::xterm::BrightTurquoise::ANSI_FG.as_bytes(), + colors::xterm::Cyan::ANSI_FG.as_bytes(), + colors::xterm::Rosewood::ANSI_FG.as_bytes(), + colors::xterm::PompadourMagenta::ANSI_FG.as_bytes(), + colors::xterm::PigmentIndigo::ANSI_FG.as_bytes(), + colors::xterm::DarkPurple::ANSI_FG.as_bytes(), + colors::xterm::ElectricIndigo::ANSI_FG.as_bytes(), + colors::xterm::ElectricPurple::ANSI_FG.as_bytes(), + colors::xterm::VerdunGreen::ANSI_FG.as_bytes(), + colors::xterm::ScorpionOlive::ANSI_FG.as_bytes(), + colors::xterm::Lilac::ANSI_FG.as_bytes(), + colors::xterm::ScampiIndigo::ANSI_FG.as_bytes(), + colors::xterm::Indigo::ANSI_FG.as_bytes(), + colors::xterm::DarkCornflowerBlue::ANSI_FG.as_bytes(), + colors::xterm::DarkLimeade::ANSI_FG.as_bytes(), + colors::xterm::GladeGreen::ANSI_FG.as_bytes(), + colors::xterm::JuniperGreen::ANSI_FG.as_bytes(), + colors::xterm::HippieBlue::ANSI_FG.as_bytes(), + colors::xterm::HavelockBlue::ANSI_FG.as_bytes(), + colors::xterm::CornflowerBlue::ANSI_FG.as_bytes(), + colors::xterm::Limeade::ANSI_FG.as_bytes(), + colors::xterm::FernGreen::ANSI_FG.as_bytes(), + colors::xterm::SilverTree::ANSI_FG.as_bytes(), + colors::xterm::Tradewind::ANSI_FG.as_bytes(), + colors::xterm::ShakespeareBlue::ANSI_FG.as_bytes(), + colors::xterm::DarkMalibuBlue::ANSI_FG.as_bytes(), + colors::xterm::DarkBrightGreen::ANSI_FG.as_bytes(), + colors::xterm::DarkPastelGreen::ANSI_FG.as_bytes(), + colors::xterm::PastelGreen::ANSI_FG.as_bytes(), + colors::xterm::DownyTeal::ANSI_FG.as_bytes(), + colors::xterm::Viking::ANSI_FG.as_bytes(), + colors::xterm::MalibuBlue::ANSI_FG.as_bytes(), + colors::xterm::BrightGreen::ANSI_FG.as_bytes(), + colors::xterm::DarkScreaminGreen::ANSI_FG.as_bytes(), + colors::xterm::ScreaminGreen::ANSI_FG.as_bytes(), + colors::xterm::DarkAquamarine::ANSI_FG.as_bytes(), + colors::xterm::Aquamarine::ANSI_FG.as_bytes(), + colors::xterm::LightAquamarine::ANSI_FG.as_bytes(), + colors::xterm::Maroon::ANSI_FG.as_bytes(), + colors::xterm::DarkFreshEggplant::ANSI_FG.as_bytes(), + colors::xterm::LightFreshEggplant::ANSI_FG.as_bytes(), + colors::xterm::Purple::ANSI_FG.as_bytes(), + colors::xterm::ElectricViolet::ANSI_FG.as_bytes(), + colors::xterm::LightElectricViolet::ANSI_FG.as_bytes(), + colors::xterm::Brown::ANSI_FG.as_bytes(), + colors::xterm::CopperRose::ANSI_FG.as_bytes(), + colors::xterm::StrikemasterPurple::ANSI_FG.as_bytes(), + colors::xterm::DelugePurple::ANSI_FG.as_bytes(), + colors::xterm::DarkMediumPurple::ANSI_FG.as_bytes(), + colors::xterm::DarkHeliotropePurple::ANSI_FG.as_bytes(), + colors::xterm::Olive::ANSI_FG.as_bytes(), + colors::xterm::ClayCreekOlive::ANSI_FG.as_bytes(), + colors::xterm::DarkGray::ANSI_FG.as_bytes(), + colors::xterm::WildBlueYonder::ANSI_FG.as_bytes(), + colors::xterm::ChetwodeBlue::ANSI_FG.as_bytes(), + colors::xterm::SlateBlue::ANSI_FG.as_bytes(), + colors::xterm::LightLimeade::ANSI_FG.as_bytes(), + colors::xterm::ChelseaCucumber::ANSI_FG.as_bytes(), + colors::xterm::BayLeaf::ANSI_FG.as_bytes(), + colors::xterm::GulfStream::ANSI_FG.as_bytes(), + colors::xterm::PoloBlue::ANSI_FG.as_bytes(), + colors::xterm::LightMalibuBlue::ANSI_FG.as_bytes(), + colors::xterm::Pistachio::ANSI_FG.as_bytes(), + colors::xterm::LightPastelGreen::ANSI_FG.as_bytes(), + colors::xterm::DarkFeijoaGreen::ANSI_FG.as_bytes(), + colors::xterm::VistaBlue::ANSI_FG.as_bytes(), + colors::xterm::Bermuda::ANSI_FG.as_bytes(), + colors::xterm::DarkAnakiwaBlue::ANSI_FG.as_bytes(), + colors::xterm::ChartreuseGreen::ANSI_FG.as_bytes(), + colors::xterm::LightScreaminGreen::ANSI_FG.as_bytes(), + colors::xterm::DarkMintGreen::ANSI_FG.as_bytes(), + colors::xterm::MintGreen::ANSI_FG.as_bytes(), + colors::xterm::LighterAquamarine::ANSI_FG.as_bytes(), + colors::xterm::AnakiwaBlue::ANSI_FG.as_bytes(), + colors::xterm::BrightRed::ANSI_FG.as_bytes(), + colors::xterm::DarkFlirt::ANSI_FG.as_bytes(), + colors::xterm::Flirt::ANSI_FG.as_bytes(), + colors::xterm::LightFlirt::ANSI_FG.as_bytes(), + colors::xterm::DarkViolet::ANSI_FG.as_bytes(), + colors::xterm::BrightElectricViolet::ANSI_FG.as_bytes(), + colors::xterm::RoseofSharonOrange::ANSI_FG.as_bytes(), + colors::xterm::MatrixPink::ANSI_FG.as_bytes(), + colors::xterm::TapestryPink::ANSI_FG.as_bytes(), + colors::xterm::FuchsiaPink::ANSI_FG.as_bytes(), + colors::xterm::MediumPurple::ANSI_FG.as_bytes(), + colors::xterm::Heliotrope::ANSI_FG.as_bytes(), + colors::xterm::PirateGold::ANSI_FG.as_bytes(), + colors::xterm::MuesliOrange::ANSI_FG.as_bytes(), + colors::xterm::PharlapPink::ANSI_FG.as_bytes(), + colors::xterm::Bouquet::ANSI_FG.as_bytes(), + colors::xterm::Lavender::ANSI_FG.as_bytes(), + colors::xterm::LightHeliotrope::ANSI_FG.as_bytes(), + colors::xterm::BuddhaGold::ANSI_FG.as_bytes(), + colors::xterm::OliveGreen::ANSI_FG.as_bytes(), + colors::xterm::HillaryOlive::ANSI_FG.as_bytes(), + colors::xterm::SilverChalice::ANSI_FG.as_bytes(), + colors::xterm::WistfulLilac::ANSI_FG.as_bytes(), + colors::xterm::MelroseLilac::ANSI_FG.as_bytes(), + colors::xterm::RioGrandeGreen::ANSI_FG.as_bytes(), + colors::xterm::ConiferGreen::ANSI_FG.as_bytes(), + colors::xterm::Feijoa::ANSI_FG.as_bytes(), + colors::xterm::PixieGreen::ANSI_FG.as_bytes(), + colors::xterm::JungleMist::ANSI_FG.as_bytes(), + colors::xterm::LightAnakiwaBlue::ANSI_FG.as_bytes(), + colors::xterm::Lime::ANSI_FG.as_bytes(), + colors::xterm::GreenYellow::ANSI_FG.as_bytes(), + colors::xterm::LightMintGreen::ANSI_FG.as_bytes(), + colors::xterm::Celadon::ANSI_FG.as_bytes(), + colors::xterm::AeroBlue::ANSI_FG.as_bytes(), + colors::xterm::FrenchPassLightBlue::ANSI_FG.as_bytes(), + colors::xterm::GuardsmanRed::ANSI_FG.as_bytes(), + colors::xterm::RazzmatazzCerise::ANSI_FG.as_bytes(), + colors::xterm::MediumVioletRed::ANSI_FG.as_bytes(), + colors::xterm::HollywoodCerise::ANSI_FG.as_bytes(), + colors::xterm::DarkPurplePizzazz::ANSI_FG.as_bytes(), + colors::xterm::BrighterElectricViolet::ANSI_FG.as_bytes(), + colors::xterm::TennOrange::ANSI_FG.as_bytes(), + colors::xterm::RomanOrange::ANSI_FG.as_bytes(), + colors::xterm::CranberryPink::ANSI_FG.as_bytes(), + colors::xterm::HopbushPink::ANSI_FG.as_bytes(), + colors::xterm::Orchid::ANSI_FG.as_bytes(), + colors::xterm::LighterHeliotrope::ANSI_FG.as_bytes(), + colors::xterm::MangoTango::ANSI_FG.as_bytes(), + colors::xterm::Copperfield::ANSI_FG.as_bytes(), + colors::xterm::SeaPink::ANSI_FG.as_bytes(), + colors::xterm::CanCanPink::ANSI_FG.as_bytes(), + colors::xterm::LightOrchid::ANSI_FG.as_bytes(), + colors::xterm::BrightHeliotrope::ANSI_FG.as_bytes(), + colors::xterm::DarkCorn::ANSI_FG.as_bytes(), + colors::xterm::DarkTachaOrange::ANSI_FG.as_bytes(), + colors::xterm::TanBeige::ANSI_FG.as_bytes(), + colors::xterm::ClamShell::ANSI_FG.as_bytes(), + colors::xterm::ThistlePink::ANSI_FG.as_bytes(), + colors::xterm::Mauve::ANSI_FG.as_bytes(), + colors::xterm::Corn::ANSI_FG.as_bytes(), + colors::xterm::TachaOrange::ANSI_FG.as_bytes(), + colors::xterm::DecoOrange::ANSI_FG.as_bytes(), + colors::xterm::PaleGoldenrod::ANSI_FG.as_bytes(), + colors::xterm::AltoBeige::ANSI_FG.as_bytes(), + colors::xterm::FogPink::ANSI_FG.as_bytes(), + colors::xterm::ChartreuseYellow::ANSI_FG.as_bytes(), + colors::xterm::Canary::ANSI_FG.as_bytes(), + colors::xterm::Honeysuckle::ANSI_FG.as_bytes(), + colors::xterm::ReefPaleYellow::ANSI_FG.as_bytes(), + colors::xterm::SnowyMint::ANSI_FG.as_bytes(), + colors::xterm::OysterBay::ANSI_FG.as_bytes(), + colors::xterm::Red::ANSI_FG.as_bytes(), + colors::xterm::DarkRose::ANSI_FG.as_bytes(), + colors::xterm::Rose::ANSI_FG.as_bytes(), + colors::xterm::LightHollywoodCerise::ANSI_FG.as_bytes(), + colors::xterm::PurplePizzazz::ANSI_FG.as_bytes(), + colors::xterm::Fuchsia::ANSI_FG.as_bytes(), + colors::xterm::BlazeOrange::ANSI_FG.as_bytes(), + colors::xterm::BittersweetOrange::ANSI_FG.as_bytes(), + colors::xterm::WildWatermelon::ANSI_FG.as_bytes(), + colors::xterm::DarkHotPink::ANSI_FG.as_bytes(), + colors::xterm::HotPink::ANSI_FG.as_bytes(), + colors::xterm::PinkFlamingo::ANSI_FG.as_bytes(), + colors::xterm::FlushOrange::ANSI_FG.as_bytes(), + colors::xterm::Salmon::ANSI_FG.as_bytes(), + colors::xterm::VividTangerine::ANSI_FG.as_bytes(), + colors::xterm::PinkSalmon::ANSI_FG.as_bytes(), + colors::xterm::DarkLavenderRose::ANSI_FG.as_bytes(), + colors::xterm::BlushPink::ANSI_FG.as_bytes(), + colors::xterm::YellowSea::ANSI_FG.as_bytes(), + colors::xterm::TexasRose::ANSI_FG.as_bytes(), + colors::xterm::Tacao::ANSI_FG.as_bytes(), + colors::xterm::Sundown::ANSI_FG.as_bytes(), + colors::xterm::CottonCandy::ANSI_FG.as_bytes(), + colors::xterm::LavenderRose::ANSI_FG.as_bytes(), + colors::xterm::Gold::ANSI_FG.as_bytes(), + colors::xterm::Dandelion::ANSI_FG.as_bytes(), + colors::xterm::GrandisCaramel::ANSI_FG.as_bytes(), + colors::xterm::Caramel::ANSI_FG.as_bytes(), + colors::xterm::CosmosSalmon::ANSI_FG.as_bytes(), + colors::xterm::PinkLace::ANSI_FG.as_bytes(), + colors::xterm::Yellow::ANSI_FG.as_bytes(), + colors::xterm::LaserLemon::ANSI_FG.as_bytes(), + colors::xterm::DollyYellow::ANSI_FG.as_bytes(), + colors::xterm::PortafinoYellow::ANSI_FG.as_bytes(), + colors::xterm::Cumulus::ANSI_FG.as_bytes(), + colors::xterm::White::ANSI_FG.as_bytes(), + colors::xterm::DarkCodGray::ANSI_FG.as_bytes(), + colors::xterm::CodGray::ANSI_FG.as_bytes(), + colors::xterm::LightCodGray::ANSI_FG.as_bytes(), + colors::xterm::DarkMineShaft::ANSI_FG.as_bytes(), + colors::xterm::MineShaft::ANSI_FG.as_bytes(), + colors::xterm::LightMineShaft::ANSI_FG.as_bytes(), + colors::xterm::DarkTundora::ANSI_FG.as_bytes(), + colors::xterm::Tundora::ANSI_FG.as_bytes(), + colors::xterm::ScorpionGray::ANSI_FG.as_bytes(), + colors::xterm::DarkDoveGray::ANSI_FG.as_bytes(), + colors::xterm::DoveGray::ANSI_FG.as_bytes(), + colors::xterm::Boulder::ANSI_FG.as_bytes(), + colors::xterm::Gray::ANSI_FG.as_bytes(), + colors::xterm::LightGray::ANSI_FG.as_bytes(), + colors::xterm::DustyGray::ANSI_FG.as_bytes(), + colors::xterm::NobelGray::ANSI_FG.as_bytes(), + colors::xterm::DarkSilverChalice::ANSI_FG.as_bytes(), + colors::xterm::LightSilverChalice::ANSI_FG.as_bytes(), + colors::xterm::DarkSilver::ANSI_FG.as_bytes(), + colors::xterm::Silver::ANSI_FG.as_bytes(), + colors::xterm::DarkAlto::ANSI_FG.as_bytes(), + colors::xterm::Alto::ANSI_FG.as_bytes(), + colors::xterm::Mercury::ANSI_FG.as_bytes(), + colors::xterm::GalleryGray::ANSI_FG.as_bytes(), +]; + +#[rustfmt::skip] +pub const CP437: [char; 256] = [ + // Copyright (c) 2016, Delan Azabani + // + // Permission to use, copy, modify, and/or distribute this software for any + // purpose with or without fee is hereby granted, provided that the above + // copyright notice and this permission notice appear in all copies. + // + // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + // 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 ␀ + + // 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',':',';','<','=','>','?', + '@','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O', + 'P','Q','R','S','T','U','V','W','X','Y','Z','[','\\',']','^','_', + '`','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o', + 'p','q','r','s','t','u','v','w','x','y','z','{','|','}','~','⌂', + 'Ç','ü','é','â','ä','à','å','ç','ê','ë','è','ï','î','ì','Ä','Å', + 'É','æ','Æ','ô','ö','ò','û','ù','ÿ','Ö','Ü','¢','£','¥','₧','ƒ', + 'á','í','ó','ú','ñ','Ñ','ª','º','¿','⌐','¬','½','¼','¡','«','»', + '░','▒','▓','│','┤','╡','╢','╖','╕','╣','║','╗','╝','╜','╛','┐', + '└','┴','┬','├','─','┼','╞','╟','╚','╔','╩','╦','╠','═','╬','╧', + '╨','╤','╥','╙','╘','╒','╓','╫','╪','┘','┌','█','▄','▌','▐','▀', + 'α','ß','Γ','π','Σ','σ','µ','τ','Φ','Θ','Ω','δ','∞','φ','ε','∩', + '≡','±','≥','≤','⌠','⌡','÷','≈','°','∙','·','√','ⁿ','²','■','ff', +]; diff --git a/src/lib.rs b/src/lib.rs index 901145c..443222f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,11 +1,11 @@ +pub(crate) mod colors; pub(crate) mod input; +pub use colors::*; pub use input::*; use std::io::{self, BufReader, Read, Write}; -use owo_colors::{colors, Color}; - pub enum Base { Binary, Octal, @@ -13,311 +13,6 @@ pub enum Base { Hexadecimal, } -const COLOR_NULL: &[u8] = colors::BrightBlack::ANSI_FG.as_bytes(); -const COLOR_OFFSET: &[u8] = colors::BrightBlack::ANSI_FG.as_bytes(); -const COLOR_ASCII_PRINTABLE: &[u8] = colors::Cyan::ANSI_FG.as_bytes(); -const COLOR_ASCII_WHITESPACE: &[u8] = colors::Green::ANSI_FG.as_bytes(); -const COLOR_ASCII_OTHER: &[u8] = colors::Green::ANSI_FG.as_bytes(); -const COLOR_NONASCII: &[u8] = colors::Yellow::ANSI_FG.as_bytes(); -const COLOR_RESET: &[u8] = colors::Default::ANSI_FG.as_bytes(); -const COLORS_XTERM: [&[u8]; 256] = [ - colors::xterm::UserBlack::ANSI_FG.as_bytes(), - colors::xterm::UserRed::ANSI_FG.as_bytes(), - colors::xterm::UserGreen::ANSI_FG.as_bytes(), - colors::xterm::UserYellow::ANSI_FG.as_bytes(), - colors::xterm::UserBlue::ANSI_FG.as_bytes(), - colors::xterm::UserMagenta::ANSI_FG.as_bytes(), - colors::xterm::UserCyan::ANSI_FG.as_bytes(), - colors::xterm::UserWhite::ANSI_FG.as_bytes(), - colors::xterm::UserBrightBlack::ANSI_FG.as_bytes(), - colors::xterm::UserBrightRed::ANSI_FG.as_bytes(), - colors::xterm::UserBrightGreen::ANSI_FG.as_bytes(), - colors::xterm::UserBrightYellow::ANSI_FG.as_bytes(), - colors::xterm::UserBrightBlue::ANSI_FG.as_bytes(), - colors::xterm::UserBrightMagenta::ANSI_FG.as_bytes(), - colors::xterm::UserBrightCyan::ANSI_FG.as_bytes(), - colors::xterm::UserBrightWhite::ANSI_FG.as_bytes(), - colors::xterm::Black::ANSI_FG.as_bytes(), - colors::xterm::StratosBlue::ANSI_FG.as_bytes(), - colors::xterm::NavyBlue::ANSI_FG.as_bytes(), - colors::xterm::MidnightBlue::ANSI_FG.as_bytes(), - colors::xterm::DarkBlue::ANSI_FG.as_bytes(), - colors::xterm::Blue::ANSI_FG.as_bytes(), - colors::xterm::CamaroneGreen::ANSI_FG.as_bytes(), - colors::xterm::BlueStone::ANSI_FG.as_bytes(), - colors::xterm::OrientBlue::ANSI_FG.as_bytes(), - colors::xterm::EndeavourBlue::ANSI_FG.as_bytes(), - colors::xterm::ScienceBlue::ANSI_FG.as_bytes(), - colors::xterm::BlueRibbon::ANSI_FG.as_bytes(), - colors::xterm::JapaneseLaurel::ANSI_FG.as_bytes(), - colors::xterm::DeepSeaGreen::ANSI_FG.as_bytes(), - colors::xterm::Teal::ANSI_FG.as_bytes(), - colors::xterm::DeepCerulean::ANSI_FG.as_bytes(), - colors::xterm::LochmaraBlue::ANSI_FG.as_bytes(), - colors::xterm::AzureRadiance::ANSI_FG.as_bytes(), - colors::xterm::LightJapaneseLaurel::ANSI_FG.as_bytes(), - colors::xterm::Jade::ANSI_FG.as_bytes(), - colors::xterm::PersianGreen::ANSI_FG.as_bytes(), - colors::xterm::BondiBlue::ANSI_FG.as_bytes(), - colors::xterm::Cerulean::ANSI_FG.as_bytes(), - colors::xterm::LightAzureRadiance::ANSI_FG.as_bytes(), - colors::xterm::DarkGreen::ANSI_FG.as_bytes(), - colors::xterm::Malachite::ANSI_FG.as_bytes(), - colors::xterm::CaribbeanGreen::ANSI_FG.as_bytes(), - colors::xterm::LightCaribbeanGreen::ANSI_FG.as_bytes(), - colors::xterm::RobinEggBlue::ANSI_FG.as_bytes(), - colors::xterm::Aqua::ANSI_FG.as_bytes(), - colors::xterm::Green::ANSI_FG.as_bytes(), - colors::xterm::DarkSpringGreen::ANSI_FG.as_bytes(), - colors::xterm::SpringGreen::ANSI_FG.as_bytes(), - colors::xterm::LightSpringGreen::ANSI_FG.as_bytes(), - colors::xterm::BrightTurquoise::ANSI_FG.as_bytes(), - colors::xterm::Cyan::ANSI_FG.as_bytes(), - colors::xterm::Rosewood::ANSI_FG.as_bytes(), - colors::xterm::PompadourMagenta::ANSI_FG.as_bytes(), - colors::xterm::PigmentIndigo::ANSI_FG.as_bytes(), - colors::xterm::DarkPurple::ANSI_FG.as_bytes(), - colors::xterm::ElectricIndigo::ANSI_FG.as_bytes(), - colors::xterm::ElectricPurple::ANSI_FG.as_bytes(), - colors::xterm::VerdunGreen::ANSI_FG.as_bytes(), - colors::xterm::ScorpionOlive::ANSI_FG.as_bytes(), - colors::xterm::Lilac::ANSI_FG.as_bytes(), - colors::xterm::ScampiIndigo::ANSI_FG.as_bytes(), - colors::xterm::Indigo::ANSI_FG.as_bytes(), - colors::xterm::DarkCornflowerBlue::ANSI_FG.as_bytes(), - colors::xterm::DarkLimeade::ANSI_FG.as_bytes(), - colors::xterm::GladeGreen::ANSI_FG.as_bytes(), - colors::xterm::JuniperGreen::ANSI_FG.as_bytes(), - colors::xterm::HippieBlue::ANSI_FG.as_bytes(), - colors::xterm::HavelockBlue::ANSI_FG.as_bytes(), - colors::xterm::CornflowerBlue::ANSI_FG.as_bytes(), - colors::xterm::Limeade::ANSI_FG.as_bytes(), - colors::xterm::FernGreen::ANSI_FG.as_bytes(), - colors::xterm::SilverTree::ANSI_FG.as_bytes(), - colors::xterm::Tradewind::ANSI_FG.as_bytes(), - colors::xterm::ShakespeareBlue::ANSI_FG.as_bytes(), - colors::xterm::DarkMalibuBlue::ANSI_FG.as_bytes(), - colors::xterm::DarkBrightGreen::ANSI_FG.as_bytes(), - colors::xterm::DarkPastelGreen::ANSI_FG.as_bytes(), - colors::xterm::PastelGreen::ANSI_FG.as_bytes(), - colors::xterm::DownyTeal::ANSI_FG.as_bytes(), - colors::xterm::Viking::ANSI_FG.as_bytes(), - colors::xterm::MalibuBlue::ANSI_FG.as_bytes(), - colors::xterm::BrightGreen::ANSI_FG.as_bytes(), - colors::xterm::DarkScreaminGreen::ANSI_FG.as_bytes(), - colors::xterm::ScreaminGreen::ANSI_FG.as_bytes(), - colors::xterm::DarkAquamarine::ANSI_FG.as_bytes(), - colors::xterm::Aquamarine::ANSI_FG.as_bytes(), - colors::xterm::LightAquamarine::ANSI_FG.as_bytes(), - colors::xterm::Maroon::ANSI_FG.as_bytes(), - colors::xterm::DarkFreshEggplant::ANSI_FG.as_bytes(), - colors::xterm::LightFreshEggplant::ANSI_FG.as_bytes(), - colors::xterm::Purple::ANSI_FG.as_bytes(), - colors::xterm::ElectricViolet::ANSI_FG.as_bytes(), - colors::xterm::LightElectricViolet::ANSI_FG.as_bytes(), - colors::xterm::Brown::ANSI_FG.as_bytes(), - colors::xterm::CopperRose::ANSI_FG.as_bytes(), - colors::xterm::StrikemasterPurple::ANSI_FG.as_bytes(), - colors::xterm::DelugePurple::ANSI_FG.as_bytes(), - colors::xterm::DarkMediumPurple::ANSI_FG.as_bytes(), - colors::xterm::DarkHeliotropePurple::ANSI_FG.as_bytes(), - colors::xterm::Olive::ANSI_FG.as_bytes(), - colors::xterm::ClayCreekOlive::ANSI_FG.as_bytes(), - colors::xterm::DarkGray::ANSI_FG.as_bytes(), - colors::xterm::WildBlueYonder::ANSI_FG.as_bytes(), - colors::xterm::ChetwodeBlue::ANSI_FG.as_bytes(), - colors::xterm::SlateBlue::ANSI_FG.as_bytes(), - colors::xterm::LightLimeade::ANSI_FG.as_bytes(), - colors::xterm::ChelseaCucumber::ANSI_FG.as_bytes(), - colors::xterm::BayLeaf::ANSI_FG.as_bytes(), - colors::xterm::GulfStream::ANSI_FG.as_bytes(), - colors::xterm::PoloBlue::ANSI_FG.as_bytes(), - colors::xterm::LightMalibuBlue::ANSI_FG.as_bytes(), - colors::xterm::Pistachio::ANSI_FG.as_bytes(), - colors::xterm::LightPastelGreen::ANSI_FG.as_bytes(), - colors::xterm::DarkFeijoaGreen::ANSI_FG.as_bytes(), - colors::xterm::VistaBlue::ANSI_FG.as_bytes(), - colors::xterm::Bermuda::ANSI_FG.as_bytes(), - colors::xterm::DarkAnakiwaBlue::ANSI_FG.as_bytes(), - colors::xterm::ChartreuseGreen::ANSI_FG.as_bytes(), - colors::xterm::LightScreaminGreen::ANSI_FG.as_bytes(), - colors::xterm::DarkMintGreen::ANSI_FG.as_bytes(), - colors::xterm::MintGreen::ANSI_FG.as_bytes(), - colors::xterm::LighterAquamarine::ANSI_FG.as_bytes(), - colors::xterm::AnakiwaBlue::ANSI_FG.as_bytes(), - colors::xterm::BrightRed::ANSI_FG.as_bytes(), - colors::xterm::DarkFlirt::ANSI_FG.as_bytes(), - colors::xterm::Flirt::ANSI_FG.as_bytes(), - colors::xterm::LightFlirt::ANSI_FG.as_bytes(), - colors::xterm::DarkViolet::ANSI_FG.as_bytes(), - colors::xterm::BrightElectricViolet::ANSI_FG.as_bytes(), - colors::xterm::RoseofSharonOrange::ANSI_FG.as_bytes(), - colors::xterm::MatrixPink::ANSI_FG.as_bytes(), - colors::xterm::TapestryPink::ANSI_FG.as_bytes(), - colors::xterm::FuchsiaPink::ANSI_FG.as_bytes(), - colors::xterm::MediumPurple::ANSI_FG.as_bytes(), - colors::xterm::Heliotrope::ANSI_FG.as_bytes(), - colors::xterm::PirateGold::ANSI_FG.as_bytes(), - colors::xterm::MuesliOrange::ANSI_FG.as_bytes(), - colors::xterm::PharlapPink::ANSI_FG.as_bytes(), - colors::xterm::Bouquet::ANSI_FG.as_bytes(), - colors::xterm::Lavender::ANSI_FG.as_bytes(), - colors::xterm::LightHeliotrope::ANSI_FG.as_bytes(), - colors::xterm::BuddhaGold::ANSI_FG.as_bytes(), - colors::xterm::OliveGreen::ANSI_FG.as_bytes(), - colors::xterm::HillaryOlive::ANSI_FG.as_bytes(), - colors::xterm::SilverChalice::ANSI_FG.as_bytes(), - colors::xterm::WistfulLilac::ANSI_FG.as_bytes(), - colors::xterm::MelroseLilac::ANSI_FG.as_bytes(), - colors::xterm::RioGrandeGreen::ANSI_FG.as_bytes(), - colors::xterm::ConiferGreen::ANSI_FG.as_bytes(), - colors::xterm::Feijoa::ANSI_FG.as_bytes(), - colors::xterm::PixieGreen::ANSI_FG.as_bytes(), - colors::xterm::JungleMist::ANSI_FG.as_bytes(), - colors::xterm::LightAnakiwaBlue::ANSI_FG.as_bytes(), - colors::xterm::Lime::ANSI_FG.as_bytes(), - colors::xterm::GreenYellow::ANSI_FG.as_bytes(), - colors::xterm::LightMintGreen::ANSI_FG.as_bytes(), - colors::xterm::Celadon::ANSI_FG.as_bytes(), - colors::xterm::AeroBlue::ANSI_FG.as_bytes(), - colors::xterm::FrenchPassLightBlue::ANSI_FG.as_bytes(), - colors::xterm::GuardsmanRed::ANSI_FG.as_bytes(), - colors::xterm::RazzmatazzCerise::ANSI_FG.as_bytes(), - colors::xterm::MediumVioletRed::ANSI_FG.as_bytes(), - colors::xterm::HollywoodCerise::ANSI_FG.as_bytes(), - colors::xterm::DarkPurplePizzazz::ANSI_FG.as_bytes(), - colors::xterm::BrighterElectricViolet::ANSI_FG.as_bytes(), - colors::xterm::TennOrange::ANSI_FG.as_bytes(), - colors::xterm::RomanOrange::ANSI_FG.as_bytes(), - colors::xterm::CranberryPink::ANSI_FG.as_bytes(), - colors::xterm::HopbushPink::ANSI_FG.as_bytes(), - colors::xterm::Orchid::ANSI_FG.as_bytes(), - colors::xterm::LighterHeliotrope::ANSI_FG.as_bytes(), - colors::xterm::MangoTango::ANSI_FG.as_bytes(), - colors::xterm::Copperfield::ANSI_FG.as_bytes(), - colors::xterm::SeaPink::ANSI_FG.as_bytes(), - colors::xterm::CanCanPink::ANSI_FG.as_bytes(), - colors::xterm::LightOrchid::ANSI_FG.as_bytes(), - colors::xterm::BrightHeliotrope::ANSI_FG.as_bytes(), - colors::xterm::DarkCorn::ANSI_FG.as_bytes(), - colors::xterm::DarkTachaOrange::ANSI_FG.as_bytes(), - colors::xterm::TanBeige::ANSI_FG.as_bytes(), - colors::xterm::ClamShell::ANSI_FG.as_bytes(), - colors::xterm::ThistlePink::ANSI_FG.as_bytes(), - colors::xterm::Mauve::ANSI_FG.as_bytes(), - colors::xterm::Corn::ANSI_FG.as_bytes(), - colors::xterm::TachaOrange::ANSI_FG.as_bytes(), - colors::xterm::DecoOrange::ANSI_FG.as_bytes(), - colors::xterm::PaleGoldenrod::ANSI_FG.as_bytes(), - colors::xterm::AltoBeige::ANSI_FG.as_bytes(), - colors::xterm::FogPink::ANSI_FG.as_bytes(), - colors::xterm::ChartreuseYellow::ANSI_FG.as_bytes(), - colors::xterm::Canary::ANSI_FG.as_bytes(), - colors::xterm::Honeysuckle::ANSI_FG.as_bytes(), - colors::xterm::ReefPaleYellow::ANSI_FG.as_bytes(), - colors::xterm::SnowyMint::ANSI_FG.as_bytes(), - colors::xterm::OysterBay::ANSI_FG.as_bytes(), - colors::xterm::Red::ANSI_FG.as_bytes(), - colors::xterm::DarkRose::ANSI_FG.as_bytes(), - colors::xterm::Rose::ANSI_FG.as_bytes(), - colors::xterm::LightHollywoodCerise::ANSI_FG.as_bytes(), - colors::xterm::PurplePizzazz::ANSI_FG.as_bytes(), - colors::xterm::Fuchsia::ANSI_FG.as_bytes(), - colors::xterm::BlazeOrange::ANSI_FG.as_bytes(), - colors::xterm::BittersweetOrange::ANSI_FG.as_bytes(), - colors::xterm::WildWatermelon::ANSI_FG.as_bytes(), - colors::xterm::DarkHotPink::ANSI_FG.as_bytes(), - colors::xterm::HotPink::ANSI_FG.as_bytes(), - colors::xterm::PinkFlamingo::ANSI_FG.as_bytes(), - colors::xterm::FlushOrange::ANSI_FG.as_bytes(), - colors::xterm::Salmon::ANSI_FG.as_bytes(), - colors::xterm::VividTangerine::ANSI_FG.as_bytes(), - colors::xterm::PinkSalmon::ANSI_FG.as_bytes(), - colors::xterm::DarkLavenderRose::ANSI_FG.as_bytes(), - colors::xterm::BlushPink::ANSI_FG.as_bytes(), - colors::xterm::YellowSea::ANSI_FG.as_bytes(), - colors::xterm::TexasRose::ANSI_FG.as_bytes(), - colors::xterm::Tacao::ANSI_FG.as_bytes(), - colors::xterm::Sundown::ANSI_FG.as_bytes(), - colors::xterm::CottonCandy::ANSI_FG.as_bytes(), - colors::xterm::LavenderRose::ANSI_FG.as_bytes(), - colors::xterm::Gold::ANSI_FG.as_bytes(), - colors::xterm::Dandelion::ANSI_FG.as_bytes(), - colors::xterm::GrandisCaramel::ANSI_FG.as_bytes(), - colors::xterm::Caramel::ANSI_FG.as_bytes(), - colors::xterm::CosmosSalmon::ANSI_FG.as_bytes(), - colors::xterm::PinkLace::ANSI_FG.as_bytes(), - colors::xterm::Yellow::ANSI_FG.as_bytes(), - colors::xterm::LaserLemon::ANSI_FG.as_bytes(), - colors::xterm::DollyYellow::ANSI_FG.as_bytes(), - colors::xterm::PortafinoYellow::ANSI_FG.as_bytes(), - colors::xterm::Cumulus::ANSI_FG.as_bytes(), - colors::xterm::White::ANSI_FG.as_bytes(), - colors::xterm::DarkCodGray::ANSI_FG.as_bytes(), - colors::xterm::CodGray::ANSI_FG.as_bytes(), - colors::xterm::LightCodGray::ANSI_FG.as_bytes(), - colors::xterm::DarkMineShaft::ANSI_FG.as_bytes(), - colors::xterm::MineShaft::ANSI_FG.as_bytes(), - colors::xterm::LightMineShaft::ANSI_FG.as_bytes(), - colors::xterm::DarkTundora::ANSI_FG.as_bytes(), - colors::xterm::Tundora::ANSI_FG.as_bytes(), - colors::xterm::ScorpionGray::ANSI_FG.as_bytes(), - colors::xterm::DarkDoveGray::ANSI_FG.as_bytes(), - colors::xterm::DoveGray::ANSI_FG.as_bytes(), - colors::xterm::Boulder::ANSI_FG.as_bytes(), - colors::xterm::Gray::ANSI_FG.as_bytes(), - colors::xterm::LightGray::ANSI_FG.as_bytes(), - colors::xterm::DustyGray::ANSI_FG.as_bytes(), - colors::xterm::NobelGray::ANSI_FG.as_bytes(), - colors::xterm::DarkSilverChalice::ANSI_FG.as_bytes(), - colors::xterm::LightSilverChalice::ANSI_FG.as_bytes(), - colors::xterm::DarkSilver::ANSI_FG.as_bytes(), - colors::xterm::Silver::ANSI_FG.as_bytes(), - colors::xterm::DarkAlto::ANSI_FG.as_bytes(), - colors::xterm::Alto::ANSI_FG.as_bytes(), - colors::xterm::Mercury::ANSI_FG.as_bytes(), - colors::xterm::GalleryGray::ANSI_FG.as_bytes(), -]; - -#[rustfmt::skip] -const CP437: [char; 256] = [ - // Copyright (c) 2016, Delan Azabani - // - // Permission to use, copy, modify, and/or distribute this software for any - // purpose with or without fee is hereby granted, provided that the above - // copyright notice and this permission notice appear in all copies. - // - // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - // 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 ␀ - - // 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',':',';','<','=','>','?', - '@','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O', - 'P','Q','R','S','T','U','V','W','X','Y','Z','[','\\',']','^','_', - '`','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o', - 'p','q','r','s','t','u','v','w','x','y','z','{','|','}','~','⌂', - 'Ç','ü','é','â','ä','à','å','ç','ê','ë','è','ï','î','ì','Ä','Å', - 'É','æ','Æ','ô','ö','ò','û','ù','ÿ','Ö','Ü','¢','£','¥','₧','ƒ', - 'á','í','ó','ú','ñ','Ñ','ª','º','¿','⌐','¬','½','¼','¡','«','»', - '░','▒','▓','│','┤','╡','╢','╖','╕','╣','║','╗','╝','╜','╛','┐', - '└','┴','┬','├','─','┼','╞','╟','╚','╔','╩','╦','╠','═','╬','╧', - '╨','╤','╥','╙','╘','╒','╓','╫','╪','┘','┌','█','▄','▌','▐','▀', - 'α','ß','Γ','π','Σ','σ','µ','τ','Φ','Θ','Ω','δ','∞','φ','ε','∩', - '≡','±','≥','≤','⌠','⌡','÷','≈','°','∙','·','√','ⁿ','²','■','ff', -]; - #[derive(Copy, Clone)] pub enum ByteCategory { Null, From dfb5d57ee7ca9398eba07795019c68f5e0768793 Mon Sep 17 00:00:00 2001 From: Sharif Haason Date: Sun, 10 Dec 2023 13:15:43 -0500 Subject: [PATCH 15/18] Remove block coloring option for refactor --- src/colors.rs | 258 -------------------------------------------------- src/lib.rs | 3 - src/main.rs | 3 +- 3 files changed, 1 insertion(+), 263 deletions(-) diff --git a/src/colors.rs b/src/colors.rs index 7a99e71..748e6fb 100644 --- a/src/colors.rs +++ b/src/colors.rs @@ -7,264 +7,6 @@ pub const COLOR_ASCII_WHITESPACE: &[u8] = colors::Green::ANSI_FG.as_bytes(); pub const COLOR_ASCII_OTHER: &[u8] = colors::Green::ANSI_FG.as_bytes(); pub const COLOR_NONASCII: &[u8] = colors::Yellow::ANSI_FG.as_bytes(); pub const COLOR_RESET: &[u8] = colors::Default::ANSI_FG.as_bytes(); -pub const COLORS_XTERM: [&[u8]; 256] = [ - colors::xterm::UserBlack::ANSI_FG.as_bytes(), - colors::xterm::UserRed::ANSI_FG.as_bytes(), - colors::xterm::UserGreen::ANSI_FG.as_bytes(), - colors::xterm::UserYellow::ANSI_FG.as_bytes(), - colors::xterm::UserBlue::ANSI_FG.as_bytes(), - colors::xterm::UserMagenta::ANSI_FG.as_bytes(), - colors::xterm::UserCyan::ANSI_FG.as_bytes(), - colors::xterm::UserWhite::ANSI_FG.as_bytes(), - colors::xterm::UserBrightBlack::ANSI_FG.as_bytes(), - colors::xterm::UserBrightRed::ANSI_FG.as_bytes(), - colors::xterm::UserBrightGreen::ANSI_FG.as_bytes(), - colors::xterm::UserBrightYellow::ANSI_FG.as_bytes(), - colors::xterm::UserBrightBlue::ANSI_FG.as_bytes(), - colors::xterm::UserBrightMagenta::ANSI_FG.as_bytes(), - colors::xterm::UserBrightCyan::ANSI_FG.as_bytes(), - colors::xterm::UserBrightWhite::ANSI_FG.as_bytes(), - colors::xterm::Black::ANSI_FG.as_bytes(), - colors::xterm::StratosBlue::ANSI_FG.as_bytes(), - colors::xterm::NavyBlue::ANSI_FG.as_bytes(), - colors::xterm::MidnightBlue::ANSI_FG.as_bytes(), - colors::xterm::DarkBlue::ANSI_FG.as_bytes(), - colors::xterm::Blue::ANSI_FG.as_bytes(), - colors::xterm::CamaroneGreen::ANSI_FG.as_bytes(), - colors::xterm::BlueStone::ANSI_FG.as_bytes(), - colors::xterm::OrientBlue::ANSI_FG.as_bytes(), - colors::xterm::EndeavourBlue::ANSI_FG.as_bytes(), - colors::xterm::ScienceBlue::ANSI_FG.as_bytes(), - colors::xterm::BlueRibbon::ANSI_FG.as_bytes(), - colors::xterm::JapaneseLaurel::ANSI_FG.as_bytes(), - colors::xterm::DeepSeaGreen::ANSI_FG.as_bytes(), - colors::xterm::Teal::ANSI_FG.as_bytes(), - colors::xterm::DeepCerulean::ANSI_FG.as_bytes(), - colors::xterm::LochmaraBlue::ANSI_FG.as_bytes(), - colors::xterm::AzureRadiance::ANSI_FG.as_bytes(), - colors::xterm::LightJapaneseLaurel::ANSI_FG.as_bytes(), - colors::xterm::Jade::ANSI_FG.as_bytes(), - colors::xterm::PersianGreen::ANSI_FG.as_bytes(), - colors::xterm::BondiBlue::ANSI_FG.as_bytes(), - colors::xterm::Cerulean::ANSI_FG.as_bytes(), - colors::xterm::LightAzureRadiance::ANSI_FG.as_bytes(), - colors::xterm::DarkGreen::ANSI_FG.as_bytes(), - colors::xterm::Malachite::ANSI_FG.as_bytes(), - colors::xterm::CaribbeanGreen::ANSI_FG.as_bytes(), - colors::xterm::LightCaribbeanGreen::ANSI_FG.as_bytes(), - colors::xterm::RobinEggBlue::ANSI_FG.as_bytes(), - colors::xterm::Aqua::ANSI_FG.as_bytes(), - colors::xterm::Green::ANSI_FG.as_bytes(), - colors::xterm::DarkSpringGreen::ANSI_FG.as_bytes(), - colors::xterm::SpringGreen::ANSI_FG.as_bytes(), - colors::xterm::LightSpringGreen::ANSI_FG.as_bytes(), - colors::xterm::BrightTurquoise::ANSI_FG.as_bytes(), - colors::xterm::Cyan::ANSI_FG.as_bytes(), - colors::xterm::Rosewood::ANSI_FG.as_bytes(), - colors::xterm::PompadourMagenta::ANSI_FG.as_bytes(), - colors::xterm::PigmentIndigo::ANSI_FG.as_bytes(), - colors::xterm::DarkPurple::ANSI_FG.as_bytes(), - colors::xterm::ElectricIndigo::ANSI_FG.as_bytes(), - colors::xterm::ElectricPurple::ANSI_FG.as_bytes(), - colors::xterm::VerdunGreen::ANSI_FG.as_bytes(), - colors::xterm::ScorpionOlive::ANSI_FG.as_bytes(), - colors::xterm::Lilac::ANSI_FG.as_bytes(), - colors::xterm::ScampiIndigo::ANSI_FG.as_bytes(), - colors::xterm::Indigo::ANSI_FG.as_bytes(), - colors::xterm::DarkCornflowerBlue::ANSI_FG.as_bytes(), - colors::xterm::DarkLimeade::ANSI_FG.as_bytes(), - colors::xterm::GladeGreen::ANSI_FG.as_bytes(), - colors::xterm::JuniperGreen::ANSI_FG.as_bytes(), - colors::xterm::HippieBlue::ANSI_FG.as_bytes(), - colors::xterm::HavelockBlue::ANSI_FG.as_bytes(), - colors::xterm::CornflowerBlue::ANSI_FG.as_bytes(), - colors::xterm::Limeade::ANSI_FG.as_bytes(), - colors::xterm::FernGreen::ANSI_FG.as_bytes(), - colors::xterm::SilverTree::ANSI_FG.as_bytes(), - colors::xterm::Tradewind::ANSI_FG.as_bytes(), - colors::xterm::ShakespeareBlue::ANSI_FG.as_bytes(), - colors::xterm::DarkMalibuBlue::ANSI_FG.as_bytes(), - colors::xterm::DarkBrightGreen::ANSI_FG.as_bytes(), - colors::xterm::DarkPastelGreen::ANSI_FG.as_bytes(), - colors::xterm::PastelGreen::ANSI_FG.as_bytes(), - colors::xterm::DownyTeal::ANSI_FG.as_bytes(), - colors::xterm::Viking::ANSI_FG.as_bytes(), - colors::xterm::MalibuBlue::ANSI_FG.as_bytes(), - colors::xterm::BrightGreen::ANSI_FG.as_bytes(), - colors::xterm::DarkScreaminGreen::ANSI_FG.as_bytes(), - colors::xterm::ScreaminGreen::ANSI_FG.as_bytes(), - colors::xterm::DarkAquamarine::ANSI_FG.as_bytes(), - colors::xterm::Aquamarine::ANSI_FG.as_bytes(), - colors::xterm::LightAquamarine::ANSI_FG.as_bytes(), - colors::xterm::Maroon::ANSI_FG.as_bytes(), - colors::xterm::DarkFreshEggplant::ANSI_FG.as_bytes(), - colors::xterm::LightFreshEggplant::ANSI_FG.as_bytes(), - colors::xterm::Purple::ANSI_FG.as_bytes(), - colors::xterm::ElectricViolet::ANSI_FG.as_bytes(), - colors::xterm::LightElectricViolet::ANSI_FG.as_bytes(), - colors::xterm::Brown::ANSI_FG.as_bytes(), - colors::xterm::CopperRose::ANSI_FG.as_bytes(), - colors::xterm::StrikemasterPurple::ANSI_FG.as_bytes(), - colors::xterm::DelugePurple::ANSI_FG.as_bytes(), - colors::xterm::DarkMediumPurple::ANSI_FG.as_bytes(), - colors::xterm::DarkHeliotropePurple::ANSI_FG.as_bytes(), - colors::xterm::Olive::ANSI_FG.as_bytes(), - colors::xterm::ClayCreekOlive::ANSI_FG.as_bytes(), - colors::xterm::DarkGray::ANSI_FG.as_bytes(), - colors::xterm::WildBlueYonder::ANSI_FG.as_bytes(), - colors::xterm::ChetwodeBlue::ANSI_FG.as_bytes(), - colors::xterm::SlateBlue::ANSI_FG.as_bytes(), - colors::xterm::LightLimeade::ANSI_FG.as_bytes(), - colors::xterm::ChelseaCucumber::ANSI_FG.as_bytes(), - colors::xterm::BayLeaf::ANSI_FG.as_bytes(), - colors::xterm::GulfStream::ANSI_FG.as_bytes(), - colors::xterm::PoloBlue::ANSI_FG.as_bytes(), - colors::xterm::LightMalibuBlue::ANSI_FG.as_bytes(), - colors::xterm::Pistachio::ANSI_FG.as_bytes(), - colors::xterm::LightPastelGreen::ANSI_FG.as_bytes(), - colors::xterm::DarkFeijoaGreen::ANSI_FG.as_bytes(), - colors::xterm::VistaBlue::ANSI_FG.as_bytes(), - colors::xterm::Bermuda::ANSI_FG.as_bytes(), - colors::xterm::DarkAnakiwaBlue::ANSI_FG.as_bytes(), - colors::xterm::ChartreuseGreen::ANSI_FG.as_bytes(), - colors::xterm::LightScreaminGreen::ANSI_FG.as_bytes(), - colors::xterm::DarkMintGreen::ANSI_FG.as_bytes(), - colors::xterm::MintGreen::ANSI_FG.as_bytes(), - colors::xterm::LighterAquamarine::ANSI_FG.as_bytes(), - colors::xterm::AnakiwaBlue::ANSI_FG.as_bytes(), - colors::xterm::BrightRed::ANSI_FG.as_bytes(), - colors::xterm::DarkFlirt::ANSI_FG.as_bytes(), - colors::xterm::Flirt::ANSI_FG.as_bytes(), - colors::xterm::LightFlirt::ANSI_FG.as_bytes(), - colors::xterm::DarkViolet::ANSI_FG.as_bytes(), - colors::xterm::BrightElectricViolet::ANSI_FG.as_bytes(), - colors::xterm::RoseofSharonOrange::ANSI_FG.as_bytes(), - colors::xterm::MatrixPink::ANSI_FG.as_bytes(), - colors::xterm::TapestryPink::ANSI_FG.as_bytes(), - colors::xterm::FuchsiaPink::ANSI_FG.as_bytes(), - colors::xterm::MediumPurple::ANSI_FG.as_bytes(), - colors::xterm::Heliotrope::ANSI_FG.as_bytes(), - colors::xterm::PirateGold::ANSI_FG.as_bytes(), - colors::xterm::MuesliOrange::ANSI_FG.as_bytes(), - colors::xterm::PharlapPink::ANSI_FG.as_bytes(), - colors::xterm::Bouquet::ANSI_FG.as_bytes(), - colors::xterm::Lavender::ANSI_FG.as_bytes(), - colors::xterm::LightHeliotrope::ANSI_FG.as_bytes(), - colors::xterm::BuddhaGold::ANSI_FG.as_bytes(), - colors::xterm::OliveGreen::ANSI_FG.as_bytes(), - colors::xterm::HillaryOlive::ANSI_FG.as_bytes(), - colors::xterm::SilverChalice::ANSI_FG.as_bytes(), - colors::xterm::WistfulLilac::ANSI_FG.as_bytes(), - colors::xterm::MelroseLilac::ANSI_FG.as_bytes(), - colors::xterm::RioGrandeGreen::ANSI_FG.as_bytes(), - colors::xterm::ConiferGreen::ANSI_FG.as_bytes(), - colors::xterm::Feijoa::ANSI_FG.as_bytes(), - colors::xterm::PixieGreen::ANSI_FG.as_bytes(), - colors::xterm::JungleMist::ANSI_FG.as_bytes(), - colors::xterm::LightAnakiwaBlue::ANSI_FG.as_bytes(), - colors::xterm::Lime::ANSI_FG.as_bytes(), - colors::xterm::GreenYellow::ANSI_FG.as_bytes(), - colors::xterm::LightMintGreen::ANSI_FG.as_bytes(), - colors::xterm::Celadon::ANSI_FG.as_bytes(), - colors::xterm::AeroBlue::ANSI_FG.as_bytes(), - colors::xterm::FrenchPassLightBlue::ANSI_FG.as_bytes(), - colors::xterm::GuardsmanRed::ANSI_FG.as_bytes(), - colors::xterm::RazzmatazzCerise::ANSI_FG.as_bytes(), - colors::xterm::MediumVioletRed::ANSI_FG.as_bytes(), - colors::xterm::HollywoodCerise::ANSI_FG.as_bytes(), - colors::xterm::DarkPurplePizzazz::ANSI_FG.as_bytes(), - colors::xterm::BrighterElectricViolet::ANSI_FG.as_bytes(), - colors::xterm::TennOrange::ANSI_FG.as_bytes(), - colors::xterm::RomanOrange::ANSI_FG.as_bytes(), - colors::xterm::CranberryPink::ANSI_FG.as_bytes(), - colors::xterm::HopbushPink::ANSI_FG.as_bytes(), - colors::xterm::Orchid::ANSI_FG.as_bytes(), - colors::xterm::LighterHeliotrope::ANSI_FG.as_bytes(), - colors::xterm::MangoTango::ANSI_FG.as_bytes(), - colors::xterm::Copperfield::ANSI_FG.as_bytes(), - colors::xterm::SeaPink::ANSI_FG.as_bytes(), - colors::xterm::CanCanPink::ANSI_FG.as_bytes(), - colors::xterm::LightOrchid::ANSI_FG.as_bytes(), - colors::xterm::BrightHeliotrope::ANSI_FG.as_bytes(), - colors::xterm::DarkCorn::ANSI_FG.as_bytes(), - colors::xterm::DarkTachaOrange::ANSI_FG.as_bytes(), - colors::xterm::TanBeige::ANSI_FG.as_bytes(), - colors::xterm::ClamShell::ANSI_FG.as_bytes(), - colors::xterm::ThistlePink::ANSI_FG.as_bytes(), - colors::xterm::Mauve::ANSI_FG.as_bytes(), - colors::xterm::Corn::ANSI_FG.as_bytes(), - colors::xterm::TachaOrange::ANSI_FG.as_bytes(), - colors::xterm::DecoOrange::ANSI_FG.as_bytes(), - colors::xterm::PaleGoldenrod::ANSI_FG.as_bytes(), - colors::xterm::AltoBeige::ANSI_FG.as_bytes(), - colors::xterm::FogPink::ANSI_FG.as_bytes(), - colors::xterm::ChartreuseYellow::ANSI_FG.as_bytes(), - colors::xterm::Canary::ANSI_FG.as_bytes(), - colors::xterm::Honeysuckle::ANSI_FG.as_bytes(), - colors::xterm::ReefPaleYellow::ANSI_FG.as_bytes(), - colors::xterm::SnowyMint::ANSI_FG.as_bytes(), - colors::xterm::OysterBay::ANSI_FG.as_bytes(), - colors::xterm::Red::ANSI_FG.as_bytes(), - colors::xterm::DarkRose::ANSI_FG.as_bytes(), - colors::xterm::Rose::ANSI_FG.as_bytes(), - colors::xterm::LightHollywoodCerise::ANSI_FG.as_bytes(), - colors::xterm::PurplePizzazz::ANSI_FG.as_bytes(), - colors::xterm::Fuchsia::ANSI_FG.as_bytes(), - colors::xterm::BlazeOrange::ANSI_FG.as_bytes(), - colors::xterm::BittersweetOrange::ANSI_FG.as_bytes(), - colors::xterm::WildWatermelon::ANSI_FG.as_bytes(), - colors::xterm::DarkHotPink::ANSI_FG.as_bytes(), - colors::xterm::HotPink::ANSI_FG.as_bytes(), - colors::xterm::PinkFlamingo::ANSI_FG.as_bytes(), - colors::xterm::FlushOrange::ANSI_FG.as_bytes(), - colors::xterm::Salmon::ANSI_FG.as_bytes(), - colors::xterm::VividTangerine::ANSI_FG.as_bytes(), - colors::xterm::PinkSalmon::ANSI_FG.as_bytes(), - colors::xterm::DarkLavenderRose::ANSI_FG.as_bytes(), - colors::xterm::BlushPink::ANSI_FG.as_bytes(), - colors::xterm::YellowSea::ANSI_FG.as_bytes(), - colors::xterm::TexasRose::ANSI_FG.as_bytes(), - colors::xterm::Tacao::ANSI_FG.as_bytes(), - colors::xterm::Sundown::ANSI_FG.as_bytes(), - colors::xterm::CottonCandy::ANSI_FG.as_bytes(), - colors::xterm::LavenderRose::ANSI_FG.as_bytes(), - colors::xterm::Gold::ANSI_FG.as_bytes(), - colors::xterm::Dandelion::ANSI_FG.as_bytes(), - colors::xterm::GrandisCaramel::ANSI_FG.as_bytes(), - colors::xterm::Caramel::ANSI_FG.as_bytes(), - colors::xterm::CosmosSalmon::ANSI_FG.as_bytes(), - colors::xterm::PinkLace::ANSI_FG.as_bytes(), - colors::xterm::Yellow::ANSI_FG.as_bytes(), - colors::xterm::LaserLemon::ANSI_FG.as_bytes(), - colors::xterm::DollyYellow::ANSI_FG.as_bytes(), - colors::xterm::PortafinoYellow::ANSI_FG.as_bytes(), - colors::xterm::Cumulus::ANSI_FG.as_bytes(), - colors::xterm::White::ANSI_FG.as_bytes(), - colors::xterm::DarkCodGray::ANSI_FG.as_bytes(), - colors::xterm::CodGray::ANSI_FG.as_bytes(), - colors::xterm::LightCodGray::ANSI_FG.as_bytes(), - colors::xterm::DarkMineShaft::ANSI_FG.as_bytes(), - colors::xterm::MineShaft::ANSI_FG.as_bytes(), - colors::xterm::LightMineShaft::ANSI_FG.as_bytes(), - colors::xterm::DarkTundora::ANSI_FG.as_bytes(), - colors::xterm::Tundora::ANSI_FG.as_bytes(), - colors::xterm::ScorpionGray::ANSI_FG.as_bytes(), - colors::xterm::DarkDoveGray::ANSI_FG.as_bytes(), - colors::xterm::DoveGray::ANSI_FG.as_bytes(), - colors::xterm::Boulder::ANSI_FG.as_bytes(), - colors::xterm::Gray::ANSI_FG.as_bytes(), - colors::xterm::LightGray::ANSI_FG.as_bytes(), - colors::xterm::DustyGray::ANSI_FG.as_bytes(), - colors::xterm::NobelGray::ANSI_FG.as_bytes(), - colors::xterm::DarkSilverChalice::ANSI_FG.as_bytes(), - colors::xterm::LightSilverChalice::ANSI_FG.as_bytes(), - colors::xterm::DarkSilver::ANSI_FG.as_bytes(), - colors::xterm::Silver::ANSI_FG.as_bytes(), - colors::xterm::DarkAlto::ANSI_FG.as_bytes(), - colors::xterm::Alto::ANSI_FG.as_bytes(), - colors::xterm::Mercury::ANSI_FG.as_bytes(), - colors::xterm::GalleryGray::ANSI_FG.as_bytes(), -]; #[rustfmt::skip] pub const CP437: [char; 256] = [ diff --git a/src/lib.rs b/src/lib.rs index 443222f..f06df56 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,7 +26,6 @@ pub enum ByteCategory { #[non_exhaustive] pub enum CharacterTable { AsciiOnly, - Block, CP437, } @@ -72,7 +71,6 @@ impl Byte { AsciiOther => COLOR_ASCII_OTHER, NonAscii => COLOR_NONASCII, }, - CharacterTable::Block => COLORS_XTERM[self.0 as usize], } } @@ -88,7 +86,6 @@ impl Byte { NonAscii => '×', }, CharacterTable::CP437 => CP437[self.0 as usize], - CharacterTable::Block => '█', } } } diff --git a/src/main.rs b/src/main.rs index 9117e45..b99469f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -216,7 +216,7 @@ fn run() -> Result<()> { Arg::new("character-table") .long("character-table") .value_name("FORMAT") - .value_parser(["codepage-437", "ascii-only", "block"]) + .value_parser(["codepage-437", "ascii-only"]) .default_value("ascii-only") .help( "The character table that should be used. 'ascii-only' \ @@ -490,7 +490,6 @@ fn run() -> Result<()> { { "ascii-only" => CharacterTable::AsciiOnly, "codepage-437" => CharacterTable::CP437, - "block" => CharacterTable::Block, _ => unreachable!(), }; From 7ca00279ed2dd791d4a5d7233bb9828428d1dcc9 Mon Sep 17 00:00:00 2001 From: Sharif Haason Date: Sun, 10 Dec 2023 13:18:25 -0500 Subject: [PATCH 16/18] Correct docs --- src/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index b99469f..2d1d8d7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -221,8 +221,7 @@ fn run() -> Result<()> { .help( "The character table that should be used. 'ascii-only' \ will show dots for non-ASCII characters, 'codepage-437' \ - will use Code page 437 for those characters, and 'block' \ - will show unique colored blocks for each byte." + will use Code page 437 for those characters." ), ) .arg( From a56b3b0c462b992ddc6409656c6c8a01692c078b Mon Sep 17 00:00:00 2001 From: Sharif Haason Date: Mon, 11 Dec 2023 13:32:46 -0500 Subject: [PATCH 17/18] Adjust color function to not include character_table --- src/lib.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index f06df56..32f55a1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,16 +61,14 @@ impl Byte { } } - fn color(self, character_table: CharacterTable) -> &'static [u8] { + fn color(self) -> &'static [u8] { use crate::ByteCategory::*; - match character_table { - CharacterTable::AsciiOnly | CharacterTable::CP437 => match self.category() { - Null => COLOR_NULL, - AsciiPrintable => COLOR_ASCII_PRINTABLE, - AsciiWhitespace => COLOR_ASCII_WHITESPACE, - AsciiOther => COLOR_ASCII_OTHER, - NonAscii => COLOR_NONASCII, - }, + match self.category() { + Null => COLOR_NULL, + AsciiPrintable => COLOR_ASCII_PRINTABLE, + AsciiWhitespace => COLOR_ASCII_WHITESPACE, + AsciiOther => COLOR_ASCII_OTHER, + NonAscii => COLOR_NONASCII, } } From 1310b1d19ed3fd8c63ec002689619934d7de9def Mon Sep 17 00:00:00 2001 From: Sharif Haason Date: Mon, 11 Dec 2023 13:33:44 -0500 Subject: [PATCH 18/18] Adjust color function to not take character_table as arg --- src/lib.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 32f55a1..145f46d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -449,11 +449,9 @@ impl<'a, Writer: Write> Printer<'a, Writer> { Squeezer::Print | Squeezer::Delete => self.writer.write_all(b" ")?, Squeezer::Ignore | Squeezer::Disabled => { if let Some(&b) = self.line_buf.get(i as usize) { - if self.show_color - && self.curr_color != Some(Byte(b).color(self.character_table)) - { - self.writer.write_all(Byte(b).color(self.character_table))?; - self.curr_color = Some(Byte(b).color(self.character_table)); + if self.show_color && self.curr_color != Some(Byte(b).color()) { + self.writer.write_all(Byte(b).color())?; + self.curr_color = Some(Byte(b).color()); } self.writer .write_all(self.byte_char_panel[b as usize].as_bytes())?; @@ -520,9 +518,9 @@ impl<'a, Writer: Write> Printer<'a, Writer> { if i % (self.group_size as usize) == 0 { self.writer.write_all(b" ")?; } - if self.show_color && self.curr_color != Some(Byte(b).color(self.character_table)) { - self.writer.write_all(Byte(b).color(self.character_table))?; - self.curr_color = Some(Byte(b).color(self.character_table)); + if self.show_color && self.curr_color != Some(Byte(b).color()) { + self.writer.write_all(Byte(b).color())?; + self.curr_color = Some(Byte(b).color()); } self.writer .write_all(self.byte_hex_panel[b as usize].as_bytes())?;