Merge branch 'morantron/unique-hints'

This commit is contained in:
Jorge Morante 2016-10-25 08:07:47 +02:00
commit 7c8356dc07
3 changed files with 21 additions and 31 deletions

View File

@ -1,3 +1,8 @@
## 0.3.2 - 25 Oct 2016
* Now hints are unique. If a match has several occurrences it will always have
the same hint.
## 0.3.1 - 22 Oct 2016
* Fixed parsing of @fingers-pattern-N option not working for more than one digit ( thanks @sunaku ! )

View File

@ -1,7 +1,5 @@
BEGIN {
n_matches = 0;
line_pos = 0;
col_pos = 0;
COMPACT_HINTS = ENVIRON["COMPACT_HINTS"];
HINTS[0] = "p"
@ -121,50 +119,37 @@ BEGIN {
}
{
line = $0;
pos = 0;
col_pos = 0;
col_pos_correction = 0;
output_line = line;
output_line = $0;
# insert hints into `output_line` and accumulate hints in `hint_lookup`
line = output_line;
pos = col_pos_correction = 0;
while (match(line, finger_patterns)) {
n_matches += 1;
hint = HINTS[n_matches - 1]
pos += RSTART;
col_pos = pos;
col_pos = pos + col_pos_correction
pre_match = substr(output_line, 0, col_pos - 1);
post_match = substr(output_line, col_pos + RLENGTH, length(line) - 1);
line_match = substr(line, RSTART, RLENGTH);
full_line_match = line_match
hint = hint_by_match[line_match]
if (!hint) {
hint = HINTS[n_matches++]
hint_by_match[line_match] = hint
}
hint_lookup = hint_lookup hint ":" line_match "\n"
if (COMPACT_HINTS) {
hint_len = length(hint)
line_match = substr(line_match, hint_len + 1, length(line_match) - hint_len);
}
col_pos = col_pos + col_pos_correction
line_pos = NR;
pre_match = substr(output_line, 0, col_pos - 1);
if (COMPACT_HINTS) {
hint_match = sprintf(compound_format, hint, line_match);
} else {
hint_match = sprintf(compound_format, line_match, hint);
}
post_match = substr(output_line, col_pos + RLENGTH, length(line) - 1);
output_line = pre_match hint_match post_match;
line = post_match;
col_pos_correction += length(sprintf(highlight_format, line_match)) + length(sprintf(hint_format, hint)) - 1;
hint_lookup = hint_lookup hint ":" full_line_match "\n"
line = post_match;
}
printf "\n%s", output_line

View File

@ -12,7 +12,7 @@ sleep 0.5;
init_pane
exec "cat ./test/fixtures/ip-output";
invoke_fingers;
send "r";
send "t";
echo_yanked;
expect {