feat: visually indicate normal vs insert

This commit is contained in:
2025-08-29 10:34:12 +02:00
parent 009ff31737
commit 3bd1cc7a87
3 changed files with 32 additions and 22 deletions

View File

@@ -1,3 +1,30 @@
__set_prompt() {
view=$(cut -d "#" -f 1 "$STATEFILE")
mode=$(cut -d "#" -f 2 "$STATEFILE")
case "$view" in
"$VIEW_ARTIST")
name="$(mb_artist "$args" | $JQ -r '.name')"
PROMPT=$(printf "$ARTIST_PROMPT" "$name")
;;
"$VIEW_RELEASEGROUP")
title="$(mb_releasegroup "$args" |
$JQ -r '.title')"
artist="$(mb_releasegroup "$args" |
$JQ -r '."artist-credit" | map(([.name, .joinphrase]|join(""))) | join("")')"
PROMPT=$(printf "$FULL_PROMPT" "$artist" "$title")
;;
"$VIEW_RELEASE")
title="$(mb_release "$args" |
$JQ -r '.title')"
artist="$(mb_release "$args" |
$JQ -r '."artist-credit" | map(([.name, .joinphrase]|join(""))) | join("")')"
PROMPT=$(printf "$FULL_PROMPT" "$artist" "$title")
;;
esac
[ "$mode" = "$MODE_INSERT" ] && PT="$PROMPT_INSERT" || PT="$PROMPT_NORMAL"
printf "+change-prompt(%s %s)" "$PT" "${PROMPT:-"$SEARCH_PROMPT"}"
}
# Reload data for FZF
fzf_handle_reload() {
view=$(cut -d "#" -f 1 "$STATEFILE")
@@ -31,23 +58,9 @@ fzf_handle_load() {
"$VIEW_ARTIST")
secsymb="$(printf "$FORMAT_TYPE_HAS_SECONDARY" "")"
QUERY="$(printf "!%s " "$secsymb")"
name="$(mb_artist "$args" | $JQ -r '.name')"
PROMPT=$(printf "$ARTIST_PROMPT" "$name")
;;
"$VIEW_RELEASEGROUP")
title="$(mb_releasegroup "$args" |
$JQ -r '.title')"
artist="$(mb_releasegroup "$args" |
$JQ -r '."artist-credit" | map(([.name, .joinphrase]|join(""))) | join("")')"
QUERY="$(printf "%s " "$FORMAT_STATUS_OFFICIAL")"
PROMPT=$(printf "$FULL_PROMPT" "$artist" "$title")
;;
"$VIEW_RELEASE")
title="$(mb_release "$args" |
$JQ -r '.title')"
artist="$(mb_release "$args" |
$JQ -r '."artist-credit" | map(([.name, .joinphrase]|join(""))) | join("")')"
PROMPT=$(printf "$FULL_PROMPT" "$artist" "$title")
;;
"$VIEW_SEARCH_ARTIST")
ENABLE_CHANGE=1
@@ -64,10 +77,10 @@ fzf_handle_load() {
"$VIEW_LIST_ALBUMS") ;;
esac
printf "+change-query(%s)" "${QUERY:-}"
printf "+change-prompt(%s)" "${PROMPT:-"$SEARCH_PROMPT"}"
[ "${DISABLE_SEARCH:-}" ] && printf "+disable-search" || printf "+enable-search"
[ "${SHOW_PREVIEW:-}" ] && printf "+show-preview" || printf "+hide-preview"
[ "${ENABLE_CHANGE:-}" ] && printf "+rebind(change)" || printf "+unbind(change)"
__set_prompt
}
# Print info string for FZF
@@ -196,7 +209,6 @@ fzf_handle_change() {
# @argument $2: MusicBrainz ID of selected object
# @argument $3: Path to decoration file (optional)
fzf_handle_key() {
foo "FZF_KEY=$FZF_KEY"
parentmbid="${1:-}"
mbid="${2:-}"
path="${3:-}"
@@ -209,14 +221,12 @@ fzf_handle_key() {
if [ "$mode" = "$MODE_INSERT" ]; then
case ",$KEYS_INPUT_SINGLE," in
*",$FZF_KEY,"*)
foo "single key"
printf "put(%s)" "$FZF_KEY"
return 0
;;
esac
case ",$KEYS_INPUT_SPECIAL," in
*",$FZF_KEY,"*)
foo "special key"
case "$FZF_KEY" in
"space") printf "put( )" ;;
"backspace") printf "backward-delete-char" ;;
@@ -230,7 +240,6 @@ fzf_handle_key() {
fi
# Handle key press
foo "handle key..."
case ",$KEYS_HALFPAGE_DOWN," in
*",$FZF_KEY,"*) printf "half-page-down" ;;
esac
@@ -514,7 +523,7 @@ fzf_handle_key() {
*)
if [ "$mode" = "$MODE_NORMAL" ]; then
printf "%s#%s" "$view" "$MODE_INSERT" >"$STATEFILE"
foo "Do more here?"
__set_prompt
else
printf "put(%s)" "$FZF_KEY"
fi
@@ -561,7 +570,7 @@ fzf_handle_key() {
*)
if [ "$mode" = "$MODE_INSERT" ]; then
printf "%s#%s" "$view" "$MODE_NORMAL" >"$STATEFILE"
foo "Do more here?"
__set_prompt
else
printf "put(%s)" "$FZF_KEY"
fi