refactor(config-settings): shared frame renderer + line-diff redraw #133

Merged
rootiest merged 13 commits from refactor/config-settings-renderer into main 2026-09-08 16:28:53 +00:00
2 changed files with 12 additions and 9 deletions
Showing only changes of commit 3c4f720749 - Show all commits
+7 -5
View File
@@ -147,7 +147,6 @@ function config-settings --description 'Interactive TUI for managing fish config
set -l cur_row 0 set -l cur_row 0
set -l panel_h 0 # real value set by the first dispatch call below set -l panel_h 0 # real value set by the first dispatch call below
set -l new_frame # captured by __cs_dispatch_draw set -l new_frame # captured by __cs_dispatch_draw
set -l prev_frame # frame currently on screen; empty until first paint
set -l last_cols $COLUMNS set -l last_cols $COLUMNS
# ── Terminal setup ──────────────────────────────────── # ── Terminal setup ────────────────────────────────────
@@ -344,6 +343,7 @@ function config-settings --description 'Interactive TUI for managing fish config
# Full erase once to enter edit mode; per-keystroke # Full erase once to enter edit mode; per-keystroke
# redraws below diff against the previous edit frame. # redraws below diff against the previous edit frame.
set -l edit_frame (__config_settings_draw_value $cur_row $page edit "$buf") set -l edit_frame (__config_settings_draw_value $cur_row $page edit "$buf")
set -l prev_edit_frame
set -l pml (math --scale=0 "($last_cols + 78) / 2") set -l pml (math --scale=0 "($last_cols + 78) / 2")
set -l eh (math --scale=0 "$panel_h * max(1, ceil($pml / $COLUMNS))") set -l eh (math --scale=0 "$panel_h * max(1, ceil($pml / $COLUMNS))")
printf '\e[%dA\e[J' $eh printf '\e[%dA\e[J' $eh
@@ -370,15 +370,16 @@ function config-settings --description 'Interactive TUI for managing fish config
set prev_edit_frame $edit_frame set prev_edit_frame $edit_frame
set edit_frame (__config_settings_draw_value $cur_row $page edit "$buf") set edit_frame (__config_settings_draw_value $cur_row $page edit "$buf")
if test (count $edit_frame) -eq (count $prev_edit_frame) -a "$COLUMNS" = "$last_cols" if test (count $edit_frame) -eq (count $prev_edit_frame) -a "$COLUMNS" = "$last_cols" -a $COLUMNS -ge 52
# `| string collect` is required on each join -- # `| string collect` is required on each join --
# see the identical note in the main loop's # see the identical note in the main loop's
# diff-path call. # diff-path call.
printf '\e[%dA' (count $edit_frame) printf '\e[%dA' (count $edit_frame)
__config_settings_diff_redraw (string join \n -- $prev_edit_frame | string collect) (string join \n -- $edit_frame | string collect) __config_settings_diff_redraw (string join \n -- $prev_edit_frame | string collect) (string join \n -- $edit_frame | string collect)
else else
set -l ph (count $prev_edit_frame)
set -l pml (math --scale=0 "($last_cols + 78) / 2") set -l pml (math --scale=0 "($last_cols + 78) / 2")
set -l eh (math --scale=0 "(count $prev_edit_frame) * max(1, ceil($pml / $COLUMNS))") set -l eh (math --scale=0 "$ph * max(1, ceil($pml / $COLUMNS))")
printf '\e[%dA\e[J' $eh printf '\e[%dA\e[J' $eh
printf '%s\n' $edit_frame printf '%s\n' $edit_frame
end end
@@ -399,6 +400,7 @@ function config-settings --description 'Interactive TUI for managing fish config
printf '\e[%dA\e[J' $eh printf '\e[%dA\e[J' $eh
set last_cols $COLUMNS set last_cols $COLUMNS
__cs_dispatch_draw __cs_dispatch_draw
printf '%s\n' $new_frame
set did_redraw 1 set did_redraw 1
end end
end end
@@ -423,10 +425,10 @@ function config-settings --description 'Interactive TUI for managing fish config
end end
set -l old_h $panel_h set -l old_h $panel_h
set prev_frame $new_frame set -l prev_frame $new_frame
__cs_dispatch_draw __cs_dispatch_draw
if test $panel_h -eq $old_h -a "$COLUMNS" = "$last_cols" if test $panel_h -eq $old_h -a "$COLUMNS" = "$last_cols" -a $COLUMNS -ge 52
# Diff path: geometry and width unchanged since the last frame -- # Diff path: geometry and width unchanged since the last frame --
# move up without erasing, rewrite only the lines that changed. # move up without erasing, rewrite only the lines that changed.
# `| string collect` is required on each join: command # `| string collect` is required on each join: command
+5 -4
View File
@@ -153,10 +153,11 @@ set -U __fish_user_dots_symlink false
# __fish_scrollback_history_max_files: unset -> DEFAULT # __fish_scrollback_history_max_files: unset -> DEFAULT
# ── Case emitter ────────────────────────────────────────────────────────── # ── Case emitter ──────────────────────────────────────────────────────────
# panel_h is passed in by the caller, mirroring __cs_dispatch_draw in # panel_h is passed in by the caller, independently declaring the expected
# config-settings.fish: the category list and both value pages are a fixed 16 # height for each page so it can be cross-checked against the draw functions'
# lines, a sub-category page is 7 + <sub-category count>. The golden records # real output: the category list and both value pages are a fixed 16 lines, a
# the declared height, the measured line count, and the erase sequence derived # sub-category page is 7 + <sub-category count>. The golden records the
# declared height, the measured line count, and the erase sequence derived
# from the declared height -- so flattening the fixed/dynamic divergence, or # from the declared height -- so flattening the fixed/dynamic divergence, or
# changing a page's height at all, breaks the compare three ways. # changing a page's height at all, breaks the compare three ways.
function _cs_render_case --argument-names label panel_h function _cs_render_case --argument-names label panel_h