News for hackers. Stuff that matters.
Re:Hexyl: A command-line hex viewer by Twisol on Wednesday January 09, 2019 @10:25AM (#18865354)
I admit, my first thought on seeing the title was "What's wrong with xxd?"

This is nice! I like the colorization a lot -- it's like with source code, you don't realize how much you rely on the colors until you get a new computer and need to download syntax definitions for your editor again. Only feature I really think is missing is line numbers.

Nicely done!

Re:Hexyl: A command-line hex viewer by kbd on Wednesday January 09, 2019 @10:51AM (#18865626)
> I admit, my first thought on seeing the title was "What's wrong with xxd?"

My first thought too. Then I looked and saw it was nice, and then I noticed it's by sharkdp. He really has a knack for improving on things you thought were fine (fd and bat being other examples).

Re:Hexyl: A command-line hex viewer by avidal on Wednesday January 09, 2019 @11:09AM (#18865808)
Looks like the screenshots on Github are outdated. I just ran it locally and it does print out offsets in a new left-most column.

edit: Added in this commit: https://github.com/sharkdp/hexyl/commit/91a119f4537f746045c8...

Re:Hexyl: A command-line hex viewer by cyberferret on Wednesday January 09, 2019 @05:18PM (#18869568)
Since back in my DOS programming days, I've lived in several different Hex editors when analysing data streams. Some great, some ordinary. I would have killed for colour highlighting like Hexyl seems to have.

I wonder though, whether I can colour code 'blocks' to differentiate them? One of the things I seemed to do a lot in hex editors was to check out the differentiation in, for example, 72 byte blocks of data, so to be able to delineate 72 byte blocks in different colours in the hex editor would make it easier to see where each block starts/ends.

Re:Hexyl: A command-line hex viewer by hwj on Wednesday January 09, 2019 @10:39AM (#18865493)
What are line numbers in context of a binary?
Re:Hexyl: A command-line hex viewer by Twisol on Wednesday January 09, 2019 @10:46AM (#18865574)
Right, I was being a bit loose there. I meant something like how `xxd` displays the number of bytes up to the current output row. Just something to give context of where you are in the file.

    00006980: 0000 0000 0000 0000 0000 0000 0000 0000
Re:Hexyl: A command-line hex viewer by msravi on Wednesday January 09, 2019 @10:50AM (#18865622)
You can quickly find position of byte number X using:

line number = floor(X/(bytes/line)) + 1

column offset = X % (bytes/line) + 1

Or it could just print byte numbers instead of line numbers.

Re:Hexyl: A command-line hex viewer by twtw on Wednesday January 09, 2019 @10:46AM (#18865573)
Addresses.
Re:Hexyl: A command-line hex viewer by archgoon on Wednesday January 09, 2019 @11:05AM (#18865766)
File offsets; not addresses :) I assume the tool isn't reading ELF format files and working out the memory address.
Re:Hexyl: A command-line hex viewer by vectorEQ on Wednesday January 09, 2019 @10:31AM (#18865403)
haha, had exactly the same thoughts. the colours really makes it much much easier on the eyes to recognise things. well done!
Re:Hexyl: A command-line hex viewer by joshenders on Wednesday January 09, 2019 @10:34AM (#18865431)
Same thought except, I wonder why this isn’t a patch to xxd?
Re:Hexyl: A command-line hex viewer by Sean1708 on Wednesday January 09, 2019 @11:39AM (#18866124)
I'm struggling to even find the canonical source code for xxd, let alone a way to provide a patch. You could probably email the address in the man page, but that's from 1997 so I wouldn't be too optimistic about getting a response. And even then it's quite likely that the original author considers xxd finished and would be reluctant to accept patches for it anyway. On top of all that the hard part of this work (cross-platform terminal colours) had already been done for the author, so the implementation was probably far easier than adding colour output to xxd would have been.
Re:Hexyl: A command-line hex viewer by kazinator on Wednesday January 09, 2019 @02:29PM (#18867945)
xxd is distributed with Vim.

I've never thought of xxd as being anything but a "Vim thing".

That it had its own history (1990-1998) before being pulled into Vim is a TIL for me.

Here you go:

https://github.com/vim/vim/tree/master/src/xxd

There might still be other versions of this out there, but I suspect most OS distros pick up xxd by way of packaging Vim.

So if you work on some other xxd, you're probably in a dead fork.

The man page is also from Vim:

https://github.com/vim/vim/blob/master/runtime/doc/xxd.1

My first patch to xxd, if I were to work on it, would be to fix the man page to indicate clearly that it's the xxd bundled with Vim.

Re:Hexyl: A command-line hex viewer by msla on Wednesday January 09, 2019 @11:58AM (#18866329)
Cross-platform terminal coloring was solved in the 1980s with termcap and then terminfo, for every terminal that's even come close to seeing mainstream use and which had colors in the first place. The libraries are part of the ncurses library and are shipped with every OS this stuff would build on to begin with.

This also solves the problem of moving the cursor and drawing a screen in general.

Re:Hexyl: A command-line hex viewer by simplicio on Wednesday January 09, 2019 @12:55PM (#18866929)
Eh, A lot of modern terminal emulators don't seem to bother providing termcap/info entries, or setting their own $TERM variables. In reality, most code just fires off ANSI sequences and hopes for the best. Looking quickly at the source for Hexyl, I think that's what the ansi_term library it uses does.

If anything, I've found doing this works better then trying to muck around with ncurses, which often gets actively mislead by incorrect terminfo entries.

Re:Hexyl: A command-line hex viewer by msla on Friday January 11, 2019 @10:11PM (#18889344)
ncurses wins once you use terminals beyond xterm.
Re:Hexyl: A command-line hex viewer by Sean1708 on Wednesday January 09, 2019 @12:20PM (#18866557)
Aren't termcap and terminfo linux (or maybe unix) only?
Re:Hexyl: A command-line hex viewer by msla on Wednesday January 09, 2019 @05:32PM (#18869686)
Both of them long predate Linux. They're definitely Unix-flavored, but so's the Berkeley sockets library, and that's available everywhere, too. Ultimately, they're a library which is packaged with a database, and nothing about them is very system-specific except the terminal information in the database.

https://en.wikipedia.org/wiki/Terminfo

Re:Hexyl: A command-line hex viewer by ksherlock on Wednesday January 09, 2019 @06:11PM (#18869968)
termcap was written by Bill Joy in 1978. terminfo dates back to 1982.
Re:Hexyl: A command-line hex viewer by feanaro on Wednesday January 09, 2019 @04:22PM (#18869035)
termcap is supported on FreeBSD, at the least.
Re:Hexyl: A command-line hex viewer by ksherlock on Wednesday January 09, 2019 @06:16PM (#18870005)
termcap/terminfo styling is limited to features like underline, bold and reverse. No coloring, per se.
Re:Hexyl: A command-line hex viewer by simplicio on Thursday January 10, 2019 @12:52AM (#18871822)
"man terminfo | grep color" shows that pretty clearly to not be the case. There's plenty of codes for setting colors.
Re:Hexyl: A command-line hex viewer by msla on Friday January 11, 2019 @10:10PM (#18889341)
It's entirely possible termcap and terminfo have been allowing applications to color their output for longer than you've been alive.
Re:Hexyl: A command-line hex viewer by msla on Friday January 11, 2019 @10:09PM (#18889339)
The downvotes prove how much HN hates history, I suppose.
Re:Hexyl: A command-line hex viewer by elteto on Wednesday January 09, 2019 @02:59PM (#18868228)
Because the author wanted to do his own, personal thing?

I get the idea behind your question, but it irks me a bit since it implies a sort of responsibility to contribute to an existing piece of software. This is a net positive of course, but the beauty of open source is the freedom to work on the things you want to work on.

Re:Hexyl: A command-line hex viewer by kps on Wednesday January 09, 2019 @02:26PM (#18867931)
It's illegible in my terminal. Not a fan of the trend to hardcoded unicorn vomit.
Re:Hexyl: A command-line hex viewer by cygned on Wednesday January 09, 2019 @10:37AM (#18865475)
I have to admit, my first question in mind was how to disable colors because I do not use syntax highlighting at all.
Re:Hexyl: A command-line hex viewer by vectorEQ on Wednesday January 09, 2019 @10:58AM (#18865683)
but if you want to disable colours in this why not use hexdump or xxd :D . it's like the only feature it adds to standard hexdump tools
Re:Hexyl: A command-line hex viewer by userbinator on Wednesday January 09, 2019 @06:34PM (#18870139)
I'm also not a fan of the colouring, especially in this application, because when you're looking at a hexdump chances are you don't care about ASCII or whitespace --- and it's not as if you couldn't tell whether something is in the ASCII range, given the character representation in the right column anyway.

The border lines don't help much either and seem more like decoration; addresses to the left and an indexing header on the top, like the traditional "canonical" hexdump format, would be far more useful.

Re:Hexyl: A command-line hex viewer by philsnow on Wednesday January 09, 2019 @10:06PM (#18871189)
How can you tell the difference between an unprintable character and whatever encodes them (I've most often seen '.'), in a single character cell, without color?
Re:Hexyl: A command-line hex viewer by sifoobar on Wednesday January 09, 2019 @03:08PM (#18868306)
Me neither.

I did use it religiously for a long, long time; then tried without for a week and never went back.

It's not like telling the difference between string literals and keywords was ever a major issue for me. I guess it could help short term when learning a new language, but I'm pretty sure it slows down overall progress.

Re:Hexyl: A command-line hex viewer by colordrops on Wednesday January 09, 2019 @03:14PM (#18868362)
How does it slow down progress?
Re:Hexyl: A command-line hex viewer by dublo7 on Wednesday January 09, 2019 @04:46PM (#18869265)
For me it doesn't. It's a quick way to see that I made a typo when a keyword doesn't turn the right color, or that I closed a strong with the wrong quote Mark.
Re:Hexyl: A command-line hex viewer by sifoobar on Friday January 11, 2019 @06:33PM (#18888247)
I find it's a bit like navigating using GPS, once I get there I still have no clue because I was mostly acting on cues.

Slow compiles have the same effect for me, I get pushed out of flow and into reactive mode.

The only way to write good code is to be proactive, and any features that interfere with that process are worse than whatever "problems" they "solve".

Re:Hexyl: A command-line hex viewer by mixmastamyk on Wednesday January 09, 2019 @11:53AM (#18866272)
Liked that though the boxes seem to be a distraction. Perhaps they could use the dim ansi code or be turned off.
Re:Hexyl: A command-line hex viewer by pbhjpbhj on Wednesday January 09, 2019 @12:53PM (#18866904)
Just looked at manpages on someone else's account with no colour highlighting, definitely missed it.