Skip to content
This repository has been archived by the owner on Apr 26, 2020. It is now read-only.

get words to highlight from another text file #8

Open
arahayrabedian opened this issue Sep 1, 2015 · 4 comments
Open

get words to highlight from another text file #8

arahayrabedian opened this issue Sep 1, 2015 · 4 comments

Comments

@arahayrabedian
Copy link

I'm looking to implement something like how grep does it (see http://www.explainshell.com/explain?cmd=grep+-f), I haven't looked at the code yet but i'm happy to try to contribute, just want to make sure you'd be on the same page if that's implemented.

Might be an acceptable solution to alleviate issue #3, whilst not one command per-se (since it'd require a pattern file) it'd at least give the option... at the moment I didn't enjoy chaining em in more than 100 pipes.

this leaves me some questions:

  1. would picking random colours per line work?
  2. customizable colour per-line? how to configure?
  3. would a switch for one colour for everything be of interest?

Let me know what you think and I'd be happy to get cracking.

@ikalnytskyi
Copy link
Owner

Actually, I'm completely ok with the idea to use a file with patterns. Although, some questions should be discussed.

This is a current CLI

usage: em [OPTION]... PATTERN [FILE]...

Em is a terminal tool that prints FILE(s), or standard input to standard
output and highlights the expressions that are matched the PATTERN.

positional arguments:
  PATTERN               a pattern to highlight
  FILE                  search for pattern in these file(s)

optional arguments:
  -f FORMAT, --format FORMAT
                        a color to highlight matched expressions
  -i, --ignore-case     ignore case distinctions
  -l, --line-mode       highlight entire line
  -v, --version         show program's version number and exit
  -h, --help            show this help message and exit

With no FILE, or when FILE is -, read standard input. The FORMAT option may be
one of: BOLD, UNDERLINE, [ON]GREY, [ON]RED, [ON]GREEN, [ON]YELLOW, [ON]BLUE,
[ON]MAGENTA, [ON]CYAN or [ON]WHITE. Default is RED.

That basically means two things:

  • the -f option is in use, therefore we can't make it compatible with grep
  • the PATTERN option is positional, therefore it's mandatory by default

You need to research whether it's possible to have either PATTERN or some another optional argument with path to pattern file. Alternatively, we could go with some prefix, like *if PATTERN is started with @ then it's a file path`.

As for your questions, I think it would be nice to have color customization per pattern. Perhaps we can use JSON instead plain text, so it would be easy to do.

@arahayrabedian
Copy link
Author

I'll see what I can do for the CLI interface parts, those should be simple to move around based on feedback, even though i used it didn't click with me that -f was taken.

While I agree with json being nice to have, my main concern is speed when using a utility like this... my use case was something like this:

i had a huge log file that was becoming a strain to look at and match some stuff together, so i went to find a highlighter tool, i already had a patterns file (generated output of another string of commands) and just wanted to get the highlighting working. In most scenarios like this (for me) creating a json is an extra mental barrier** to using the tool, however, it's probably easy to add once the core mechanism is already in place and i'd be happy to do it (would just use a different flag for the file type i suppose), though as I mentioned, haven't even had time to look at the code yet, will do that shortly. I'm hoping it'll be easy to add in :)

**: is the reason I didn't opt to use something like clide which i saw recommended elsewhere because I didn't want to spend the (probably very few) minutes learning how to set up it's pattern files. - though now on second thought I've essentially proposed the same. -_-

I'll start simple - random colours assigned to each line on a patterns file and work from there, probably won't PR that part but at least I'll get a feel for the code and see if I can pull off the rest.

@arahayrabedian
Copy link
Author

oh, also not a huge fan of the @Prefix personally, curl does it and it drives me insane cos i forget it often, will play with argparse and make it all work out.

Will address all this at the end as it's just an entry point to lower level stuff and is thus super-flexible (gotta love arg/optparse and stuff!)

edit: apologies to the person with the username 'prefix' - i figure they'll have a notification regarding this.

@ikalnytskyi
Copy link
Owner

@arahayrabedian Sorry for the delay, I was busy.

Ok, I'll wait for your pull request. Let's just make it happen, and postpone further discussions until patch is implemented. :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants