feat(config-toggle): add Left/Right arrows for directional value changes
Left/Right now adjust the highlighted value one step along the OFF ← DEFAULT → ON scale, clamped at the ends (no wrap), complementing Space which cycles through all states and wraps. Right steps toward ON, Left toward OFF. Extract the set/erase side-effect into __config_toggle_apply so Space, Left, and Right share one implementation of the scope-aware set -U/-g/-Ue/-eg logic. Update the in-panel keybind hint (now width-padded via string pad so the border stays aligned) and the help text and offline docs to cover the new keys.
This commit is contained in:
+7
-2
@@ -1232,15 +1232,20 @@ Add -i (interactive confirmation) to destructive commands:
|
||||
Universal — persists across all sessions (set -U)
|
||||
Session — current shell only (set -g)
|
||||
|
||||
Changes apply immediately on each Space keypress. Always available
|
||||
Changes apply immediately on each value keypress. Always available
|
||||
regardless of the __fish_config_opinionated master state.
|
||||
|
||||
Navigation:
|
||||
↑ ↓ / j k Move cursor
|
||||
Space Cycle: ON → OFF → DEFAULT → ON
|
||||
← → Set value directionally: OFF ← DEFAULT → ON (clamped)
|
||||
Space Cycle through all states: ON → OFF → DEFAULT → ON (wraps)
|
||||
Tab Switch scope (Universal ↔ Session)
|
||||
q / Escape Exit
|
||||
|
||||
Left/Right move one step along the OFF–DEFAULT–ON scale and stop at the
|
||||
ends; Space cycles through every state and wraps around. DEFAULT erases
|
||||
the variable so the master switch / built-in default applies.
|
||||
|
||||
Flags:
|
||||
--help / -h Show usage.
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
# Copyright (C) 2026 Rootiest
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
# SYNOPSIS
|
||||
# __config_toggle_apply <varname> <scope> <value>
|
||||
#
|
||||
# DESCRIPTION
|
||||
# Applies a state value to an opinionated-component variable in the given
|
||||
# scope, immediately and persistently. Used by config-toggle's Space (cycle)
|
||||
# and Left/Right (directional) handlers so the set/erase logic lives in one
|
||||
# place. A value of "DEFAULT" erases the variable in that scope so the
|
||||
# master switch / built-in default takes over again.
|
||||
#
|
||||
# universal → set -U (on/off) / set -Ue (DEFAULT)
|
||||
# session → set -g (on/off) / set -eg (DEFAULT)
|
||||
#
|
||||
# ARGUMENTS
|
||||
# varname Variable name without the $ prefix
|
||||
# scope "universal" or "session"
|
||||
# value "on", "off", or "DEFAULT"
|
||||
#
|
||||
# RETURNS
|
||||
# 0 Always
|
||||
#
|
||||
# EXAMPLE
|
||||
# __config_toggle_apply __fish_config_op_aliases universal off
|
||||
# __config_toggle_apply __fish_config_op_greeting session DEFAULT
|
||||
function __config_toggle_apply
|
||||
set -l varname $argv[1]
|
||||
set -l scope $argv[2]
|
||||
set -l value $argv[3]
|
||||
|
||||
switch $scope
|
||||
case universal
|
||||
switch $value
|
||||
case on
|
||||
set -U $varname on
|
||||
case off
|
||||
set -U $varname off
|
||||
case DEFAULT
|
||||
set -Ue $varname
|
||||
end
|
||||
case session
|
||||
switch $value
|
||||
case on
|
||||
set -g $varname on
|
||||
case off
|
||||
set -g $varname off
|
||||
case DEFAULT
|
||||
set -eg $varname
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -131,8 +131,10 @@ function __config_toggle_draw
|
||||
printf '│%s│\n' $HBR
|
||||
|
||||
# ── Keybind hint ──────────────────────────────────────
|
||||
printf '│ %s↑↓/jk: move Space: cycle Tab: scope q: quit%s │\n' \
|
||||
$c_dim $c_reset
|
||||
# Padded to the inner width so the right border stays aligned regardless
|
||||
# of the hint text. string pad is width-aware (arrows count as 1 column).
|
||||
set -l hint " ↑↓ move ←→ set Space cycle Tab scope q quit"
|
||||
printf '│%s%s%s│\n' $c_dim (string pad -r -w $IW -- $hint) $c_reset
|
||||
|
||||
# ── Bottom border ─────────────────────────────────────
|
||||
printf '└%s┘\n' $HBR
|
||||
|
||||
@@ -44,7 +44,8 @@ function config-toggle --description 'Interactive TUI for toggling opinionated c
|
||||
echo
|
||||
echo "$c_head""Navigation:$c_reset"
|
||||
echo " $c_flag↑ ↓$c_reset or $c_flag""j k$c_reset Move cursor up / down"
|
||||
echo " $c_flag""Space$c_reset Cycle: ON → OFF → DEFAULT → ON"
|
||||
echo " $c_flag← →$c_reset Set value: OFF ← DEFAULT → ON (clamped)"
|
||||
echo " $c_flag""Space$c_reset Cycle: ON → OFF → DEFAULT → ON (wraps)"
|
||||
echo " $c_flag""Tab$c_reset Switch scope (Universal ↔ Session)"
|
||||
echo " $c_flag""q$c_reset / $c_flag""Esc$c_reset Exit"
|
||||
echo
|
||||
@@ -107,12 +108,12 @@ function config-toggle --description 'Interactive TUI for toggling opinionated c
|
||||
else
|
||||
set cur_scope universal
|
||||
end
|
||||
case space # Space — cycle and apply immediately
|
||||
case space # Space — cycle through all states and apply
|
||||
set -l varname $vars[(math $cur_row + 1)]
|
||||
set -l cur_val (__config_toggle_get_val $varname $cur_scope)
|
||||
set -l next_val ""
|
||||
|
||||
# Cycle: on → off → DEFAULT → on
|
||||
# Cycle (wraps): on → off → DEFAULT → on
|
||||
set -l next_val on
|
||||
switch $cur_val
|
||||
case on
|
||||
set next_val off
|
||||
@@ -121,28 +122,37 @@ function config-toggle --description 'Interactive TUI for toggling opinionated c
|
||||
case '*' # DEFAULT or any unrecognised
|
||||
set next_val on
|
||||
end
|
||||
__config_toggle_apply $varname $cur_scope $next_val
|
||||
case right # → step toward ON (clamped, no wrap)
|
||||
set -l varname $vars[(math $cur_row + 1)]
|
||||
set -l cur_val (__config_toggle_get_val $varname $cur_scope)
|
||||
|
||||
# Apply immediately
|
||||
switch $cur_scope
|
||||
case universal
|
||||
switch $next_val
|
||||
case on
|
||||
set -U $varname on
|
||||
case off
|
||||
set -U $varname off
|
||||
case DEFAULT
|
||||
set -Ue $varname
|
||||
end
|
||||
case session
|
||||
switch $next_val
|
||||
case on
|
||||
set -g $varname on
|
||||
case off
|
||||
set -g $varname off
|
||||
case DEFAULT
|
||||
set -eg $varname
|
||||
end
|
||||
# Order: OFF ← DEFAULT → ON
|
||||
set -l next_val on
|
||||
switch $cur_val
|
||||
case off
|
||||
set next_val DEFAULT
|
||||
case on
|
||||
set next_val on # already at the right end
|
||||
case '*' # DEFAULT or unrecognised
|
||||
set next_val on
|
||||
end
|
||||
__config_toggle_apply $varname $cur_scope $next_val
|
||||
case left # ← step toward OFF (clamped, no wrap)
|
||||
set -l varname $vars[(math $cur_row + 1)]
|
||||
set -l cur_val (__config_toggle_get_val $varname $cur_scope)
|
||||
|
||||
# Order: OFF ← DEFAULT → ON
|
||||
set -l next_val off
|
||||
switch $cur_val
|
||||
case on
|
||||
set next_val DEFAULT
|
||||
case off
|
||||
set next_val off # already at the left end
|
||||
case '*' # DEFAULT or unrecognised
|
||||
set next_val off
|
||||
end
|
||||
__config_toggle_apply $varname $cur_scope $next_val
|
||||
case q Q quit escape
|
||||
break
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user