Skip to content

Commit 3da5547

Browse files
committed
Center key bind text on horizontal layout fzf screens
1 parent df8ab05 commit 3da5547

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

zfsbootmenu/lib/zfsbootmenu-lib.sh

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ csv_cat() {
3838
# returns: nothing
3939

4040
column_wrap() {
41-
local footer
41+
local footer max lpad pad
4242
footer="${1}"
4343

4444
if [ "${COLUMNS:-0}" -lt 80 ] || [ -z "${HAS_COLUMN}" ] ; then
@@ -53,9 +53,18 @@ column_wrap() {
5353
footer="$( echo -e "${footer}" | column -t -s ':' )"
5454
fi
5555

56+
# Find the number of characters in the longest line
57+
max="$( echo -e "${footer}" | awk 'BEGIN{l=0} length>l {l=length}; END{print l}' )"
58+
59+
# remove an extra 3 - 1 for '^', 2 for the fzf gutter
60+
lpad="$(( (COLUMNS - max - 3) / 2 ))"
61+
62+
[[ ${lpad} -gt 0 ]] && printf -v pad "%*s" "${lpad}" ''
63+
5664
footer="${footer//\[/\\033\[0;32m\[}"
5765
footer="${footer//\]/\]\\033\[0m}"
58-
echo -e "${footer}"
66+
67+
echo -e "${footer//^/${pad}}"
5968
}
6069

6170
# arg1: Path to file with detected boot environments, 1 per line
@@ -87,14 +96,14 @@ draw_be() {
8796
fi
8897

8998
header="$( column_wrap "\
90-
[RETURN] boot:[ESCAPE] refresh view:[CTRL+P] pool status
91-
[CTRL+D] set bootfs:[CTRL+S] snapshots:[CTRL+K] kernels
92-
[CTRL+E] edit kcl:[CTRL+J] jump into chroot:[CTRL+R] recovery shell
93-
${kcl_text:+${kcl_text}:}[CTRL+L] view logs:${blank}[CTRL+H] help" \
99+
^[RETURN] boot:[ESCAPE] refresh view:[CTRL+P] pool status
100+
^[CTRL+D] set bootfs:[CTRL+S] snapshots:[CTRL+K] kernels
101+
^[CTRL+E] edit kcl:[CTRL+J] jump into chroot:[CTRL+R] recovery shell
102+
^${kcl_text:+${kcl_text}:}[CTRL+L] view logs:${blank}[CTRL+H] help" \
94103
"\
95-
[RETURN] boot
96-
[CTRL+R] recovery shell
97-
[CTRL+H] help" )"
104+
^[RETURN] boot
105+
^[CTRL+R] recovery shell
106+
^[CTRL+H] help" )"
98107

99108
expects="--expect=alt-e,alt-k,alt-d,alt-s,alt-c,alt-r,alt-p,alt-w,alt-j,alt-o${kcl_bind:+,${kcl_bind}}"
100109

@@ -135,13 +144,13 @@ draw_kernel() {
135144
zdebug "using kernels file: ${_kernels}"
136145

137146
header="$( column_wrap "\
138-
[RETURN] boot:[ESCAPE] back
139-
[CTRL+D] set default:[CTRL+U] unset default
140-
[CTRL+L] view logs:[CTRL+H] help" \
147+
^[RETURN] boot:[ESCAPE] back
148+
^[CTRL+D] set default:[CTRL+U] unset default
149+
^[CTRL+L] view logs:[CTRL+H] help" \
141150
"\
142-
[RETURN] boot
143-
[CTRL+D] set default
144-
[CTRL+H] help" )"
151+
^[RETURN] boot
152+
^[CTRL+D] set default
153+
^[CTRL+H] help" )"
145154

146155
expects="--expect=alt-d,alt-u"
147156

@@ -178,14 +187,14 @@ draw_snapshots() {
178187
sort_key="$( get_sort_key )"
179188

180189
header="$( column_wrap "\
181-
[RETURN] duplicate:[CTRL+C] clone only:[CTRL+X] clone and promote
182-
[CTRL+D] show diff:[CTRL+R] rollback:[CTRL+N] create new snapshot
183-
[CTRL+L] view logs::[CTRL+J] jump into chroot
184-
[CTRL+H] help::[ESCAPE] back" \
190+
^[RETURN] duplicate:[CTRL+C] clone only:[CTRL+X] clone and promote
191+
^[CTRL+D] show diff:[CTRL+R] rollback:[CTRL+N] create new snapshot
192+
^[CTRL+L] view logs::[CTRL+J] jump into chroot
193+
^[CTRL+H] help::[ESCAPE] back" \
185194
"\
186-
[RETURN] duplicate
187-
[CTRL+D] show diff
188-
[CTRL+H] help" )"
195+
^[RETURN] duplicate
196+
^[CTRL+D] show diff
197+
^[CTRL+H] help" )"
189198

190199
context="Note: for diff viewer, use tab to select/deselect up to two items"
191200

0 commit comments

Comments
 (0)