chiefwiggum 1.2.8 → 1.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/chiefwiggum +52 -11
- package/package.json +1 -1
package/chiefwiggum
CHANGED
|
@@ -100,25 +100,66 @@ ask_choice() {
|
|
|
100
100
|
local prompt="$1"
|
|
101
101
|
shift
|
|
102
102
|
local options=("$@")
|
|
103
|
+
local selected=0
|
|
104
|
+
local key
|
|
103
105
|
|
|
104
106
|
echo ""
|
|
105
107
|
echo -e "${BOLD}${prompt}${NC}"
|
|
106
108
|
echo ""
|
|
107
109
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
110
|
+
# Hide cursor
|
|
111
|
+
tput civis 2>/dev/null
|
|
112
|
+
|
|
113
|
+
# Draw menu with current selection highlighted
|
|
114
|
+
draw_menu() {
|
|
115
|
+
for i in "${!options[@]}"; do
|
|
116
|
+
tput el 2>/dev/null # Clear line
|
|
117
|
+
if [ "$i" -eq "$selected" ]; then
|
|
118
|
+
echo -e " ${CYAN}▸${NC} ${BOLD}${options[$i]}${NC}"
|
|
119
|
+
else
|
|
120
|
+
echo -e " ${options[$i]}"
|
|
121
|
+
fi
|
|
122
|
+
done
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
draw_menu
|
|
114
126
|
|
|
115
127
|
while true; do
|
|
116
|
-
read -
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
128
|
+
read -rsn1 key
|
|
129
|
+
|
|
130
|
+
case "$key" in
|
|
131
|
+
$'\x1b') # Escape sequence (arrow keys)
|
|
132
|
+
read -rsn2 key
|
|
133
|
+
case "$key" in
|
|
134
|
+
'[A'|'OA') # Up arrow
|
|
135
|
+
((selected > 0)) && ((selected--))
|
|
136
|
+
;;
|
|
137
|
+
'[B'|'OB') # Down arrow
|
|
138
|
+
((selected < ${#options[@]} - 1)) && ((selected++))
|
|
139
|
+
;;
|
|
140
|
+
esac
|
|
141
|
+
;;
|
|
142
|
+
'k') # Vim up
|
|
143
|
+
((selected > 0)) && ((selected--))
|
|
144
|
+
;;
|
|
145
|
+
'j') # Vim down
|
|
146
|
+
((selected < ${#options[@]} - 1)) && ((selected++))
|
|
147
|
+
;;
|
|
148
|
+
'') # Enter key
|
|
149
|
+
break
|
|
150
|
+
;;
|
|
151
|
+
esac
|
|
152
|
+
|
|
153
|
+
# Move cursor back up and redraw
|
|
154
|
+
tput cuu ${#options[@]} 2>/dev/null
|
|
155
|
+
draw_menu
|
|
121
156
|
done
|
|
157
|
+
|
|
158
|
+
# Show cursor again
|
|
159
|
+
tput cnorm 2>/dev/null
|
|
160
|
+
echo ""
|
|
161
|
+
|
|
162
|
+
return $selected
|
|
122
163
|
}
|
|
123
164
|
|
|
124
165
|
ask_text() {
|