From 3f3af527baab7c84dbc071a4662949b6afce1939 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 26 Jan 2019 17:21:38 +0200 Subject: [PATCH 1/6] general: Proper support for special keys and mouse support. --- fff | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/fff b/fff index 013bca6..9ae0491 100755 --- a/fff +++ b/fff @@ -28,6 +28,7 @@ setup_terminal() { # '\e[1;Nr': Limit scrolling to scrolling area. # Also sets cursor to (0,0). printf '\e[?1049h\e[?6h\e[?7l\e[?25l\e[2J\e[1;%sr' "$max_items" + printf '\e[?1000h\e[?1006h' } reset_terminal() { @@ -521,12 +522,18 @@ cmd_line() { } key() { - case "$1" in + # Handle special key presses. + [[ $1 == $'\e' ]] && { + read -rsn 2 + local special_key="${1}${REPLY}" + } + + case "${special_key:-$1}" in # Open list item. # 'C' is what bash sees when the right arrow is pressed ('\e[C'). # '' is what bash sees when the enter/return key is pressed. "${FFF_KEY_CHILD1:=l}"|\ - "${FFF_KEY_CHILD2:=C}"|\ + "${FFF_KEY_CHILD2:=$'\e[C'}"|\ "${FFF_KEY_CHILD3:=""}") open "${list[scroll]}" ;; @@ -536,7 +543,7 @@ key() { # '\177' and '\b' are what bash sometimes sees when the backspace # key is pressed. "${FFF_KEY_PARENT1:=h}"|\ - "${FFF_KEY_PARENT2:=D}"|\ + "${FFF_KEY_PARENT2:=$'\e[D'}"|\ "${FFF_KEY_PARENT3:=$'\177'}"|\ "${FFF_KEY_PARENT4:=$'\b'}") # If a search was done, clear the results and open the current dir. @@ -553,7 +560,7 @@ key() { # Scroll down. # 'B' is what bash sees when the down arrow is pressed ('\e[B'). "${FFF_KEY_SCROLL_DOWN1:=j}"|\ - "${FFF_KEY_SCROLL_DOWN2:=B}") + "${FFF_KEY_SCROLL_DOWN2:=$'\e[B'}") ((scroll < list_total)) && { ((scroll++)) ((y < max_items )) && ((y++)) @@ -568,7 +575,7 @@ key() { # Scroll up. # 'A' is what bash sees when the down arrow is pressed ('\e[A'). "${FFF_KEY_SCROLL_UP1:=k}"|\ - "${FFF_KEY_SCROLL_UP2:=A}") + "${FFF_KEY_SCROLL_UP2:=$'\e[A'}") # '\e[1L': Insert a line above the cursor. # '\e[A': Move cursor up a line. ((scroll > 0)) && { From 98040247c64d119c8d8e4da2410a90550825ff22 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 26 Jan 2019 17:39:12 +0200 Subject: [PATCH 2/6] general: Remove mouse support. Not possible and portable --- fff | 1 - 1 file changed, 1 deletion(-) diff --git a/fff b/fff index 9ae0491..145285c 100755 --- a/fff +++ b/fff @@ -28,7 +28,6 @@ setup_terminal() { # '\e[1;Nr': Limit scrolling to scrolling area. # Also sets cursor to (0,0). printf '\e[?1049h\e[?6h\e[?7l\e[?25l\e[2J\e[1;%sr' "$max_items" - printf '\e[?1000h\e[?1006h' } reset_terminal() { From 7f3d455635d6f15e3c9bb15c334cd61202ca3f14 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 26 Jan 2019 17:44:28 +0200 Subject: [PATCH 3/6] docs: update --- fff | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fff b/fff index 145285c..dd905e6 100755 --- a/fff +++ b/fff @@ -523,7 +523,7 @@ cmd_line() { key() { # Handle special key presses. [[ $1 == $'\e' ]] && { - read -rsn 2 + read -rsn 2 -t 1 local special_key="${1}${REPLY}" } From ce2dfd77520163c39d478a35ac4ba48f87eee981 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 28 Jan 2019 18:04:31 +0200 Subject: [PATCH 4/6] general: fix quirk --- fff | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fff b/fff index dd905e6..8effa44 100755 --- a/fff +++ b/fff @@ -523,7 +523,7 @@ cmd_line() { key() { # Handle special key presses. [[ $1 == $'\e' ]] && { - read -rsn 2 -t 1 + read "${read_flags:-'-t1'}" -rsn 2 local special_key="${1}${REPLY}" } @@ -806,7 +806,7 @@ main() { # anything until a key is pressed. # SEE: https://github.com/dylanaraps/fff/issues/48 ((BASH_VERSINFO[0] > 3)) && - read_flags=(-t 0.05) + read_flags="-t0.05" # Initialize LS_COLORS support if enabled. ((${FFF_LS_COLORS:=1} == 1)) && @@ -840,7 +840,7 @@ main() { # Vintage infinite loop. for ((;;)); { - read "${read_flags[@]}" -srn 1 && key "$REPLY" + read "$read_flags" -srn 1 && key "$REPLY" } } From 6e64b745ac157f996e91bbb743e474bc5c88de96 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 28 Jan 2019 18:12:47 +0200 Subject: [PATCH 5/6] docs: update --- README.md | 25 ++++++------------------- fff.1 | 16 ++++++++-------- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 585e081..60a6fb0 100644 --- a/README.md +++ b/README.md @@ -180,12 +180,12 @@ This is the list of full keybindings along with their default values. You only n # Go to child directory. export FFF_KEY_CHILD1="l" -export FFF_KEY_CHILD2="C" # Right Arrow -export FFF_KEY_CHILD3="" # Enter / Return +export FFF_KEY_CHILD2=$'\e[C' # Right Arrow +export FFF_KEY_CHILD3="" # Enter / Return # Go to parent directory. export FFF_KEY_PARENT1="h" -export FFF_KEY_PARENT2="D" # Left Arrow +export FFF_KEY_PARENT2=$'\e[D' # Left Arrow export FFF_KEY_PARENT3=$'\177' # Backspace export FFF_KEY_PARENT4=$'\b' # Backspace (Older terminals) @@ -200,11 +200,11 @@ export FFF_KEY_SHELL="s" # Scroll down. export FFF_KEY_SCROLL_DOWN1="j" -export FFF_KEY_SCROLL_DOWN2="B" # Down Arrow +export FFF_KEY_SCROLL_DOWN2=$'\e[B' # Down Arrow # Scroll up. export FFF_KEY_SCROLL_UP1="k" -export FFF_KEY_SCROLL_UP2="A" # Up Arrow +export FFF_KEY_SCROLL_UP2=$'\e[A' # Up Arrow # Go to top and bottom. export FFF_KEY_TO_TOP="g" @@ -259,19 +259,6 @@ When rebinding a key in `fff` make sure you don't have two bindings with the sam ### How to figure out special keys. -You can verify the value of a keypress with the following command: - -```sh -# Run this and press the desired key. -read -rn 1 - -# Left Arrow was pressed which is an escape sequence ('^[[D' or '\e[D']). -# 'read -n 1' uses the last character of escape sequences. -# Therefore the key-binding for the left arrow is 'D'. -āžœ read -rn 1 -^[[Dāžœ [D -``` - Below is a tiny script I've written which will tell you the exact value to use. It automates the deciphering of special key escape sequences to the exact value `fff` needs. Save this to a file and run it. Give it a key-press and it'll spit out the exact value needed. ```sh @@ -287,7 +274,7 @@ key() { # Escape Sequences. $'\e') read -rsn 2 - printf '%s\n' "key: ${REPLY: -1}" + printf '%s %q\n' "key:" "${1}${REPLY}" ;; # Return / Enter. diff --git a/fff.1 b/fff.1 index 2a68d67..2dda9c1 100644 --- a/fff.1 +++ b/fff.1 @@ -121,17 +121,17 @@ For more information see: # Go to child directory. export FFF_KEY_CHILD1="l" -export FFF_KEY_CHILD2="C" # Right Arrow -export FFF_KEY_CHILD3="" # Enter / Return +export FFF_KEY_CHILD2=$'\e[C' # Right Arrow +export FFF_KEY_CHILD3="" # Enter / Return # Go to parent directory. export FFF_KEY_PARENT1="h" -export FFF_KEY_PARENT2="D" # Left Arrow -export FFF_KEY_PARENT3=$'\\177' # Backspace -export FFF_KEY_PARENT4=$'\\b' # Backspace (Older terminals) +export FFF_KEY_PARENT2=$'\e[D' # Left Arrow +export FFF_KEY_PARENT3=$'\177' # Backspace +export FFF_KEY_PARENT4=$'\b' # Backspace (Older terminals) # Go to previous directory. -export FFF_KEY_PREVIOUS="\-" +export FFF_KEY_PREVIOUS="-" # Search. export FFF_KEY_SEARCH="/" @@ -141,11 +141,11 @@ export FFF_KEY_SHELL="s" # Scroll down. export FFF_KEY_SCROLL_DOWN1="j" -export FFF_KEY_SCROLL_DOWN2="B" # Down Arrow +export FFF_KEY_SCROLL_DOWN2=$'\e[B' # Down Arrow # Scroll up. export FFF_KEY_SCROLL_UP1="k" -export FFF_KEY_SCROLL_UP2="A" # Up Arrow +export FFF_KEY_SCROLL_UP2=$'\e[A' # Up Arrow # Go to top and bottom. export FFF_KEY_TO_TOP="g" From f8c8ba2bbe75a70d906ae7ccea5db74c5fd5881e Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 28 Jan 2019 18:22:15 +0200 Subject: [PATCH 6/6] general: fix quirk --- fff | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fff b/fff index 8effa44..9680b41 100755 --- a/fff +++ b/fff @@ -523,7 +523,7 @@ cmd_line() { key() { # Handle special key presses. [[ $1 == $'\e' ]] && { - read "${read_flags:-'-t1'}" -rsn 2 + read "${read_flags[@]}" -rsn 2 local special_key="${1}${REPLY}" } @@ -806,7 +806,7 @@ main() { # anything until a key is pressed. # SEE: https://github.com/dylanaraps/fff/issues/48 ((BASH_VERSINFO[0] > 3)) && - read_flags="-t0.05" + read_flags=(-t 0.05) # Initialize LS_COLORS support if enabled. ((${FFF_LS_COLORS:=1} == 1)) && @@ -840,7 +840,7 @@ main() { # Vintage infinite loop. for ((;;)); { - read "$read_flags" -srn 1 && key "$REPLY" + read "${read_flags[@]}" -srn 1 && key "$REPLY" } }