From b15848887b33fcb854f0a8e38143b7153306c4a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=84min=20Baumeler?= Date: Wed, 3 Sep 2025 17:35:55 +0200 Subject: [PATCH] imprv: search enable/disable, some keys, comments --- src/sh/fzf.sh | 3 ++- src/sh/keys.sh | 46 ++++++++++++++++++++++++++++++++++------------ 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/sh/fzf.sh b/src/sh/fzf.sh index 2c7ccd7..69ac477 100644 --- a/src/sh/fzf.sh +++ b/src/sh/fzf.sh @@ -78,7 +78,7 @@ fzf_handle_load() { ;; "$VIEW_LIST_ALBUMS") ;; esac - [ "${DISABLE_SEARCH:-}" ] && printf "+disable-search+change-query(%s)" "${QUERY:-"$FZF_QUERY"}" || printf "+enable-search+change-query(%s)" "${QUERY:-}" + [ "${DISABLE_SEARCH:-}" ] && printf "+disable-search+change-query(%s)+disable-search" "${QUERY:-"$FZF_QUERY"}" || printf "+enable-search+change-query(%s)+enable-search" "${QUERY:-}" [ "${SHOW_PREVIEW:-}" ] && printf "+show-preview" || printf "+hide-preview" [ "${ENABLE_CHANGE:-}" ] && printf "+rebind(change)" || printf "+unbind(change)" __set_prompt "$view" "$mode" @@ -547,6 +547,7 @@ fzf_handle_key() { if [ "${VIEW_NEXT:-}" ]; then [ "$VIEW_NEXT" = "$VIEW_PLAYLIST" ] && MODE_NEXT="$MODE_NORMAL" state_update "$VIEW_NEXT" "${MODE_NEXT:-"$mode"}" "${VIEW_NEXT_ARGS:-}" + [ "$MODE_NEXT" = "$MODE_INSERT" ] && printf "+enable-search" || printf "+disable-search" [ "${ACCEPT:-}" ] && printf "+accept" || printf "+reload:%s" "$0 --fzf-reload" fi } diff --git a/src/sh/keys.sh b/src/sh/keys.sh index 99f2f60..6fe65d1 100644 --- a/src/sh/keys.sh +++ b/src/sh/keys.sh @@ -1,3 +1,25 @@ +# Key bindings +# +# Some key-bindings are used exclusively in the normal mode, others exclusively +# in the insert mode, others in both modes. +# Some key-bindings are universal in the sense that they do not depend on the +# state of the player (view, mode, arguments), others are not universal. +# +# For fast processing, we propose the following. +# The mode (normal or insert) is stored in the FZF_INPUT_STATE variable. All +# key-bindings that are independent of the `view` and of the `arguments` are +# directly processed using a `--bind` with inline transform element. Keys that +# depend on `view` or `arguments` are processed through `$0 --fzf-key`. In a +# future step, we may also store the `view` part of the state as hidden fields +# in the list (the list generator makes that). Then, it may be possible to +# completely get rid of the state files. Even beter, we may store the view part +# in FZF_HEADER_LABEL. +# +# Switching between the modes (normal <-> insert) is done using two fzf `--bind` +# arguments. We make sure that only one is active. +KEYS_I_NORMAL="${KEYS_I_NORMAL:-"esc"}" +KEYS_N_INSERT="${KEYS_N_INSERT:-"a,i,/"}" + KEYS_INPUT_SINGLE='0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,!,",#,$,%,&,\,(,),*,+,,,-,.,/,:,;,<,=,>,?,@,[,\,\,],^,_,`,{,|,},~' KEYS_INPUT_SINGLE="$KEYS_INPUT_SINGLE,'" KEYS_INPUT_SPECIAL="space,backspace,delete,left,right" @@ -21,6 +43,8 @@ KEYS_SWITCH_LOCAL_REMOTE="${KEYS_SWITCH_LOCAL_REMOTE:-"ctrl-/"}" KEYS_PLAY="${KEYS_PLAY:-"enter"}" KEYS_QUEUE="${KEYS_QUEUE:-"ctrl-alt-m"}" KEYS_SHOW_PLAYLIST="${KEYS_SHOW_PLAYLIST:-"ctrl-p"}" +KEYS_NI="$KEYS_HALFPAGE_DOWN,$KEYS_HALFPAGE_UP,$KEYS_BROWSE,$KEYS_OPEN,$KEYS_OUT,$KEYS_IN,$KEYS_SELECT_ARTIST,$KEYS_FILTER_LOCAL,$KEYS_FILTER_1,$KEYS_FILTER_2,$KEYS_FILTER_3,$KEYS_FILTER_4,$KEYS_SWITCH_ARTIST_ALBUM,$KEYS_SWITCH_LOCAL_REMOTE,$KEYS_PLAY,$KEYS_QUEUE,$KEYS_SHOW_PLAYLIST" +export KEYS_NI # Keys in normal mode only KEYS_N_DOWN="${KEYS_N_DOWN:-"j"}" @@ -36,23 +60,21 @@ KEYS_N_PLAY_NEXT="${KEYS_N_PLAY_NEXT:-"right"}" KEYS_N_PLAY_PREV="${KEYS_N_PLAY_PREV:-"left"}" KEYS_N_SEEK_FORWARD="${KEYS_N_SEEK_FORWARD:-"shift-right"}" KEYS_N_SEEK_BACKWARD="${KEYS_N_SEEK_BACKWARD:-"shift-left"}" - -# Special playlist keys -KEYS_PLAYLIST_RELOAD="${KEYS_PLAYLIST_RELOAD:-"r"}" +KEYS_N="$KEYS_N_DOWN,$KEYS_N_UP,$KEYS_N_OUT,$KEYS_N_IN,$KEYS_N_TOP,$KEYS_N_BOT,$KEYS_N_QUIT,$KEYS_N_INSERT,$KEYS_N_TOGGLE_PLAY_PAUSE,$KEYS_N_PLAY_NEXT,$KEYS_N_PLAY_PREV,$KEYS_N_SEEK_FORWARD,$KEYS_N_SEEK_BACKWARD" +export KEYS_N # Keys in insert mode only KEYS_I_NORMAL="${KEYS_I_NORMAL:-"esc"}" +KEYS_I="$KEYS_I_NORMAL" +export KEYS_I + +# Special playlist keys +KEYS_PLAYLIST_RELOAD="${KEYS_PLAYLIST_RELOAD:-"r"}" +KEYS_PLAYLIST="$KEYS_PLAYLIST_RELOAD" +export KEYS_PLAYLIST # Grouping -KEYS_GROUP_NI="$KEYS_HALFPAGE_DOWN,$KEYS_HALFPAGE_UP,$KEYS_OPEN,$KEYS_BROWSE,$KEYS_OUT,$KEYS_IN,$KEYS_SELECT_ARTIST,$KEYS_FILTER_LOCAL,$KEYS_FILTER_1,$KEYS_FILTER_2,$KEYS_FILTER_3,$KEYS_FILTER_4,$KEYS_SWITCH_ARTIST_ALBUM,$KEYS_SWITCH_LOCAL_REMOTE,$KEYS_PLAY,$KEYS_QUEUE,$KEYS_SHOW_PLAYLIST" - -KEYS_GROUP_N="$KEYS_N_DOWN,$KEYS_N_UP,$KEYS_N_OUT,$KEYS_N_IN,$KEYS_N_TOP,$KEYS_N_BOT,$KEYS_N_QUIT,$KEYS_N_INSERT,$KEYS_N_TOGGLE_PLAY_PAUSE,$KEYS_N_PLAY_NEXT,$KEYS_N_PLAY_PREV,$KEYS_N_SEEK_FORWARD,$KEYS_N_SEEK_BACKWARD" - -KEYS_GROUP_I="$KEYS_I_NORMAL" - -KEYS_PLAYLIST="$KEYS_PLAYLIST_RELOAD" - -KEYS_ALL="$KEYS_GROUP_NI,$KEYS_GROUP_N,$KEYS_GROUP_I,$KEYS_INPUT_SINGLE,$KEYS_INPUT_SPECIAL,$KEYS_PLAYLIST" +KEYS_ALL="$KEYS_NI,$KEYS_N,$KEYS_I,$KEYS_INPUT_SINGLE,$KEYS_INPUT_SPECIAL,$KEYS_PLAYLIST" export KEYS_HALFPAGE_DOWN KEYS_HALFPAGE_UP KEYS_OPEN KEYS_BROWSE KEYS_OUT KEYS_IN \ KEYS_SELECT_ARTIST KEYS_FILTER_LOCAL KEYS_FILTER_1 KEYS_FILTER_2 KEYS_FILETER_3 KEYS_FILTER_4 \