Skip to content

Commit

Permalink
optimize ansi/overstrike detection in passthru #11
Browse files Browse the repository at this point in the history
Instead of checking for ansi/overstrike in every line, check at the end
when printing the short content.
  • Loading branch information
rkitover committed Apr 7, 2015
1 parent 86d63f8 commit 0728dd8
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions vimpager
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,6 @@ ansi_filter() {
# Normally, filter outputs overstrike free content to STDERR.
# When content is short, filter outputs content with ANSI escape codes and overstrikes to STDOUT.
filter() {
_ansi_detected=0
_overstrike_detected=0
OLDIFS="${IFS}"
if [ -z "${no_pass_thru}" ]; then
content=
Expand All @@ -635,8 +633,9 @@ filter() {
read -r line

if [ $? != 0 -a -z "$line" ]; then
if [ "${_ansi_detected}" = "1" ] || [ "${_overstrike_detected}" = "1" ]; then
exec printf %s "${content}"
if echo "${content}" | grep_q '\[[^m]*m' || \
echo "${content}" | grep_q '(.)\1'; then
exec printf %s "${content}"
fi

# use vimcat to highlight otherwise
Expand All @@ -649,12 +648,6 @@ filter() {

content="${content}${line}
"
if [ "${_ansi_detected}" = "0" ] && echo "${content}" | grep_q '\[[^m]*m'; then
_ansi_detected=1
fi
if [ "${_overstrike_detected}" = "0" ] && echo "${content}" | grep_q '(.)\1'; then
_overstrike_detected=1
fi
nl=$((nl+1))

# w: line width
Expand Down

0 comments on commit 0728dd8

Please sign in to comment.