-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodules
More file actions
executable file
·397 lines (340 loc) · 13.9 KB
/
Copy pathmodules
File metadata and controls
executable file
·397 lines (340 loc) · 13.9 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
#!/bin/bash
# ═══════════════════════════════════════════════════════════════
# PLAINTEXT MODULE MANAGER - Interactive TUI
# Toggle modules on/off for faster development builds.
# Disabled modules are commented out in pom.xml files.
# Pre-push hook re-enables all modules automatically.
# ═══════════════════════════════════════════════════════════════
set -e
# PROJECT_DIR must be set by caller (e.g. start script) or defaults to cwd
SCRIPT_DIR="${PROJECT_DIR:-$(pwd)}"
source "$HOME/codeplain/plaintext-scripts/tui-common.sh"
source "$HOME/codeplain/plaintext-scripts/tui-modules-logic.sh"
# ── Non-interactive mode ─────────────────────────────────────
if [[ "$1" == "apply" ]]; then
load_state
if has_disabled; then
apply_changes
echo -e "${FG_GREEN}✓ Applied ($(count_enabled)/${TOTAL} enabled)${RESET}"
else
echo -e "${FG_GREEN}✓ All modules already enabled${RESET}"
fi
exit 0
fi
if [[ "$1" == "restore" || "$1" == "on" ]]; then
restore_all
echo -e "${FG_GREEN}✓ All modules re-enabled${RESET}"
exit 0
fi
if [[ "$1" == "status" ]]; then
load_state
enabled=$(count_enabled)
echo -e "${FG_BLUE}Module Status: ${FG_CYAN}${enabled}/${TOTAL} enabled${RESET}"
for ((i=0; i<TOTAL; i++)); do
if [[ "${TOGGLE_STATE[$i]}" == "1" ]]; then
echo -e " ${FG_GREEN}☑${RESET} ${TOGGLE_NAMES[$i]}"
else
echo -e " ${FG_DIM}☐ ${TOGGLE_NAMES[$i]}${RESET}"
fi
done
exit 0
fi
if [[ "$1" == "help" || "$1" == "-h" || "$1" == "--help" ]]; then
echo -e "${FG_BLUE}${BOLD}Plaintext Module Manager${RESET}"
echo ""
echo -e " ${FG_CYAN}./modules${RESET} Interactive TUI"
echo -e " ${FG_CYAN}./modules status${RESET} Show current state"
echo -e " ${FG_CYAN}./modules restore${RESET} Re-enable all modules"
echo -e " ${FG_CYAN}./modules help${RESET} Show this help"
exit 0
fi
# ── TUI ──────────────────────────────────────────────────────
load_state
CURSOR=0
SCROLL_OFF=0
cleanup() {
tui_cleanup
tput rmcup 2>/dev/null
}
trap cleanup EXIT
tui_init
tput smcup
draw() {
local TERM_ROWS TERM_COLS
TERM_ROWS=$(tput lines)
TERM_COLS=$(tput cols)
local enabled_count
enabled_count=$(count_enabled)
tput clear
# Total visible lines
local total_lines=$((7 + ${#ROOT_MODULES[@]} + TOTAL + 10))
local start_row=$(( (TERM_ROWS - total_lines) / 2 ))
[[ $start_row -lt 0 ]] && start_row=0
local col=$(( (TERM_COLS - TUI_W - 2) / 2 ))
[[ $col -lt 0 ]] && col=0
local row=$start_row
# ── Blue band header (uses custom rendering, not tui_hline) ──
tput cup $row $col
printf "${BG_BLUE}${FG_WHITE}${BOLD}"
local j; for ((j=0; j<TUI_W+2; j++)); do printf "▄"; done
printf "${RESET}"
row=$((row + 1)); tput cup $row $col
local title="PLAINTEXT MODULE MANAGER"
local tlen=${#title}
local lp=$(( (TUI_W - tlen) / 2 ))
local rp=$((TUI_W - tlen - lp))
printf "${BG_BLUE}${FG_WHITE}${BOLD} %${lp}s%s%${rp}s ${RESET}" "" "$title" ""
row=$((row + 1)); tput cup $row $col
local sub="${enabled_count}/${TOTAL} modules enabled"
local slen=${#sub}
lp=$(( (TUI_W - slen) / 2 ))
rp=$((TUI_W - slen - lp))
printf "${BG_BLUE}${FG_CYAN} %${lp}s%s%${rp}s ${RESET}" "" "$sub" ""
# ── Box top ──
row=$((row + 1)); tput cup $row $col
tui_hline "┌" "─" "┐"
# Build display list: (type, index) - "g"=group header, "i"=item
# We pre-compute which display-line the cursor item is on
local DLIST_TYPE=() # "g" or "i"
local DLIST_IDX=() # module index for "i", -1 for "g"
local DLIST_LABEL=() # group name for "g", display name for "i"
local cursor_dline=-1
local prev_grp=""
local i dline=0
for ((i=0; i<TOTAL; i++)); do
local grp="${TOGGLE_GROUP[$i]}"
if [[ "$grp" != "$prev_grp" ]]; then
case "$grp" in
root) DLIST_LABEL+=("Root") ;;
admin) DLIST_LABEL+=("Admin") ;;
feature) DLIST_LABEL+=("Features") ;;
esac
DLIST_TYPE+=("g")
DLIST_IDX+=(-1)
dline=$((dline + 1))
prev_grp="$grp"
fi
DLIST_TYPE+=("i")
DLIST_IDX+=($i)
DLIST_LABEL+=("${TOGGLE_DISPLAY[$i]}")
if [[ $CURSOR -eq $i ]]; then
cursor_dline=$dline
fi
dline=$((dline + 1))
done
local DLIST_TOTAL=${#DLIST_TYPE[@]}
# Calculate viewport (fixed overhead: header=4, box_top=1, footer=5, bottom=1 = 11)
local fixed_overhead=11
local viewport=$((TERM_ROWS - fixed_overhead))
[[ $viewport -lt 5 ]] && viewport=5
[[ $viewport -gt $DLIST_TOTAL ]] && viewport=$DLIST_TOTAL
# Adjust scroll offset so cursor is visible
if [[ $cursor_dline -lt $SCROLL_OFF ]]; then
SCROLL_OFF=$cursor_dline
fi
if [[ $cursor_dline -ge $((SCROLL_OFF + viewport)) ]]; then
SCROLL_OFF=$((cursor_dline - viewport + 1))
fi
[[ $SCROLL_OFF -lt 0 ]] && SCROLL_OFF=0
local max_off=$((DLIST_TOTAL - viewport))
[[ $max_off -lt 0 ]] && max_off=0
[[ $SCROLL_OFF -gt $max_off ]] && SCROLL_OFF=$max_off
# Scroll indicator top
if [[ $SCROLL_OFF -gt 0 ]]; then
row=$((row + 1)); tput cup $row $col
tui_row " ▲ more" "${FG_DIM}"
viewport=$((viewport - 1))
fi
# Render visible items
local d rendered=0
for ((d=SCROLL_OFF; d<DLIST_TOTAL && rendered<viewport; d++)); do
row=$((row + 1)); tput cup $row $col
if [[ "${DLIST_TYPE[$d]}" == "g" ]]; then
# Group header
tui_row " ${DLIST_LABEL[$d]}" "${FG_BLUE}${BOLD}"
rendered=$((rendered + 1))
continue
fi
# Module item (custom rendering for checkboxes, locked state, colors)
local mi="${DLIST_IDX[$d]}"
local dname="${DLIST_LABEL[$d]}"
local is_sel=0
[[ $CURSOR -eq $mi ]] && is_sel=1
local is_on="${TOGGLE_STATE[$mi]}"
local locked=0
if is_locked "${TOGGLE_NAMES[$mi]}"; then locked=1; fi
if [[ $locked -eq 1 ]]; then
local icon="■" item_color="${FG_DIM}" icon_color="${FG_DIM}"
elif [[ $is_on -eq 1 ]]; then
local icon="☑" item_color="${FG_CYAN}" icon_color="${FG_GREEN}"
else
local icon="☐" item_color="${FG_DIM}" icon_color="${FG_DIM}"
fi
if [[ $is_sel -eq 1 ]]; then
local text=" ▸ ${icon} ${dname}"
if [[ $locked -eq 1 ]]; then
text=" ▸ ${icon} ${dname} (locked)"
fi
local pad2=$((TUI_W - ${#text}))
[[ $pad2 -lt 0 ]] && pad2=0
printf "${BG_SELECT}${FG_DBLUE}│${RESET}"
if [[ $locked -eq 1 ]]; then
printf "${BG_SELECT} ▸ ${FG_DIM}${icon} %s (locked)" "$dname"
else
printf "${BG_SELECT} ▸ ${icon_color}${icon} ${FG_WHITE}${BOLD}%s" "$dname"
fi
printf "%${pad2}s" ""
printf "${RESET}${BG_SELECT}${FG_DBLUE}│${RESET}"
else
local text=" ${icon} ${dname}"
local pad2=$((TUI_W - ${#text}))
[[ $pad2 -lt 0 ]] && pad2=0
printf "${FG_DBLUE}│${RESET}"
printf " ${icon_color}${icon}${RESET} ${item_color}%s" "$dname"
printf "%${pad2}s" ""
printf "${RESET}${FG_DBLUE}│${RESET}"
fi
rendered=$((rendered + 1))
done
# Scroll indicator bottom
local shown_total=$((SCROLL_OFF + viewport))
[[ $SCROLL_OFF -gt 0 ]] && shown_total=$((shown_total + 1))
if [[ $shown_total -lt $DLIST_TOTAL ]]; then
row=$((row + 1)); tput cup $row $col
tui_row " ▼ more" "${FG_DIM}"
fi
# ── Footer ──
row=$((row + 1)); tput cup $row $col
tui_hline "├" "─" "┤"
row=$((row + 1)); tput cup $row $col
tui_row " ↑↓ Navigate SPC Toggle A/N All" "${FG_DIM}"
row=$((row + 1)); tput cup $row $col
tui_hline "├" "─" "┤"
row=$((row + 1)); tput cup $row $col
tui_row " Q Beenden B Speichern+Bauen H Hilfe" "${FG_DIM}"
row=$((row + 1)); tput cup $row $col
tui_hline "└" "─" "┘"
}
show_help() {
local TERM_ROWS TERM_COLS
TERM_ROWS=$(tput lines)
TERM_COLS=$(tput cols)
local col=$(( (TERM_COLS - TUI_W - 2) / 2 ))
[[ $col -lt 0 ]] && col=0
local row=$(( (TERM_ROWS - 20) / 2 ))
[[ $row -lt 0 ]] && row=0
tput clear
tput cup $row $col; tui_hline "┌" "─" "┐"
row=$((row+1)); tput cup $row $col; tui_row "" ""
row=$((row+1)); tput cup $row $col; tui_row " PLAINTEXT MODULE MANAGER - HELP" "${FG_WHITE}${BOLD}"
row=$((row+1)); tput cup $row $col; tui_row "" ""
row=$((row+1)); tput cup $row $col; tui_hline "├" "─" "┤"
row=$((row+1)); tput cup $row $col; tui_row " Tastatur:" "${FG_CYAN}${BOLD}"
row=$((row+1)); tput cup $row $col; tui_row " ↑ ↓ Navigieren" "${FG_CYAN}"
row=$((row+1)); tput cup $row $col; tui_row " SPACE Modul ein/ausschalten" "${FG_CYAN}"
row=$((row+1)); tput cup $row $col; tui_row " A / N Alle ein / alle aus" "${FG_CYAN}"
row=$((row+1)); tput cup $row $col; tui_row " Q / ESC Beenden (Speichern/Abbrechen)" "${FG_CYAN}"
row=$((row+1)); tput cup $row $col; tui_row " B Speichern + Bauen" "${FG_CYAN}"
row=$((row+1)); tput cup $row $col; tui_row "" ""
row=$((row+1)); tput cup $row $col; tui_row " CLI:" "${FG_CYAN}${BOLD}"
row=$((row+1)); tput cup $row $col; tui_row " ./modules status Aktuellen Status" "${FG_CYAN}"
row=$((row+1)); tput cup $row $col; tui_row " ./modules restore Alle aktivieren" "${FG_CYAN}"
row=$((row+1)); tput cup $row $col; tui_row " ./modules apply State anwenden" "${FG_CYAN}"
row=$((row+1)); tput cup $row $col; tui_row "" ""
row=$((row+1)); tput cup $row $col; tui_hline "├" "─" "┤"
row=$((row+1)); tput cup $row $col; tui_row " Beliebige Taste zum Schliessen..." "${FG_DIM}"
row=$((row+1)); tput cup $row $col; tui_hline "└" "─" "┘"
IFS= read -rsn1
}
# ── Quit Dialog ───────────────────────────────────────────────
show_quit_dialog() {
local TERM_ROWS TERM_COLS
TERM_ROWS=$(tput lines)
TERM_COLS=$(tput cols)
local dlg_w=34
local dlg_h=7
local dlg_row=$(( (TERM_ROWS - dlg_h) / 2 ))
local dlg_col=$(( (TERM_COLS - dlg_w - 2) / 2 ))
[[ $dlg_row -lt 0 ]] && dlg_row=0
[[ $dlg_col -lt 0 ]] && dlg_col=0
# Draw dialog box
tput cup $dlg_row $dlg_col
printf "${FG_DBLUE}┌"; for ((j=0; j<dlg_w; j++)); do printf "─"; done; printf "┐${RESET}"
local r=$((dlg_row + 1)); tput cup $r $dlg_col
printf "${FG_DBLUE}│${RESET}${FG_WHITE}${BOLD} Aenderungen speichern? ${RESET}${FG_DBLUE}│${RESET}"
r=$((r + 1)); tput cup $r $dlg_col
printf "${FG_DBLUE}├"; for ((j=0; j<dlg_w; j++)); do printf "─"; done; printf "┤${RESET}"
r=$((r + 1)); tput cup $r $dlg_col
printf "${FG_DBLUE}│${RESET}${FG_CYAN} ${RESET}${FG_DBLUE}│${RESET}"
r=$((r + 1)); tput cup $r $dlg_col
printf "${FG_DBLUE}│${RESET}${FG_CYAN} S ${FG_WHITE}Speichern ${FG_CYAN}A ${FG_WHITE}Abbrechen ${RESET}${FG_DBLUE}│${RESET}"
r=$((r + 1)); tput cup $r $dlg_col
printf "${FG_DBLUE}│${RESET}${FG_CYAN} ${RESET}${FG_DBLUE}│${RESET}"
r=$((r + 1)); tput cup $r $dlg_col
printf "${FG_DBLUE}└"; for ((j=0; j<dlg_w; j++)); do printf "─"; done; printf "┘${RESET}"
# Wait for choice
while true; do
IFS= read -rsn1 dlg_key
case "$dlg_key" in
's'|'S')
cleanup
save_and_apply
exit 0
;;
'a'|'A'|'q'|'Q'|$'\x1b')
cleanup
echo -e "${FG_YELLOW}Beendet - keine Aenderungen${RESET}"
exit 0
;;
esac
done
}
# ── Main loop ────────────────────────────────────────────────
MAX_IDX=$((TOTAL - 1))
draw
while true; do
IFS= read -rsn1 key
case "$key" in
$'\x1b')
read -rsn2 -t 1 seq || seq=""
case "$seq" in
'[A') # Up
[[ $CURSOR -gt 0 ]] && CURSOR=$((CURSOR - 1))
;;
'[B') # Down
[[ $CURSOR -lt $MAX_IDX ]] && CURSOR=$((CURSOR + 1))
;;
esac
if [[ -z "$seq" ]]; then
show_quit_dialog
fi
;;
' ')
do_toggle $CURSOR
;;
'a'|'A')
for ((i=0; i<TOTAL; i++)); do TOGGLE_STATE[$i]=1; done
;;
'n'|'N')
for ((i=0; i<TOTAL; i++)); do
if ! is_locked "${TOGGLE_NAMES[$i]}"; then
TOGGLE_STATE[$i]=0
fi
done
;;
'q'|'Q') # Quit - ask save or cancel
show_quit_dialog
;;
'b'|'B') # Save + Build & Run
cleanup
save_and_apply
echo ""
echo -e "${FG_BLUE}${BOLD}Building & starting application...${RESET}"
exec "$SCRIPT_DIR/build" run
;;
'h'|'H'|'?')
show_help
;;
esac
draw
done