@@ -67,6 +67,53 @@ column_wrap() {
6767 echo -e " ${footer// ^/ ${pad} } "
6868}
6969
70+ # arg1: optional page to mark as active
71+ # prints: a header string with the active page highlighted yellow
72+ # returns: nothing
73+
74+ # shellcheck disable=SC2120
75+ global_header () {
76+ local header page tab
77+
78+ # Accept a parameter to explicitly set a page to be shown
79+ if [ -n " ${1} " ]; then
80+ page=" ${1} "
81+ else
82+ # Name of the calling function
83+ page=" ${FUNCNAME[1]} "
84+ fi
85+
86+ # Set the entire string to one color
87+ header=" \\ 033[0;37m Boot Environments | Snapshots | Kernels | Pool Status | Logs | Help \\ 033[0m"
88+
89+ case " ${page} " in
90+ draw_be)
91+ tab=" Boot Environments"
92+ ;;
93+ draw_kernel)
94+ tab=" Kernels"
95+ ;;
96+ draw_snapshots|draw_diff)
97+ tab=" Snapshots"
98+ ;;
99+ draw_pool_status)
100+ tab=" Pool Status"
101+ ;;
102+ help_pager)
103+ tab=" Help"
104+ ;;
105+ zlogtail)
106+ tab=" Logs"
107+ ;;
108+ * )
109+ zdebug " Called from unknown function: ${page} "
110+ ;;
111+ esac
112+
113+ # change the name of the selected tab to be yellow
114+ echo -n -e " ${header/ ${tab} / \\ 033[1;33m${tab} \\ 033[0;37m} "
115+ }
116+
70117# arg1: Path to file with detected boot environments, 1 per line
71118# prints: key pressed, boot environment on successful selection
72119# returns: 0 on successful selection, 1 if Esc was pressed, 130 if BE list is missing
@@ -109,7 +156,8 @@ draw_be() {
109156
110157 if ! selected=" $( ${FUZZYSEL} -0 --prompt " BE > " \
111158 ${expects} ${expects// alt-/ ctrl-} ${expects// alt-/ ctrl-alt-} \
112- --header=" ${header} " --preview-window=" up:${PREVIEW_HEIGHT} " \
159+ ${HAS_BORDER_LABEL: +--border-label=" $( global_header ) " } \
160+ --header=" ${header} " --preview-window=" up:${PREVIEW_HEIGHT} ,border-sharp" \
113161 --preview=" /libexec/zfsbootmenu-preview {} ${BOOTFS} " < " ${env} " ) " ; then
114162 return 1
115163 fi
@@ -156,9 +204,10 @@ draw_kernel() {
156204
157205 if ! selected=" $( HELP_SECTION=kernel-management ${FUZZYSEL} \
158206 --prompt " ${benv} > " --tac --with-nth=2 --header=" ${header} " \
207+ ${HAS_BORDER_LABEL: +--border-label=" $( global_header ) " } \
159208 ${expects} ${expects// alt-/ ctrl-} ${expects// alt-/ ctrl-alt-} \
160209 --preview=" /libexec/zfsbootmenu-preview ${benv} ${BOOTFS} " \
161- --preview-window=" up:${PREVIEW_HEIGHT} " < " ${_kernels} " ) " ; then
210+ --preview-window=" up:${PREVIEW_HEIGHT} ,border-sharp " < " ${_kernels} " ) " ; then
162211 return 1
163212 fi
164213
@@ -206,14 +255,28 @@ draw_snapshots() {
206255
207256 zdebug " snapshots: ${snapshots[*]} "
208257
209- if ! selected=" $( HELP_SECTION=snapshot-management ${FUZZYSEL} \
258+ # when defined this controls passing an additional parameter to zfsbootmenu-preview
259+ # as well as extending the preview window height by 1
260+ # when undefined, it triggers added 0 to the window height, leaving it as-is
261+
262+ local LEGACY_CONTEXT
263+ if [ -z " ${HAS_BORDER_LABEL} " ]; then
264+ LEGACY_CONTEXT=1
265+ fi
266+
267+ if ! selected=" $( \
268+ HELP_SECTION=snapshot-management ${FUZZYSEL} \
210269 --prompt " Snapshot > " --header=" ${header} " --tac --multi 2 \
270+ ${HAS_BORDER_LABEL: +--border-label=" $( global_header ) " } \
211271 ${expects} ${expects// alt-/ ctrl-} ${expects// alt-/ ctrl-alt-} \
212272 --bind=' alt-d:execute[ /libexec/zfunc draw_diff {+} ]' \
213273 --bind=' ctrl-d:execute[ /libexec/zfunc draw_diff {+} ]' \
214274 --bind=' ctrl-alt-d:execute[ /libexec/zfunc draw_diff {+} ]' \
215- --preview=" /libexec/zfsbootmenu-preview ${benv} ${BOOTFS} '${context} '" \
216- --preview-window=" up:$(( PREVIEW_HEIGHT + 1 )) " <<< " ${snapshots}" ) " ; then
275+ ${HAS_BORDER_LABEL: +--preview-label-pos=bottom} \
276+ ${HAS_BORDER_LABEL: +--preview-label=" $( colorize orange " ${context} " ) " } \
277+ --preview=" /libexec/zfsbootmenu-preview ${benv} ${BOOTFS} ${LEGACY_CONTEXT: +\" ${context} \" } " \
278+ --preview-window=" up:$(( PREVIEW_HEIGHT + ${LEGACY_CONTEXT:- 0} )) ,border-sharp" <<< " ${snapshots}" ) "
279+ then
217280 return 1
218281 fi
219282
@@ -291,8 +354,9 @@ draw_diff() {
291354 line_two=" ${left_pad} $( colorize green " +++${diff_target} " ) "
292355
293356 sed " s,${mnt} ,," < & 3 | HELP_SECTION=diff-viewer ${FUZZYSEL} --prompt " > " \
357+ ${HAS_BORDER_LABEL: +--border-label=" $( global_header ) " } \
294358 --preview=" echo -e '${line_one} \n${line_two} '" --no-sort \
295- --preview-window=" up:${PREVIEW_HEIGHT} "
359+ --preview-window=" up:${PREVIEW_HEIGHT} ,border-sharp "
296360
297361 [ -n " ${zfs_diff_PID} " ] && kill " ${zfs_diff_PID} "
298362
@@ -322,7 +386,8 @@ draw_pool_status() {
322386 if ! selected=" $( zpool list -H -o name |
323387 HELP_SECTION=zpool-health ${FUZZYSEL} \
324388 --prompt " Pool > " --tac --expect=alt-r,ctrl-r,ctrl-alt-r \
325- --preview-window=" right:${psize} " \
389+ ${HAS_BORDER_LABEL: +--border-label=" $( global_header ) " } \
390+ --preview-window=" right:${psize} ,border-sharp" \
326391 --preview=" zpool status -v {}" --header=" ${header} " ) " ; then
327392 return 1
328393 fi
0 commit comments