Live data from Hacker News

Show HN: Grep with colours written in Go

github.com

51–60 of 90 posts

Re: Show HN: Grep with colours written in Go

#51
post #33

Earlier quoted context omitted.

I turned most colors off many years ago. For me it was because several tools (especially ls) used colors that were very hard to distinguish with my terminal background. I found myself spending too much time trying to figure out what was on my screen. Another bonus is that I don't feel cheated when I log into systems that don't support colors (*BSD, Solaris, etc). Everything just looks normal to me. Even non-syntax hi…

The tools don't exactly choose the color. They choose a color name from a palette. Your terminal's theme defines that palette. If your terminal has a background very close to one of the colors on that palette, that is a theme problem, not an app problem.

That's mostly true, but there are several different methods for sending colours via escape codes and the one you discuss is just the ANSI standard. There is also 265 colour palette and even true colours (defined via RGB values). However most tools will use the standard 8 colour palette or the extended 8x3 colour palette (8 colours across 3 different intensities) because they're supported on pretty much every terminal emulator (even on Windows's cmd.exe).

So it is possible for tools to choose colours by an exact RGB value, but typically they wont.

The other thing to remember is some tools can have their colours remapped. Even tools people might not expect to be able to. eg you can configure (via environmental variables IIRC) `ls` to have specific colours for specific inode types. However in my personal opinion it is a lot of faff for very little reward.

Re: Show HN: Grep with colours written in Go

#52
post #39

Earlier quoted context omitted.

Genuinely curious, why do some developers prefer not having colors for ls, grep, etc.? no-color.org mentions that many users prefer having colors disabled, but didn't list any reasons why.

Colorless is not my cup of tea, but here is one perspective I read a few years ago: http://www.linusakesson.net/programming/syntaxhighlighting/i... HN discussion: https://news.ycombinator.com/item?id=3717303

I disagree with the author's claim that "A splash of colour may grab the reader's attention, but it will inevitably decrease the legibility of the text."

Funny enough, I've found that adding syntax highlighting to even normal English text makes it more readable. I sometimes turn on a random language's syntax highlighting in e.g. Notepad++ even if the choice of colouring is basically nonsense.

In the article you link, apart from the green on grey, the little example paragraph is actually very nice and readable.

Something like http://www.beelinereader.com/individual would probably make things easier for me, though it costs money.

The other issue is that it is too uniform. I like how syntax highlighting tends to make random patterns which kind of looks like pictures in the code - it makes it much easier for me to navigate, and figure out where I was and where I'm going.

Re: Show HN: Grep with colours written in Go

#53

Do be sure to at least consider supporting no colour! http://no-color.org

| sed -e /\x1b\[[0-9;]+m// ^ I have not run the above program, only proven it to be correct.

Sadly that only removes 1 of the 3 methods of escaping terminal colours. Plus there is also the risk of it removing other SGR (Select Graphic Rendition) escape codes such as underline. That latter bug might be an acceptable casualty though.

Re: Show HN: Grep with colours written in Go

#54
post #20
post #6

Useless use of cat candidate.

This is one of my pet peeves - complaining about technically unnecessary, but fully benign uses of cat. Yes, 'cat FILENAME | blush "some text"' and 'blush "some text" So, yes, its unnecessary. And, yes, in a script using cat like that can complicate error handling. But, for interactive use, what advice exactly are you trying to convey?

Sometimes things are lost over text -- my comment was meant to be more whimsical than it actually read. Just the old http://porkmail.org/era/unix/award.html joke.

My actual (light) advice is merely that we're all guilty of inappropriately using IO redirection facilities that punish the performance of our shells. `cat | grep ` should be replaced by `grep `.

No doubt that pipelines are easier to read. The author has a whole section in README demonstrating blush's ability to read STDIN - nothing is lost by using best practices everywhere else. Documentation matters, and it should communicate best practices.

Re: Show HN: Grep with colours written in Go

#55
post #39

Earlier quoted context omitted.

Colorless is not my cup of tea, but here is one perspective I read a few years ago: http://www.linusakesson.net/programming/syntaxhighlighting/i... HN discussion: https://news.ycombinator.com/item?id=3717303

I disagree with the author's claim that "A splash of colour may grab the reader's attention, but it will inevitably decrease the legibility of the text." Funny enough, I've found that adding syntax highlighting to even normal English text makes it more readable. I sometimes turn on a random language's syntax highlighting in e.g. Notepad++ even if the choice of colouring is basically nonsense. In the article you link,…

There was a link to a study here on HN some year(s) ago where they alternated the colour of each sentence in a text and found the reading speed to be increased. Probably similar effect as making text columns more narrow instead of using the full width of your screen, its easier to navigate and uts easier to read a whole chunk at once instead of word by word.

Re: Show HN: Grep with colours written in Go

#56

Do be sure to at least consider supporting no colour! http://no-color.org

+1 for NO_COLOR.

For example, yellow text on a dull yellow background? No thanks.

For years I've just wrapped commands on bash to strip the colour control-codes from stdout.

function monochrome() { "$@" | sed -r "s/[[:cntrl:]]\[[0-9]{1,3}m//g" }

Re: Show HN: Grep with colours written in Go

#57

Do be sure to at least consider supporting no colour! http://no-color.org

Why wouldn't you just write a command line tool that strips the color escapes and then set up aliases like alias ag='ag | nocolor' or whatever. Seems much easier than trying to convince every developer out there to support your environment variable.

Re: Show HN: Grep with colours written in Go

#58
post #46
post #8

Earlier quoted context omitted.

A quick look at the source shows that it appears to be linear and just uses `strings.Contains` or `r.MatchString` on each line, so I don't think it has any of the optimizations that are built into `ag`.

That is correct. The project is at its early stages. I want to see what the community need the most and shape the project towards that goal. On the other hand I tried to avoid optimisations until most of functionalities are implemented.

It's a very nice idea and you should be proud of what you've built, but my personal opinion is that speed is a core feature of `grep`.

A good place to start would be this: why GNU grep is fast[1] - Starting with the Boyer-Moore string search algorithm and reading through the optimizations done in GNU grep.

p.s. there's an implementation of Boyer-Moore hiding in Go's standard library.

[1] https://lists.freebsd.org/pipermail/freebsd-current/2010-Aug...

Re: Show HN: Grep with colours written in Go

#59
post #18

Earlier quoted context omitted.

I could be wrong, but I read valarauca1's comment as "I’m doubtful. ag and rg use a lot of smart optimizations to get their speed."

lol people's reading comprensión is so bad sometimes

Reading comprehension is difficult when there's missing punctuation. For example, "Let's eat grandma" versus "Let's eat, grandma".

Re: Show HN: Grep with colours written in Go

#60
post #39

Earlier quoted context omitted.

Colorless is not my cup of tea, but here is one perspective I read a few years ago: http://www.linusakesson.net/programming/syntaxhighlighting/i... HN discussion: https://news.ycombinator.com/item?id=3717303

I disagree with the author's claim that "A splash of colour may grab the reader's attention, but it will inevitably decrease the legibility of the text." Funny enough, I've found that adding syntax highlighting to even normal English text makes it more readable. I sometimes turn on a random language's syntax highlighting in e.g. Notepad++ even if the choice of colouring is basically nonsense. In the article you link,…

"...a splash of colour may grab the reader's attention, but it will inevitably decrease the legibility of the text."

This depends entirely on the content of the text. Stories, fiction, non-fiction, reference material ... information where one human is intending to communicate with another human should limit use of color.

For source code, that humans do read but is intended to be parsed and compiled by a computer, I'm not assembling (in my head) the whimsical trials of a protagonist - I need to see structure; color gives me a quicker overview of the structure of a line, function, class, etc.

Post reply on HN