89205f90e533478f231beebbcf7b889bb085159e

Author
Sebastian Gniazdowski <sgniazdowski@gmail.com>
Committer
Sebastian Gniazdowski <sgniazdowski@gmail.com>
Date

Message

znt: faster startup of tools using colorifying (e.g. n-history)

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/zsh-navigation-tools/README.md b/plugins/zsh-navigation-tools/README.md
  2index 670a85ece9f073d70ed4df1f1f13860ac02ac71c..630b2e840e6ee1445fbab305beb47bc0a6462cfb 100644
  3--- a/plugins/zsh-navigation-tools/README.md
  4+++ b/plugins/zsh-navigation-tools/README.md
  5@@ -105,8 +105,7 @@ colorize output of the tools, via their config files (check out e.g. n-cd.conf,
  6 it uses this).
  7 
  8 ## Performance
  9-ZNT are fastest with Zsh before 5.0.8 and starting from 5.2 (the version yet to
 10-be released).
 11+ZNT are fastest with Zsh before 5.0.8 and starting from 5.2
 12 
 13 
 14 vim:filetype=conf
 15diff --git a/plugins/zsh-navigation-tools/n-list b/plugins/zsh-navigation-tools/n-list
 16index 26431a0d9c24ce581c2abda128c75a3e8a3da406..0a98d86e1831c9d60403864b3529dacb8a9d2b94 100644
 17--- a/plugins/zsh-navigation-tools/n-list
 18+++ b/plugins/zsh-navigation-tools/n-list
 19@@ -116,15 +116,15 @@ _nlist_setup_user_vars() {
 20     fi
 21 }
 22 
 23-_nlist_coloring_list_into_col_list() {
 24+_nlist_colorify_disp_list() {
 25     local col=$'\x1b[00;34m' reset=$'\x1b[0m'
 26     [ -n "$NLIST_COLORING_COLOR" ] && col="$NLIST_COLORING_COLOR"
 27     [ -n "$NLIST_COLORING_END_COLOR" ] && reset="$NLIST_COLORING_END_COLOR"
 28 
 29     if [ "$NLIST_COLORING_MATCH_MULTIPLE" -eq 1 ]; then
 30-        col_list=( "${(@)list//(#mi)$~NLIST_COLORING_PATTERN/$col${MATCH}$reset}" )
 31+        disp_list=( "${(@)disp_list//(#mi)$~NLIST_COLORING_PATTERN/$col${MATCH}$reset}" )
 32     else
 33-        col_list=( "${(@)list/(#mi)$~NLIST_COLORING_PATTERN/$col${MATCH}$reset}" )
 34+        disp_list=( "${(@)disp_list/(#mi)$~NLIST_COLORING_PATTERN/$col${MATCH}$reset}" )
 35     fi
 36 }
 37 
 38@@ -154,7 +154,7 @@ integer inner_width=term_width-3
 39 integer page_height=inner_height
 40 integer page_width=inner_width
 41 
 42-typeset -a list col_list disp_list
 43+typeset -a list disp_list
 44 integer last_element=$#
 45 local action
 46 local final_key
 47@@ -227,16 +227,10 @@ keypad=""
 48 list=( "$@" )
 49 last_element="$#list"
 50 
 51-integer is_colored=0
 52-if [[ -z "$NLIST_SEARCH_BUFFER" && -n "$NLIST_COLORING_PATTERN" ]]; then
 53-    is_colored=1
 54-    _nlist_coloring_list_into_col_list
 55-fi
 56-
 57 while (( 1 )); do
 58     # Do searching (filtering with string)
 59     if [ -n "$NLIST_SEARCH_BUFFER" ]; then
 60-        # Compute new list, col_list ?
 61+        # Compute new list?
 62         if [[ "$NLIST_SEARCH_BUFFER" != "$prev_search_buffer" || "$NLIST_IS_UNIQ_MODE" -ne "$prev_uniq_mode" ]]; then
 63             prev_search_buffer="$NLIST_SEARCH_BUFFER"
 64             prev_uniq_mode="$NLIST_IS_UNIQ_MODE"
 65@@ -290,7 +284,7 @@ while (( 1 )); do
 66                 disp_list=( "${(@)disp_list//(#mi)($~colsearch_pattern)/$red${MATCH}$reset}" )
 67             fi
 68 
 69-            # We have display list, lets replace newlines with "\n" when needed (1/3)
 70+            # We have display list, lets replace newlines with "\n" when needed (1/2)
 71             [ "$NLIST_REPLACE_NEWLINES" -eq 1 ] && disp_list=( "${(@)disp_list//$'\n'/\\n}" )
 72         fi
 73 
 74@@ -302,7 +296,7 @@ while (( 1 )); do
 75         # There is no search, but there was in previous loop
 76         # OR
 77         # Uniq mode was entered or left out
 78-        # -> compute new list (maybe also col_list)
 79+        # -> compute new list
 80         if [[ -n "$prev_search_buffer" || "$NLIST_IS_UNIQ_MODE" -ne "$prev_uniq_mode" ]]; then
 81             prev_search_buffer=""
 82             prev_uniq_mode="$NLIST_IS_UNIQ_MODE"
 83@@ -322,13 +316,6 @@ while (( 1 )); do
 84             # Remove duplicates when in uniq mode
 85             [ "$NLIST_IS_UNIQ_MODE" -eq 1 ] && typeset -U list
 86 
 87-            # Apply coloring pattern (when not with search query)
 88-            is_colored=0
 89-            if [ -n "$NLIST_COLORING_PATTERN" ]; then
 90-                is_colored=1
 91-                _nlist_coloring_list_into_col_list 
 92-            fi
 93-
 94             last_element="$#list"
 95             # Called after processing list
 96             _nlist_verify_vars
 97@@ -340,22 +327,14 @@ while (( 1 )); do
 98         integer end_idx=$(( NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN + page_height - 1 ))
 99         [ "$end_idx" -gt "$last_element" ] && end_idx=last_element
100 
101-        if [ "$is_colored" -eq 0 ]; then
102-            if [ "$prev_start_idx" -ne "$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" ]; then
103-                prev_start_idx="$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN"
104-                disp_list=( "${(@)list[NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN, end_idx]}" )
105+        if [ "$prev_start_idx" -ne "$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" ]; then
106+            prev_start_idx="$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN"
107+            disp_list=( "${(@)list[NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN, end_idx]}" )
108 
109-                # We have display list, lets replace newlines with "\n" when needed (2/3)
110-                [ "$NLIST_REPLACE_NEWLINES" -eq 1 ] && disp_list=( "${(@)disp_list//$'\n'/\\n}" )
111-            fi
112-        else
113-            if [ "$prev_start_idx" -ne "$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN" ]; then
114-                prev_start_idx="$NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN"
115-                disp_list=( "${(@)col_list[NLIST_FROM_WHAT_IDX_LIST_IS_SHOWN, end_idx]}" )
116+            [ -n "$NLIST_COLORING_PATTERN" ] && _nlist_colorify_disp_list
117 
118-                # We have display list, lets replace newlines with "\n" when needed (3/3)