feat(zsh): whiptail helpers
This commit is contained in:
parent
d45e45e011
commit
9be893d07f
55
.zshrc
55
.zshrc
@ -311,16 +311,61 @@ bindkey -M viins '\en' nnn-file-widget
|
|||||||
|
|
||||||
# Whiptail helper
|
# Whiptail helper
|
||||||
#
|
#
|
||||||
menu_choose() {
|
# see https://stackoverflow.com/questions/1970180/whiptail-how-to-redirect-output-to-environment-variable
|
||||||
|
|
||||||
|
whiptail_checklist() {
|
||||||
|
autoload zmathfunc; zmathfunc # min, max, sum
|
||||||
|
eval $(resize) # COLUMNS, LINES
|
||||||
|
|
||||||
local res title="$1" text="$2"
|
local res title="$1" text="$2"
|
||||||
|
(( width=max(30, $#text) ))
|
||||||
shift 2
|
shift 2
|
||||||
|
|
||||||
|
# Make tags compatible with whiptail
|
||||||
local -a tags
|
local -a tags
|
||||||
for tag;
|
for tag; do
|
||||||
{ tags+=($tag $tag) }
|
tags+=($tag $tag 0)
|
||||||
|
(( width=max(width, $#tag) ))
|
||||||
|
done
|
||||||
|
|
||||||
# see https://stackoverflow.com/questions/1970180/whiptail-how-to-redirect-output-to-environment-variable
|
# Compute "best" width & height
|
||||||
tag=$(whiptail --title $title --menu $text 25 40 15 $tags --notags 3>&1 1>&2 2>&3 3>&-)
|
(( list_height=min(20, ${#*}, LINES * .5) ))
|
||||||
|
(( height=min(list_height+8, LINES) ))
|
||||||
|
(( width=min(width + 9, COLUMNS * .75) ))
|
||||||
|
|
||||||
|
tag=$(whiptail --title $title \
|
||||||
|
--checklist $text $height $width $list_height $tags \
|
||||||
|
--separate-output --notags 3>&1 1>&2 2>&3 3>&-)
|
||||||
|
res=$?
|
||||||
|
|
||||||
|
# Use res=${(f)"$(whiptail_checklist...)"} to ignore spaces
|
||||||
|
echo $tag
|
||||||
|
return $res
|
||||||
|
}
|
||||||
|
|
||||||
|
whiptail_menu() {
|
||||||
|
autoload zmathfunc; zmathfunc # min, max, sum
|
||||||
|
eval $(resize) # COLUMNS, LINES
|
||||||
|
|
||||||
|
local res title="$1" text="$2"
|
||||||
|
(( width=max(30, $#text) ))
|
||||||
|
shift 2
|
||||||
|
|
||||||
|
# Make tags compatible with whiptail
|
||||||
|
local -a tags
|
||||||
|
for tag; do
|
||||||
|
tags+=($tag $tag)
|
||||||
|
(( width=max(width, $#tag) ))
|
||||||
|
done
|
||||||
|
|
||||||
|
# Compute "best" width & height
|
||||||
|
(( menu_height=min(20, ${#*}, LINES * .5) ))
|
||||||
|
(( height=min(menu_height+8, LINES) ))
|
||||||
|
(( width=min(width + 5, COLUMNS * .75) ))
|
||||||
|
|
||||||
|
tag=$(whiptail --title $title \
|
||||||
|
--menu $text $height $width $menu_height $tags \
|
||||||
|
--notags 3>&1 1>&2 2>&3 3>&-)
|
||||||
res=$?
|
res=$?
|
||||||
|
|
||||||
echo $tag
|
echo $tag
|
||||||
|
Loading…
Reference in New Issue
Block a user