From f205f143613958464e6e9e0d2dd815d76d36b631 Mon Sep 17 00:00:00 2001 From: davidovski Date: Sun, 15 May 2022 21:56:06 +0100 Subject: added paged radio menu to xitui --- src/glyphs.sh | 2 +- src/xitui.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/glyphs.sh b/src/glyphs.sh index fce29b2..b4ecccd 100644 --- a/src/glyphs.sh +++ b/src/glyphs.sh @@ -8,7 +8,7 @@ export CROSSMARK="✘" export HOURGLASS="⧖" export LARGE_CIRCLE="◯" export REFRESH="🗘" -export TABCHAR="╰┈➤ " +export TABCHAR="╚═" export XI="Ξ" export LOGO_SMALL="████████ diff --git a/src/xitui.sh b/src/xitui.sh index da60017..dcfaf02 100644 --- a/src/xitui.sh +++ b/src/xitui.sh @@ -49,7 +49,7 @@ t_set_tty () { t_clean () { stty $SAVED_TTY_SETTINGS tput clear - reset + t_yes_cur } readc () { @@ -349,10 +349,28 @@ t_prompt () { t_dialog "$@" "" } +t_yesno () { + t_dialog "$@" "" "" + [ "$T_RESULT" = "" ] +} + t_input () { stty $SAVED_TTY_SETTINGS t_msg "$@ +>" > $(tty) + t_yes_cu + read var + t_set_tty + t_no_cur + export T_RESULT="$var" +} + +t_input_hidden () { + stty $SAVED_TTY_SETTINGS + stty -echo + t_msg "$@ + >" > $(tty) t_yes_cur read var @@ -365,15 +383,41 @@ t_tail() { t_drw_txt 0 7 "$(tail -$((LINES-14)) $1)" } +t_paged_radio () { + perpage=9 + heading=$1 + shift + + T_RESULT="more..." + page=0 + max_pages=$((($#/perpage)+1)) + while true; do + start=$((page*perpage)) + current=$(echo $@ | tr ' ' '\n' | tail -$(($#-start)) | head -$perpage) + current="$current more..." + + t_cls_ptrn + t_radio "$heading" $current + [ "$T_RESULT" = "more..." ] && page=$(((page+1)%max_pages)) || return 0 + done +} + t_demo () { t_init t_no_cur + t_cls_ptrn t_prompt "Hello world?" t_cls_ptrn + t_paged_radio "Pick a number" $(seq 34) + t_prompt "You selected the following: $T_RESULT" + t_cls_ptrn + + exit 1 + t_radio "Pick one:" "toast" "bread" "bread but fishy" "empty sandwich" t_prompt "You selected the following: $T_RESULT" t_cls_ptrn @@ -391,7 +435,7 @@ t_demo () { t_prompt "Hello $T_RESULT" t_cls_ptrn - file=./xit.sh + file=$2.sh [ -f $file ] && { t_tail $file } || { -- cgit v1.2.1