Skip to content

Commit 00ef434

Browse files
committed
Add/use border label feature flag
fzf 0.35 added the ability to added labels to borders - both for the entire application window and for the preview window. This can now be used to add a global header, present on all fzf instances. The snapshot screen can now optionally move context text to the bottom border around the preview window instead of being in it.
1 parent 562b14a commit 00ef434

File tree

5 files changed

+101
-8
lines changed

5 files changed

+101
-8
lines changed

zfsbootmenu/bin/zfsbootmenu

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ fuzzy_default_options=(
9696
"--bind" "\"ctrl-alt-l:execute[ /bin/zlogtail ]${HAS_REFRESH:++refresh-preview}\""
9797
)
9898

99+
if [ -n "${HAS_BORDER_LABEL}" ]; then
100+
# shellcheck disable=SC2016
101+
fuzzy_default_options+=(
102+
"--border-label-pos=top" "--border=top"
103+
"--color=border:white" "--separator=''"
104+
)
105+
fi
106+
99107
# shellcheck disable=SC2016,SC2086
100108
if [ ${loglevel:-4} -eq 7 ] ; then
101109
fuzzy_default_options+=(

zfsbootmenu/bin/zlogtail

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/bash
22

3+
# shellcheck disable=SC1091
4+
source /lib/zfsbootmenu-lib.sh >/dev/null 2>&1 || exit 1
5+
36
[ -f "${BASE}/have_errors" ] && rm "${BASE}/have_errors"
47
[ -f "${BASE}/have_warnings" ] && rm "${BASE}/have_warnings"
58

@@ -16,6 +19,14 @@ if [ -n "${HAS_DISABLED}" ]; then
1619
)
1720
fi
1821

22+
if [ -n "${HAS_BORDER_LABEL}" ]; then
23+
fuzzy_default_options+=(
24+
"--border-label-pos=top" "--border=top"
25+
"--border-label=\"$( global_header zlogtail )\""
26+
"--color=border:white"
27+
)
28+
fi
29+
1930
export FZF_DEFAULT_OPTS="${fuzzy_default_options[*]}"
2031

2132
# Try to use feature flags found on dmesg from util-linux

zfsbootmenu/install-helpers.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ create_zbm_conf() {
9898
has_disabled=1
9999
fi
100100

101+
# Check if fuzzy finder supports border labels
102+
# Added in fzf 0.35.0
103+
local has_border_label
104+
if echo "abc" | fzf -f "abc" --border-label=test --exit-0 >/dev/null 2>&1; then
105+
has_border_label=1
106+
fi
107+
101108
local has_column
102109
if command -v column >/dev/null 2>&1 ; then
103110
has_column=1
@@ -113,6 +120,7 @@ create_zbm_conf() {
113120
export BYTE_ORDER="${endian:-le}"
114121
export HAS_REFRESH="${has_refresh}"
115122
export HAS_DISABLED="${has_disabled}"
123+
export HAS_BORDER_LABEL="${has_border_label}"
116124
export HAS_COLUMN="${has_column}"
117125
EOF
118126
}

zfsbootmenu/lib/zfsbootmenu-lib.sh

Lines changed: 72 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

zfsbootmenu/libexec/zfsbootmenu-help

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ help_pager() {
4242
--with-nth=2.. \
4343
--bind pgup:preview-up,pgdn:preview-down \
4444
--preview="$0 -s {1}" \
45-
--preview-window="right:${PREVIEW_SIZE}:wrap" \
45+
--preview-window="right:${PREVIEW_SIZE}:wrap,border-sharp" \
4646
--header="${header}" \
47+
--border=top --border-label="$( global_header )" \
4748
--tac --inline-info --ansi --layout="reverse-list"
4849
}
4950

0 commit comments

Comments
 (0)