drafting multi mode

This commit is contained in:
Jorge Morante 2020-01-03 18:55:30 +01:00
parent 1deef23dc7
commit 1a5dc4fc10
6 changed files with 96 additions and 20 deletions

View File

@ -126,10 +126,14 @@ fingers_defaults=( \
[fingers-hint-position]="left" \
[fingers-hint-format]="#[fg=yellow,bold]%s" \
[fingers-selected-hint-format]="#[fg=red,bold]%s" \
[fingers-selected-highlight-format]="#[fg=red,nobold,dim]%s" \
[fingers-highlight-format]="#[fg=yellow,nobold,dim]%s" \
[fingers-hint-position-nocompact]="right" \
[fingers-hint-format-nocompact]="#[fg=yellow,bold][%s]" \
[fingers-selected-hint-format-nocompact]="#[fg=red,bold][%s]" \
[fingers-selected-highlight-format-nocompact]="#[fg=red,nobold,dim][%s]" \
[fingers-highlight-format-nocompact]="#[fg=yellow,nobold,dim]%s" \
[fingers-keyboard-layout]="qwerty" \
@ -163,9 +167,14 @@ set_tmux_env 'fingers-hint-position-nocompact'
set_tmux_env 'fingers-hint-format-nocompact' process_format
set_tmux_env 'fingers-highlight-format-nocompact' process_format
set_tmux_env 'fingers-selected-hint-format' process_format
set_tmux_env 'fingers-selected-highlight-format' process_format
set_tmux_env 'fingers-selected-hint-format-nocompact' process_format
set_tmux_env 'fingers-selected-highlight-format-nocompact' process_format
set_tmux_env 'fingers-keyboard-layout'
for option in fingers-{hint,highlight}-format{,-nocompact}; do
for option in fingers-{selected-hint,selected-highlight,hint,highlight}-format{,-nocompact}; do
env_name="$(envify "$option")_NOCOLOR"
option_value="$(read_from_config "$option")"
default_value="${fingers_defaults[$option]}"

View File

@ -12,3 +12,12 @@ function current_ms() {
function log() {
echo "$1" >> "$CURRENT_DIR/../fingers.log"
}
function log_array() {
declare -a arg_arr=(${!1})
for i in "${arg_arr[@]}"
do
log "> $i"
done
}

View File

@ -9,6 +9,7 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $CURRENT_DIR/hints.sh
source $CURRENT_DIR/utils.sh
source $CURRENT_DIR/help.sh
source $CURRENT_DIR/debug.sh
current_pane_id=$1
fingers_pane_id=$2
@ -43,8 +44,8 @@ function hide_cursor() {
echo -n "$(tput civis)"
}
function copy_result() {
local result="${state[result]}"
function copy_final_result() {
local result="${state[final_result]}"
tmux set-buffer "$result"
}
@ -115,7 +116,7 @@ function run_shell_action() {
local command_to_run="$1"
if [[ ! -z $command_to_run ]]; then
tmux run-shell -b "printf \"$(escape_quotes "${state[result]}")\" | MODIFIER=${state[modifier]} HINT=${state[input]} $EXEC_PREFIX $command_to_run"
tmux run-shell -b "printf \"$(escape_quotes "${state[final_result]}")\" | MODIFIER=${state[modifier]} HINT=${state[input]} $EXEC_PREFIX $command_to_run"
fi
}
@ -175,8 +176,11 @@ trap "handle_exit" EXIT
state[pane_was_zoomed]=$(is_pane_zoomed "$current_pane_id")
state[show_help]=0
state[compact_mode]="$FINGERS_COMPACT_HINTS"
state[multi_mode]=0
state[input]=''
state[modifier]=''
selected_matches=()
selected_hints=()
hide_cursor
show_hints_and_swap "$current_pane_id" "$fingers_pane_id" "$compact_state"
@ -207,6 +211,9 @@ do
toggle-compact-mode)
toggle_state "compact_mode"
;;
toggle-multi-mode)
toggle_state "multi_mode"
;;
hint:*)
accept_hint "$statement"
;;
@ -223,20 +230,35 @@ do
fi
if [[ $(did_state_change "show_help" "1 => 0") == 1 ]]; then
show_hints "$fingers_pane_id" "${state[compact_mode]}"
show_hints "$fingers_pane_id" "${state[compact_mode]}" "${state[multi_mode]}" "${selected_hints[@]}"
fi
if [[ $(did_state_change "compact_mode") == 1 ]]; then
show_hints "$fingers_pane_id" "${state[compact_mode]}"
show_hints "$fingers_pane_id" "${state[compact_mode]}" "${state[multi_mode]}" "${selected_hints[@]}"
fi
# Exiting multi mode makes an early exit
if [[ $(did_state_change "multi_mode" "1 => 0") == 1 ]]; then
state[final_result]=$(array_join " " "${selected_matches[@]}")
copy_final_result
break
fi
input="${state[input]}"
state[result]=$(lookup_match "$input")
state[current_match]=$(lookup_match "$input")
if [[ -n "${state[result]}" ]]; then
copy_result
break
if [[ -n "${state[current_match]}" ]]; then
if [[ "${state[multi_mode]}" == "1" ]]; then
selected_matches+=(${state[current_match]})
selected_hints+=(${state[input]})
state[input]=''
show_hints "$fingers_pane_id" "${state[compact_mode]}" "${state[multi_mode]}" "${selected_hints[@]}"
else
state[final_result]="${state[current_match]}"
copy_final_result
break
fi
fi
done < <(tail -f /tmp/fingers-command-queue)

View File

@ -15,19 +15,37 @@ BEGIN {
hint_format_nocolor = ENVIRON["FINGERS_HINT_FORMAT_NOCOLOR"]
highlight_format = ENVIRON["FINGERS_HIGHLIGHT_FORMAT"]
highlight_format_nocolor = ENVIRON["FINGERS_HIGHLIGHT_FORMAT_NOCOLOR"]
selected_highlight_format = ENVIRON["FINGERS_SELECTED_HIGHLIGHT_FORMAT"]
selected_highlight_format_nocolor = ENVIRON["FINGERS_SELECTED_HIGHLIGHT_FORMAT_NOCOLOR"]
selected_hint_format = ENVIRON["FINGERS_SELECTED_HINT_FORMAT"]
selected_hint_format_nocolor = ENVIRON["FINGERS_SELECTED_HINT_FORMAT_NOCOLOR"]
} else {
hint_format = ENVIRON["FINGERS_HINT_FORMAT_NOCOMPACT"]
highlight_format = ENVIRON["FINGERS_HIGHLIGHT_FORMAT_NOCOMPACT"]
hint_format_nocolor = ENVIRON["FINGERS_HINT_FORMAT_NOCOMPACT_NOCOLOR"]
highlight_format_nocolor = ENVIRON["FINGERS_HIGHLIGHT_FORMAT_NOCOMPACT_NOCOLOR"]
selected_highlight_format = ENVIRON["FINGERS_SELECTED_HIGHLIGHT_FORMAT_NOCOMPACT"]
selected_highlight_format_nocolor = ENVIRON["FINGERS_SELECTED_HIGHLIGHT_FORMAT_NOCOMPACT_NOCOLOR"]
selected_hint_format = ENVIRON["FINGERS_SELECTED_HINT_FORMAT_NOCOMPACT"]
selected_hint_format_nocolor = ENVIRON["FINGERS_SELECTED_HINT_FORMAT_NOCOMPACT_NOCOLOR"]
}
if (fingers_hint_position == "left")
compound_format = hint_format highlight_format
else
compound_format = highlight_format hint_format
if (fingers_hint_position == "left") {
general_compound_format = hint_format highlight_format
selected_compound_format = selected_hint_format selected_highlight_format
} else {
general_compound_format = highlight_format hint_format
selected_compound_format = selected_highlight_format selected_hint_format
}
hint_lookup = ""
split(ENVIRON["FINGERS_SELECTED_HINTS"], selected_hints_arr, ":")
for (i = 1; i <= length(selected_hints_arr); ++i) {
selected_hints_lookup[selected_hints_arr[i]] = 1
}
}
{
@ -97,8 +115,16 @@ END {
hint_lookup = hint_lookup hint ":" token "\n"
}
if (selected_hints_lookup[hint]) {
this_hint_format_nocolor = selected_hint_format_nocolor
this_compound_format = selected_compound_format
} else {
this_hint_format_nocolor = hint_format_nocolor
this_compound_format = general_compound_format
}
if (fingers_compact_hints) {
hint_len = length(sprintf(hint_format_nocolor, hint))
hint_len = length(sprintf(this_hint_format_nocolor, hint))
if (fingers_hint_position == "left")
token = substr(token, hint_len + 1, length(token) - hint_len);
else
@ -106,9 +132,9 @@ END {
}
if (fingers_hint_position == "left")
token = sprintf(compound_format, hint, token);
token = sprintf(this_compound_format, hint, token);
else
token = sprintf(compound_format, token, hint);
token = sprintf(this_compound_format, token, hint);
}
printf "%s", token

View File

@ -29,12 +29,22 @@ function get_stdin() {
function show_hints() {
local fingers_pane_id=$1
local compact_hints=$2
shift
local compact_hints=$1
shift
local multi_mode=$1
shift
declare -a selected_hints=(${@})
FINGERS_ALPHABET_DIR="$CURRENT_DIR/../alphabets/$FINGERS_KEYBOARD_LAYOUT/"
log "logging array begin"
log_array selected_hints[@]
log "logging array end"
log "join array: $(array_join ":" "${selected_hints[@]}")"
clear_screen "$fingers_pane_id"
get_stdin | FINGERS_COMPACT_HINTS="$compact_hints" FINGERS_ALPHABET_DIR="$FINGERS_ALPHABET_DIR" gawk -f $CURRENT_DIR/hinter.awk 3> $match_lookup_table
get_stdin | FINGERS_SELECTED_HINTS="$(array_join ":" "${selected_hints[@]}")" FINGERS_COMPACT_HINTS="$compact_hints" FINGERS_ALPHABET_DIR="$FINGERS_ALPHABET_DIR" gawk -f $CURRENT_DIR/hinter.awk 3> $match_lookup_table
}
function show_hints_and_swap() {

View File

@ -33,7 +33,7 @@ fingers_bind "?" "toggle-help"
fingers_bind "Space" "toggle-compact-mode"
fingers_bind "Enter" "noop"
fingers_bind "Tab" "noop"
fingers_bind "Tab" "toggle-multi-mode"
fingers_bind "Any" "noop"