-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
demo_menu
executable file
·110 lines (103 loc) · 4.51 KB
/
demo_menu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash
source bashui
defb(){
# Create default button to copy
#1 X(row) coordinate
#2 Y(line) coordinate
#3 Button name
#4 Function to run
#5 Text color
#6 Border color
#7 Background color
# 1 2 3 4 5 6 7
button "$1" "$2" "butt $3" "fun_${3,,}" "$wht" "$ylw" "$bblk"
}
clr(){ for i in {1..4}; do XY 1 $i "%${COLUMNS}s"; done; } # clear output area
but_d(){ defb "$1" "$2" D; }
but_e(){ defb "$1" "$2" E; }
but_f(){ defb "$1" "$2" F; }
fun_d(){ clr; XY 1 1 "butt D; target: $_target_"; }
fun_e(){ clr; XY 1 1 "butt E; description: ${_target_[1]}"; }
fun_f(){ clr; XY 1 1 "butt F; all items of target:"
printf -v text -- '%s\n' "${_target_[@]}"
XY 1 2 "$text"; }
clear
w=$((COLUMNS-10))
my_items(){
#1 X(row) coordinate
#2 Y(line) coordinate
#3 Window width
#4 Window height, min is 5
#5 Number of columns or columns sizes in % of Width
#6 Name of the list
#7 Text color
#8 Border color
#9 Background
local mess="Columns via number(${bred}Esc to continue$bblk)"
# 1 2 3 4 5 6 7 8 9 data
items 10 5 $w 20 3 "$mess" "$wht" "$ylw" "$bblk" "$@"
}
my_items2(){
local mess="Columns via percent of Width(${bred}Esc to exit$bblk)"
# 1 2 3 4 5 6 7 8 9 data
items 10 5 $w 20 '30 55 15' "$mess" "$wht" "$ylw" "$bblk" "$@"
}
data=(
#-------------{ first line - column descriptions }--------------------
$red'Item name' $blu'Item description' $grn'Status'
#-----------------------{ the data }----------------------------------
'first' $BLD$ylw'Long description text' 'true'
'second' 'Description 2' 'O_o'
'third' 'description 3' 'false'
'fourth' "${red}Long ${grn}description ${blu}text" 'true'
'' '' ''
$ylw'fifth' 'Description 2' 'O_o'
'sixth' 'description 3' 'false'
'midle' $grn'Long description text' 'true'
'long name row2' 'Description 2' 'O_o'
'' '' ''
'row 3' 'description 3' 'false'
'row1' $blu'Long description text' 'true'
'row1' 'Long description text' 'true'
'last' 'Description 2' 'O_o'
'first' $BLD$ylw'Long description text' 'true'
'second' 'Description 2' 'O_o'
'third' 'description 3' 'false'
'fourth' "${red}Long ${grn}description ${blu}text" 'true'
'' '' ''
$ylw'fifth' 'Description 2' 'O_o'
'sixth' 'description 3' 'false'
'midle' $grn'Long description text' 'true'
'long name row2' 'Description 2' 'O_o'
'' '' ''
'row 3' 'description 3' 'false'
'row1' $blu'Long description text' 'true'
'row1' 'Long description text' 'true'
'last' 'Description 2' 'O_o'
)
xbuttons=(but_d but_e but_f)
butts (){ x_row $LINES "${xbuttons[@]}"; }
ilist (){ my_items "${data[@]}" ; }
ilist2(){ my_items2 "${data[@]}" ; }
menu (){
cursor off
default_button but_d
while true; do
$1; butts
read_input
case $_input_ in
up ) select_prev_item "${data[@]}" ;;
down ) select_next_item "${data[@]}" ;;
left ) select_prev_butt "${xbuttons[@]}";;
right ) select_next_butt "${xbuttons[@]}";;
enter ) press_button butts ;;
escape ) return;;
pgup ) select_prev_item --fast "${data[@]}";;
pgdown ) select_next_item --fast "${data[@]}";;
* ) select_by_hot_key $_input_ "${data[@]}";;
esac
done
}
menu ilist # Columns via number
clear
menu ilist2 # Columns via percent