Skip to content

Commit

Permalink
Added the highlight options and documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Krenz committed Jun 24, 2010
1 parent 58add8e commit 949e534
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

June 23rd, 2010
--------------------------

- Added --highlight set of options and documentation


May 19th, 2010
--------------------------

Expand Down
56 changes: 55 additions & 1 deletion clide
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ my $version_number = 0.9;
my @passed_expressions = (); # //,fg=yellow and so on.
my @definition_files = ();
my @expression_files = ();
my @general_highlights = ();
my $highlight_attributes = '';
my $gethelp = '';
my $warmfuzzy = '';
my $listcolors = 0;
Expand All @@ -48,6 +50,8 @@ GetOptions(
"expression|e=s" => \@passed_expressions, # Searches passed on command line.
"definitionfile|d=s" => \@definition_files,
"expressionfile|f=s" => \@expression_files,
"highlight|hl=s" => \@general_highlights,
"highlightattributes|ha=s" => \$highlight_attributes,
"listcolors" => \$listcolors,
"liststyles" => \$liststyles,
"listdefinitions" => \$listdefinitions,
Expand Down Expand Up @@ -216,9 +220,25 @@ foreach my $expressionfile (@expression_files) {
close($efh);
}

my $highlights_expression = "";
# Now make the expression for the general highlights if there are any.
if (($#general_highlights + 1) > 0) {
unless ($highlight_attributes) {
# This is a default that will be familiar to most people.
$highlight_attributes = "bold,bg=yellow";
}

my $all_highlights_string = join(",", @general_highlights);
# The --highlights option will take strings literally, so we need to escape any character
# that would have meaning in PCRE.
$all_highlights_string =~ s/([\$\^\*\(\)\+\|\[\]\.\?])/\\$1/g;
$all_highlights_string =~ s/,/|/g;
$highlights_expression = "/($all_highlights_string)/gi,$highlight_attributes";
push(@all_expressions, @passed_expressions, $highlights_expression);
} else {
push(@all_expressions, @passed_expressions);
}

push(@all_expressions, @passed_expressions);

# Now read all the expressions into a priority tree that we can use later per each line of input.
my %searches = ();
Expand Down Expand Up @@ -515,6 +535,15 @@ Options:
-d, --definitionfile <file>
-f, --expressionfile <file>
--highlight, --hl <word1>[,word2,word3,...]
Quickly highlight the words specified by the comma seperated
string you provide.
--highlightattributes, --ha <attribute1>[,attribute2,attribute3,...]
The default attributes used by the highlight option.
This option uses the same comma seperate values taht
can be defined in an normal expression.
--listcolors - Show a list of foreground and background colors
that can be used.
--liststyles - Show a list of styles that can be used (not all
Expand Down Expand Up @@ -564,6 +593,14 @@ and expressions. Currently the focus is on creating ANSI color and style escape
-f, --expressionfile <file>
--highlight, --hl <word1>[,word2,word3,...] - Quickly highlight
the words given in the comma seperated list of words.
--highlightattributes, --ha <attribute1>[,attribute2,attribute3,...]
The default attributes used by the highlight option.
This option uses the same comma seperate values taht
can be defined in an normal expression.
--listcolors - Show a list of foreground and background colors
that can be used.
Expand Down Expand Up @@ -620,6 +657,23 @@ Expressions can be specified on the command line using one or more -e options.
You can also use the -f option one or more times to specify premade expression
files.
=head2 QUICK HIGHLIGHTING
If you're in a hurry and don't want to come up with an expression for matching
words or characters that you'd like to highlight, you can use the --highlight
option along with a comma seperated list of values you want to match. Like
this:
clide --highlight car,truck,boat insurance-readme.txt
By default clide will highlight these words in yellow. you can override
this with the --highlightattributes option, specifying what you want
in the same way you would pass attribute arguments in a -e argument.
You can use the --highlight option in combination with -e of -f options,
but the expressions will be applied after the expressions specified with
-e or -f.
=head2 PERL REGULAR EXPRESSIONS
clide works by passing the expression that you specify into a PERL matching
Expand Down

0 comments on commit 949e534

Please sign in to comment.