-
-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement character table control and codepage 437 option #195
Conversation
Wow! That was fast 😄 Thank you so much.
I think I saw a MIT license in the repository earlier today? If so, I would just copy the license text verbatim and paste it into a comment preceding the table. And add a reference to the original source file + author, if not present in the license text. Maybe let's also describe the manual modifications we did in that comment. |
Nice! I’m glad this idea is catching on. Note that ␀ is already a printable character, since it’s U+2400 SYMBOL FOR NULL rather than U+0000 NULL. In fact, the whole range U+2400 through U+241F are printable representations of the C0 controls U+0000 through U+001F, though I chose to use the cp437 dingbats for the others. ⋄ probably makes more sense for hexyl though :) FFh is also visually indistinguishable from 20h in this table, so for the Rewind path interpreter, we used U+FB00 LATIN SMALL LIGATURE FF (ff) for FFh. |
Thank you very much for commenting here and for the original idea! A while ago, I built binocle, which uses a similar idea in a graphical application (distinctly colored pixels for each byte), but I never thought about translating this idea to the character panel of I'm now thinking that it might also be cool to have a mode in
We use (some of) those U+2400 … U+241F symbols in
@sharifhsn I think we should integrate the same adaptation here, if you agree? |
Makes sense.
Ditto.
Great idea! I've implemented this using the |
This is so cool. Especially when combined with But I would appreciated if we could focus this PR on We can then explore the colorization part in a separate PR. |
I added a test for code page 437, and I've fixed the issue with the asterisk, which was a leftover bug from my original implementation anyway 😅 I've also refactored the color components into a new module, since they're taking up a lot of visual space and have separated concerns anyway. With regards to performance, preliminary benchmarks show that performance is within noise for the default case and for code page 437, and significantly slower with block coloring (due to the fact that the color changes every single byte).
With regards to colorization and the block table, it's all the same machinery. I would prefer to push this all in one PR unless there's some outstanding issue with the block table that can't be resolved quickly. |
Thank you for the updates. I would still prefer to move the colorization part to a new PR. |
Co-authored-by: David Peter <sharkdp@users.noreply.github.com>
@sharkdp The colorization of characters has been factored out. This PR should be ready to merge. |
src/lib.rs
Outdated
@@ -62,28 +61,31 @@ impl Byte { | |||
} | |||
} | |||
|
|||
fn color(self) -> &'static [u8] { | |||
fn color(self, character_table: CharacterTable) -> &'static [u8] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need the character_table
parameter here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is left over from when I included distinct colored blocks as a character table option. I'll remove it now, good catch!
@@ -401,8 +415,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'*'])?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please explain this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a leftover bug from my initial design. Originally, the colored characters were pre-colored and cached ahead of time. I changed the way that coloring works in #176 to write prefix color codes separately from the characters themselves. The caching is now unnecessary here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much! Just two minor questions.
Implements #194
Additional comments: