toggle collapsed hints by pressing <space>
This commit is contained in:
parent
b05b723165
commit
dcf65b7b7e
|
@ -6,6 +6,7 @@ source $CURRENT_DIR/config.sh
|
|||
source $CURRENT_DIR/actions.sh
|
||||
source $CURRENT_DIR/hints.sh
|
||||
source $CURRENT_DIR/utils.sh
|
||||
source $CURRENT_DIR/debug.sh
|
||||
|
||||
FINGERS_COPY_COMMAND=$(tmux show-option -gqv @fingers-copy-command)
|
||||
|
||||
|
@ -82,6 +83,16 @@ show_hints_and_swap $current_pane_id $fingers_pane_id
|
|||
|
||||
hide_cursor
|
||||
input=''
|
||||
collapsed_state=1
|
||||
|
||||
function toggle_collapsed_state() {
|
||||
if [[ $collapsed_state == "0" ]]; then
|
||||
collapsed_state=1
|
||||
else
|
||||
collapsed_state=0
|
||||
fi
|
||||
}
|
||||
|
||||
while read -rsn1 char; do
|
||||
# Escape sequence, flush input
|
||||
if [[ "$char" == $'\x1b' ]]; then
|
||||
|
@ -98,9 +109,13 @@ while read -rsn1 char; do
|
|||
continue
|
||||
fi
|
||||
|
||||
|
||||
if [[ $char == "$BACKSPACE" ]]; then
|
||||
input=""
|
||||
continue
|
||||
elif [[ $char == "" ]]; then
|
||||
toggle_collapsed_state
|
||||
show_hints "$fingers_pane_id" $collapsed_state
|
||||
else
|
||||
input="$input$char"
|
||||
fi
|
||||
|
|
|
@ -2,7 +2,7 @@ BEGIN {
|
|||
n_matches = 0;
|
||||
line_pos = 0;
|
||||
col_pos = 0;
|
||||
COLLAPSE_HINTS = 1;
|
||||
COLLAPSE_HINTS = ENVIRON["COLLAPSED_HINTS"];
|
||||
|
||||
HINTS[0] = "p"
|
||||
HINTS[1] = "o"
|
||||
|
@ -110,13 +110,13 @@ BEGIN {
|
|||
if (COLLAPSE_HINTS) {
|
||||
hint_format = "\033[30;1;43m%s\033[0m"
|
||||
highlight_format = "\033[1;33m%s\033[0m"
|
||||
compound_format = hint_format highlight_format
|
||||
} else {
|
||||
hint_format = "\033[1;33m[%s]\033[0m"
|
||||
highlight_format = "\033[1;33m%s\033[0m"
|
||||
compound_format = highlight_format hint_format
|
||||
}
|
||||
|
||||
compound_format = highlight_format hint_format
|
||||
|
||||
hint_lookup = ""
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,7 @@ BEGIN {
|
|||
|
||||
if (COLLAPSE_HINTS) {
|
||||
hint_len = length(hint)
|
||||
line_match = substr(line_match, hint_len - 1, length(line_match) - hint_len);
|
||||
line_match = substr(line_match, hint_len + 1, length(line_match) - hint_len);
|
||||
}
|
||||
|
||||
col_pos = col_pos + col_pos_correction
|
||||
|
@ -149,7 +149,13 @@ BEGIN {
|
|||
line_pos = NR;
|
||||
|
||||
pre_match = substr(output_line, 0, col_pos - 1);
|
||||
hint_match = sprintf(compound_format, line_match, hint);
|
||||
|
||||
if (COLLAPSE_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;
|
||||
|
|
|
@ -2,8 +2,11 @@
|
|||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
source $CURRENT_DIR/utils.sh
|
||||
source $CURRENT_DIR/debug.sh
|
||||
|
||||
match_lookup_table=$(fingers_tmp)
|
||||
pane_output_temp=$(fingers_tmp)
|
||||
flushed_input=0
|
||||
|
||||
function clear_screen() {
|
||||
local fingers_pane_id=$1
|
||||
|
@ -16,10 +19,26 @@ function lookup_match() {
|
|||
echo "$(cat $match_lookup_table | grep "^$input:" | sed "s/^$input://")"
|
||||
}
|
||||
|
||||
function get_stdin() {
|
||||
if [[ $(cat $pane_output_temp | wc -l) -gt 0 ]]; then
|
||||
cat $pane_output_temp
|
||||
else
|
||||
flushed_input="1"
|
||||
tee $pane_output_temp
|
||||
fi
|
||||
}
|
||||
|
||||
function show_hints() {
|
||||
local fingers_pane_id=$1
|
||||
local collapsed_hints=$2
|
||||
|
||||
clear_screen "$fingers_pane_id"
|
||||
get_stdin | COLLAPSED_HINTS=$collapsed_hints FINGER_PATTERNS=$PATTERNS __awk__ -f $CURRENT_DIR/hinter.awk 3> $match_lookup_table
|
||||
}
|
||||
|
||||
function show_hints_and_swap() {
|
||||
current_pane_id=$1
|
||||
fingers_pane_id=$2
|
||||
tmux swap-pane -s "$current_pane_id" -t "$fingers_pane_id"
|
||||
clear_screen "$fingers_pane_id"
|
||||
cat | FINGER_PATTERNS=$PATTERNS __awk__ -f $CURRENT_DIR/hinter.awk 3> $match_lookup_table
|
||||
show_hints "$fingers_pane_id" 1
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue