refactor(config-settings): shared frame renderer + line-diff redraw #133
@@ -41,10 +41,7 @@ function __config_settings_draw_subcat
|
|||||||
set -l cur_scope $argv[2]
|
set -l cur_scope $argv[2]
|
||||||
set -l category_var $argv[3]
|
set -l category_var $argv[3]
|
||||||
|
|
||||||
set -l c_ok (set_color green)
|
|
||||||
set -l c_err (set_color red)
|
|
||||||
set -l c_dim (set_color brblack)
|
set -l c_dim (set_color brblack)
|
||||||
set -l c_sel (set_color --bold magenta)
|
|
||||||
set -l c_head (set_color --bold cyan)
|
set -l c_head (set_color --bold cyan)
|
||||||
set -l c_reset (set_color normal)
|
set -l c_reset (set_color normal)
|
||||||
|
|
||||||
@@ -52,23 +49,14 @@ function __config_settings_draw_subcat
|
|||||||
set -l n (count $rows)
|
set -l n (count $rows)
|
||||||
|
|
||||||
# ── Width tier: matches __config_settings_draw's 6-col-per-side steps ──
|
# ── Width tier: matches __config_settings_draw's 6-col-per-side steps ──
|
||||||
set -l iw 50
|
set -l iw (__config_settings_frame width)
|
||||||
if test "$COLUMNS" -ge 90
|
|
||||||
set iw 76
|
|
||||||
else if test "$COLUMNS" -ge 86
|
|
||||||
set iw 72
|
|
||||||
else if test "$COLUMNS" -ge 82
|
|
||||||
set iw 68
|
|
||||||
end
|
|
||||||
set -l HBR (string repeat -n $iw '─')
|
set -l HBR (string repeat -n $iw '─')
|
||||||
set -l p (string repeat -n (math --scale=0 "max(0, ($COLUMNS - ($iw + 2)) / 2)") ' ')
|
set -l p (string repeat -n (math --scale=0 "max(0, ($COLUMNS - ($iw + 2)) / 2)") ' ')
|
||||||
|
|
||||||
# Label field is 13 wide (one wider than __config_settings_draw's 12) --
|
# Label field is 13 wide (one wider than __config_settings_draw's 12) --
|
||||||
# the longest real sub-category label ("Notifications") is 13 chars.
|
# the longest real sub-category label ("Notifications") is 13 chars. The
|
||||||
# Description field absorbs the difference so every row still totals
|
# description field absorbs the difference inside the frame
|
||||||
# iw+2, matching the surrounding box lines exactly.
|
# (field_w = iw - 21 - label_w = iw - 34), so every row still totals iw+2.
|
||||||
set -l label_w 13
|
|
||||||
set -l desc_w (math $iw - 34)
|
|
||||||
|
|
||||||
set -l cat_label (string replace -r '^__fish_config_op_' '' -- $category_var)
|
set -l cat_label (string replace -r '^__fish_config_op_' '' -- $category_var)
|
||||||
# Scope indicator: toggling a row on this page writes -U (Universal,
|
# Scope indicator: toggling a row on this page writes -U (Universal,
|
||||||
@@ -77,32 +65,18 @@ function __config_settings_draw_subcat
|
|||||||
set -l scope_label Universal
|
set -l scope_label Universal
|
||||||
test "$cur_scope" = session; and set scope_label Session
|
test "$cur_scope" = session; and set scope_label Session
|
||||||
# Title layout is "┌─ Sub-categories: <label> (<scope>) ───┐"; the
|
# Title layout is "┌─ Sub-categories: <label> (<scope>) ───┐"; the
|
||||||
# dash count must absorb every visible char added around cat_label so
|
# dash count absorbs every visible char added around cat_label so the
|
||||||
# the line still totals iw+2, matching the surrounding box exactly --
|
# line still totals iw+2, matching the surrounding box exactly. The
|
||||||
# see the DESCRIPTION doc comment above for why this is hand-verified,
|
# frame derives it from the segment's visible width, so it no longer
|
||||||
# not eyeballed.
|
# has to be hand-verified here.
|
||||||
set -l title_dashes (math $iw - (string length -- $cat_label) - (string length -- $scope_label) - 22)
|
__config_settings_frame title $iw $p \
|
||||||
printf '%s┌─%s Sub-categories: %s (%s)%s %s┐\n' \
|
"$c_head Sub-categories: $cat_label ($scope_label)$c_reset "
|
||||||
$p $c_head "$cat_label" $scope_label "$c_reset" (string repeat -n (math "max(0, $title_dashes)") '─')
|
|
||||||
|
|
||||||
printf '%s│%s│\n' $p $HBR
|
printf '%s│%s│\n' $p $HBR
|
||||||
|
|
||||||
# Row 0: the category's own toggle, still meaningful as the cascade
|
# Row 0: the category's own toggle, still meaningful as the cascade
|
||||||
# default any DEFAULT-valued sub-category below falls back to.
|
# default any DEFAULT-valued sub-category below falls back to.
|
||||||
set -l cat_val (__config_settings_get_val $category_var $cur_scope)
|
set -l cat_val (__config_settings_get_val $category_var $cur_scope)
|
||||||
set -l cat_badge
|
|
||||||
switch $cat_val
|
|
||||||
case on
|
|
||||||
set cat_badge "$c_ok"" ON$c_reset"
|
|
||||||
case off
|
|
||||||
set cat_badge "$c_err""OFF $c_reset"
|
|
||||||
case '*'
|
|
||||||
set cat_badge "$c_dim""DEFAULT$c_reset"
|
|
||||||
end
|
|
||||||
set -l cat_curs " "
|
|
||||||
if test $cur_row -eq 0
|
|
||||||
set cat_curs "$c_sel▶$c_reset "
|
|
||||||
end
|
|
||||||
set -l cat_desc "cascade default"
|
set -l cat_desc "cascade default"
|
||||||
if test $iw -ge 68
|
if test $iw -ge 68
|
||||||
set cat_desc "default for all sub-cats below"
|
set cat_desc "default for all sub-cats below"
|
||||||
@@ -110,38 +84,35 @@ function __config_settings_draw_subcat
|
|||||||
if test $iw -ge 72
|
if test $iw -ge 72
|
||||||
set cat_desc "default for all sub-categories below"
|
set cat_desc "default for all sub-categories below"
|
||||||
end
|
end
|
||||||
printf '%s│ %s%s [ %s ] %s │\n' $p $cat_curs \
|
# `cut` for the same reason as the sub-category rows below. It also
|
||||||
(string pad -r -w $label_w -- "(category)") $cat_badge \
|
# truncates the label, which the old code did not -- provably inert here,
|
||||||
(string pad -r -w $desc_w -- (string sub -l $desc_w -- $cat_desc))
|
# since "(category)" is a 10-char literal against a 13-wide field.
|
||||||
|
__config_settings_frame row $iw $p \
|
||||||
|
(__config_settings_frame cursor 0 $cur_row) \
|
||||||
|
"(category)" 13 \
|
||||||
|
(__config_settings_frame badge $cat_val) \
|
||||||
|
$cat_desc cut
|
||||||
|
|
||||||
printf '%s│ %s │\n' $p (string repeat -n (math $iw - 6) '─')
|
printf '%s│ %s │\n' $p (string repeat -n (math $iw - 6) '─')
|
||||||
|
|
||||||
for i in (seq 1 $n)
|
for i in (seq 1 $n)
|
||||||
set -l fields (string split -- \t $rows[$i])
|
set -l fields (string split -- \t $rows[$i])
|
||||||
set -l slug $fields[1]
|
|
||||||
set -l label $fields[2]
|
set -l label $fields[2]
|
||||||
set -l desc $fields[3]
|
set -l desc $fields[3]
|
||||||
set -l subcat_var "$category_var"_(string replace -a -- '-' '_' $slug)
|
set -l subcat_var "$category_var"_(string replace -a -- '-' '_' $fields[1])
|
||||||
|
|
||||||
set -l val (__config_settings_get_val $subcat_var $cur_scope)
|
set -l val (__config_settings_get_val $subcat_var $cur_scope)
|
||||||
set -l badge
|
# `cut`: these labels and descriptions are static data from
|
||||||
switch $val
|
# __config_settings_subcats, not authored per width tier the way
|
||||||
case on
|
# __config_settings_draw's are, and several run well past the
|
||||||
set badge "$c_ok"" ON$c_reset"
|
# narrower tiers' fields. `string pad` only ever grows a string, so
|
||||||
case off
|
# they must be truncated before padding or the box stops being
|
||||||
set badge "$c_err""OFF $c_reset"
|
# rectangular. This is the divergence the DESCRIPTION block above
|
||||||
case '*'
|
# documents -- do not "simplify" it to `pad`.
|
||||||
set badge "$c_dim""DEFAULT$c_reset"
|
__config_settings_frame row $iw $p \
|
||||||
end
|
(__config_settings_frame cursor $i $cur_row) \
|
||||||
|
$label 13 \
|
||||||
set -l curs " "
|
(__config_settings_frame badge $val) \
|
||||||
if test $i -eq $cur_row
|
$desc cut
|
||||||
set curs "$c_sel▶$c_reset "
|
|
||||||
end
|
|
||||||
|
|
||||||
set -l lpad (string pad -r -w $label_w -- (string sub -l $label_w -- $label))
|
|
||||||
set -l dpad (string pad -r -w $desc_w -- (string sub -l $desc_w -- $desc))
|
|
||||||
printf '%s│ %s%s [ %s ] %s │\n' $p $curs $lpad $badge $dpad
|
|
||||||
end
|
end
|
||||||
|
|
||||||
printf '%s│%s│\n' $p $HBR
|
printf '%s│%s│\n' $p $HBR
|
||||||
|
|||||||
Reference in New Issue
Block a user