-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.ts
More file actions
937 lines (855 loc) · 36.5 KB
/
Copy pathexample.ts
File metadata and controls
937 lines (855 loc) · 36.5 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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
import { MepCLI } from './src'; // Or 'mepcli' if installed via NPM
/**
* Runs a comprehensive demo showcasing all MepCLI prompt types and utilities.
* This demonstrates all core functionalities including Text, Password, Select,
* Checkbox, Number, Toggle, Confirm, List, Slider, Date, File, MultiSelect,
* Autocomplete, Sort, Table, and the Spin utility.
*/
async function runComprehensiveDemo() {
console.clear();
console.log("--- MepCLI Comprehensive Demo (All Prompts + Spin Utility) ---\n");
try {
// --- 1. Text Prompt (Input with Validation and initial value) ---
const projectName = await MepCLI.text({
message: "Enter the name for your new project:",
placeholder: "e.g., minimalist-cli-app",
initial: "MepProject",
validate: (value) => {
if (value.length < 3) return "Project name must be at least 3 characters long.";
return true;
}
});
console.log(`\n Text Result: Project name set to '${projectName}'`);
// --- 1.5 Text Prompt with Suggestion (Ghost Text) ---
const gitCommand = await MepCLI.text({
message: "Enter a git command (try typing 'git c' and press Tab):",
placeholder: "git ...",
suggest: (input) => {
if (!input) return "";
const suggestions = ["git commit", "git checkout", "git clone", "git push", "git pull", "git status"];
const match = suggestions.find(s => s.startsWith(input));
return match || "";
}
});
console.log(`\n Text Suggestion Result: '${gitCommand}'`);
// --- 2. Password Prompt (Hidden input) ---
const apiKey = await MepCLI.password({
message: "Enter the project's external API key:",
placeholder: "Input will be hidden..."
});
console.log(`\n Password Result: API key entered (length: ${apiKey.length})`);
// --- 2.5. Secret Prompt (Completely hidden input) ---
const secretToken = await MepCLI.secret({
message: "Enter secret token (no feedback):",
validate: (v) => v.length > 0 || "Token required"
});
console.log(`\n Secret Result: Token entered (length: ${secretToken.length})`);
// --- 3. Select Prompt (Single choice, supports filtering/searching by typing) ---
const theme = await MepCLI.select({
message: "Choose your preferred editor color theme:",
choices: [
{ title: "Dark Mode (Default)", value: "dark" },
{ title: "Light Mode (Classic)", value: "light" },
{ title: "High Contrast (Accessibility)", value: "contrast" },
// Demonstrates a separator option
{ separator: true, text: "--- Pro Themes ---" },
{ title: "Monokai Pro", value: "monokai" },
]
});
console.log(`\n Select Result: Chosen theme is: ${theme}`);
// --- 4. Checkbox Prompt (Multi-choice with Min/Max limits) ---
const buildTools = await MepCLI.checkbox({
message: "Select your required bundlers/build tools (Min 1, Max 2):",
min: 1,
max: 2,
choices: [
{ title: "Webpack", value: "webpack" },
{ title: "Vite", value: "vite", selected: true }, // Default selected state
{ title: "Rollup", value: "rollup" },
{ title: "esbuild", value: "esbuild" }
]
});
console.log(`\n Checkbox Result: Selected build tools: [${buildTools.join(', ')}]`);
// --- 5. Number Prompt (Numeric input, supports Min/Max and Up/Down arrow for Step) ---
const port = await MepCLI.number({
message: "Which port should the server run on?",
initial: 3000,
min: 1024,
max: 65535,
step: 100 // Increments/decrements by 100 with arrows
});
console.log(`\n Number Result: Server port: ${port}`);
// --- 6. Toggle Prompt (Boolean input, supports custom labels) ---
const isSecure = await MepCLI.toggle({
message: "Enable HTTPS/SSL for production?",
initial: false,
activeText: "SECURE", // Custom 'on' label
inactiveText: "INSECURE" // Custom 'off' label
});
console.log(`\n Toggle Result: HTTPS enabled: ${isSecure}`);
// --- 7. List / Tags Input ---
const keywords = await MepCLI.list({
message: "Enter keywords for package.json (Enter to add, Backspace to remove):",
initial: ["cli", "mep"],
validate: (tags) => tags.length > 0 || "Please add at least one keyword."
});
console.log(`\n List Result: Keywords: [${keywords.join(', ')}]`);
// --- 8. Slider / Scale ---
const brightness = await MepCLI.slider({
message: "Set initial brightness:",
min: 0,
max: 100,
initial: 80,
step: 5,
unit: "%"
});
console.log(`\n Slider Result: Brightness: ${brightness}%`);
// --- 8.1. Range Prompt (Dual Slider) ---
const priceRange = await MepCLI.range({
message: "Filter by price range:",
min: 0,
max: 1000,
initial: [200, 800],
step: 50,
unit: "$"
});
console.log(`\n Range Result: $${priceRange[0]} - $${priceRange[1]}`);
// --- 9. Rating Prompt ---
const userRating = await MepCLI.rating({
message: "How would you rate this CLI tool?",
min: 1,
max: 5,
initial: 5
});
console.log(`\n Rating Result: You rated it: ${userRating}/5`);
// --- 10. Date / Time Picker ---
// We capture 'now' once to ensure initial >= min
const now = new Date();
const releaseDate = await MepCLI.date({
message: "Schedule release date:",
initial: now,
min: now // Cannot be in the past
});
console.log(`\n Date Result: Release set for: ${releaseDate.toLocaleString()}`);
// --- 11. File Path Selector ---
const configPath = await MepCLI.file({
message: "Select configuration file (Tab to autocomplete):",
basePath: process.cwd()
});
console.log(`\n File Result: Path: ${configPath}`);
// --- 12. Multi-Select Autocomplete ---
const linters = await MepCLI.multiSelect({
message: "Select linters to install (Type to search, Space to select):",
choices: [
{ title: "ESLint", value: "eslint", selected: true },
{ title: "Prettier", value: "prettier" },
{ title: "Stylelint", value: "stylelint" },
{ title: "TSLint (Deprecated)", value: "tslint" },
{ title: "JSHint", value: "jshint" },
{ title: "StandardJS", value: "standard" }
],
min: 1
});
console.log(`\n MultiSelect Result: Linters: [${linters.join(', ')}]`);
// --- 13. Autocomplete Prompt ---
const city = await MepCLI.autocomplete({
message: "Search for a city (simulated async):",
suggest: async (query) => {
const cities = [
{ title: "New York", value: "NY" },
{ title: "London", value: "LDN" },
{ title: "Paris", value: "PAR" },
{ title: "Tokyo", value: "TKY" },
{ title: "Berlin", value: "BER" },
{ title: "San Francisco", value: "SF" },
{ title: "Toronto", value: "TOR" }
];
// Simulate delay
await new Promise(r => setTimeout(r, 400));
return cities.filter(c => c.title.toLowerCase().includes(query.toLowerCase()));
}
});
console.log(`\n Autocomplete Result: City code: ${city}`);
// --- 14. Sort Prompt ---
const priorities = await MepCLI.sort({
message: "Rank your top priorities (Space to grab/drop, Arrows to move):",
items: ["Performance", "Security", "Features", "Usability", "Cost"]
});
console.log(`\n Sort Result: Priorities: [${priorities.join(', ')}]`);
// --- 14.1 Transfer Prompt (PickList) ---
const teamA = await MepCLI.transfer({
message: "Assign members to Team A (Space to move):",
source: ["Alice", "Bob", "Charlie", "David", "Eve"],
target: ["Frank"] // Pre-assigned
});
console.log(`\n Transfer Result: Team A: [${teamA[1].join(', ')}] (Remaining: [${teamA[0].join(', ')}])`);
// --- 15. Table Prompt ---
const userId = await MepCLI.table({
message: "Select a user from the database:",
columns: ["ID", "Name", "Role", "Status"],
data: [
{ value: 1, row: ["001", "Alice", "Admin", "Active"] },
{ value: 2, row: ["002", "Bob", "Dev", "Offline"] },
{ value: 3, row: ["003", "Charlie", "User", "Active"] },
{ value: 4, row: ["004", "David", "Manager", "Active"] },
]
});
console.log(`\n Table Result: Selected User ID: ${userId}`);
// --- 16. Confirm Prompt (Simple Yes/No) ---
const proceed = await MepCLI.confirm({
message: "Ready to deploy the project now?",
initial: true
});
console.log(`\n Confirm Result: Deployment decision: ${proceed ? 'Proceed' : 'Cancel'}`);
// --- 17. Editor Prompt ---
const bio = await MepCLI.editor({
message: "Write your biography (opens default editor):",
initial: "Hi, I am a developer...",
extension: ".md",
waitUserInput: true
});
console.log(`\n Editor Result: Biography length: ${bio.length} chars`);
// --- 18. Keypress Prompt ---
console.log("\n--- Press any key to continue to the Tree Prompt Demo... ---");
const key = await MepCLI.keypress({
message: "Press any key to proceed (or 'q' to quit):",
keys: ['q', 'enter', 'space', 'escape'] // Optional whitelist, or leave undefined for any
});
console.log(`\n Keypress Result: You pressed '${key}'`);
if (key === 'q') return;
// --- 19. Tree Prompt ---
const selectedFile = await MepCLI.tree({
message: "Select a file from the project structure (Space to toggle, Enter to select):",
data: [
{
title: "src",
value: "src",
children: [
{ title: "index.ts", value: "src/index.ts" },
{ title: "utils.ts", value: "src/utils.ts" },
{
title: "prompts",
value: "src/prompts",
expanded: true,
children: [
{ title: "text.ts", value: "src/prompts/text.ts" },
{ title: "select.ts", value: "src/prompts/select.ts" }
]
}
]
},
{
title: "package.json",
value: "package.json"
},
{
title: "README.md",
value: "README.md"
}
]
});
console.log(`\n Tree Result: Selected path: ${selectedFile}`);
// --- 20. Form Prompt ---
const userDetails = await MepCLI.form({
message: "Enter User Details (Up/Down/Tab to navigate):",
fields: [
{ name: "firstname", message: "First Name", initial: "John" },
{ name: "lastname", message: "Last Name", validate: (v) => v.length > 0 ? true : "Required" },
{ name: "email", message: "Email", validate: (v) => v.includes("@") || "Invalid email" },
{ name: "role", message: "Job Role", initial: "Developer" }
]
});
console.log(`\n Form Result: User: ${JSON.stringify(userDetails)}`);
// --- 21. Snippet Prompt ---
const commitMsg = await MepCLI.snippet({
message: "Compose Commit Message (Tab/Shift+Tab to navigate variables):",
template: "feat(${scope}): ${message} (Refs: #${issue})",
values: {
scope: "cli",
issue: "123"
}
});
console.log(`\n Snippet Result: "${commitMsg}"`);
// --- 22. Spam Prompt ---
const spamConfirmed = await MepCLI.spam({
message: "Hold on! Confirm deployment by mashing the Space key!",
threshold: 10,
decay: false, // We're not devil
spamKey: ' ' // Space key
});
console.log(`\n Spam Result: Deployment confirmed: ${spamConfirmed}`);
// --- 23. Wait Prompt ---
await MepCLI.wait({
message: "Please wait while we finalize the setup...",
seconds: 3, // Just 3 seconds for demo
autoSubmit: true // Automatically proceeds after time is up
});
console.log("\n Wait Result: Wait complete.");
// --- 24. Code Prompt ---
const config = await MepCLI.code({
message: "Configure Server (JSON) - Tab to nav:",
language: "json",
highlight: true, // Experimental syntax highlighting
template: `
{
"host": "\${host}",
"port": \${port},
"debug": \${debug}
}
`
});
console.log(`\n Code Result: Config: ${config.replace(/\n/g, ' ')}`);
// --- 25. Tree Select Prompt ---
const selectedTreeItems = await MepCLI.treeSelect({
message: "Select files to backup (Multi-select Tree):",
data: [
{
title: "src",
value: "src",
children: [
{ title: "index.ts", value: "src/index.ts" },
{ title: "utils.ts", value: "src/utils.ts" }
]
},
{
title: "tests",
value: "tests",
expanded: true,
children: [
{ title: "e2e", value: "tests/e2e", selected: true },
{ title: "unit", value: "tests/unit" }
]
}
]
});
console.log(`\n TreeSelect Result: Selected: [${selectedTreeItems.join(', ')}]`);
// --- 26. Cron Prompt ---
const schedule = await MepCLI.cron({
message: "Set backup schedule (Cron):",
initial: "0 4 * * *" // Daily at 4:00 AM
});
console.log(`\n Cron Result: "${schedule}"`);
// --- 27. Color Prompt ---
const themeColor = await MepCLI.color({
message: "Pick your brand color (RGB):",
initial: "#6366f1"
});
console.log(`\n Color Result: "${themeColor}"`);
// --- 28. Grid Prompt ---
const permissions = await MepCLI.grid({
message: "Configure Access Permissions:",
rows: ["Admin", "User", "Guest"],
columns: ["Read", "Write", "Execute"]
});
console.log(`\n Grid Result: (Boolean Matrix)`, permissions);
// --- 29. Calendar Prompt ---
const bookingRange = await MepCLI.calendar({
message: "Select booking period:",
mode: "range"
});
console.log(`\n Calendar Result:`, bookingRange);
// --- 30. Map Prompt ---
const envVars = await MepCLI.map({
message: "Configure Environment Variables (Map):",
initial: { "API_URL": "http://localhost:8080", "DB_HOST": "127.0.0.1" }
});
console.log(`\n Map Result:`, envVars);
// --- 31. IP Prompt ---
const ipAddress = await MepCLI.ip({
message: "Enter Server IP Address:",
initial: "192.168.0.1"
});
console.log(`\n IP Result: ${ipAddress}`);
// --- 32. SemVer Prompt ---
const nextVersion = await MepCLI.semver({
message: "Bump Package Version:",
currentVersion: "1.0.5"
});
console.log(`\n SemVer Result: ${nextVersion}`);
// --- 33. OTP Prompt ---
const otpCode = await MepCLI.otp({
message: "Enter Verification Code (OTP):",
length: 6,
mask: "•",
secure: false // Set true to hide input like password
});
console.log(`\n OTP Result: ${otpCode}`);
// --- 34. Quiz Select Prompt ---
const quizResult1 = await MepCLI.quizSelect({
message: "Quiz: Which language runs in the browser?",
choices: [
{ title: "C++", value: "cpp" },
{ title: "JavaScript", value: "js" },
{ title: "Python", value: "py" }
],
correctValue: "js",
explanation: "JavaScript is the primary scripting language for the web."
});
console.log(`\n Quiz Select Result: ${quizResult1}`);
// --- 35. Quiz Text Prompt ---
const quizResult2 = await MepCLI.quizText({
message: "Quiz: What is the largest planet in our solar system?",
correctAnswer: "Jupiter",
explanation: "Jupiter is a gas giant and the largest planet.",
// Optional custom verify function (e.g., allow case insensitive)
verify: (val) => val.trim().toLowerCase() === "jupiter"
});
console.log(`\n Quiz Text Result: ${quizResult2}`);
// --- 36. Kanban Prompt ---
const kanbanBoard = await MepCLI.kanban({
message: "Manage Project Tasks (Kanban):",
columns: [
{
id: "todo",
title: "To Do",
items: [
{ id: "t1", title: "Setup Repo" },
{ id: "t2", title: "Design DB" }
]
},
{
id: "in-progress",
title: "In Progress",
items: [
{ id: "t3", title: "Auth Module" }
]
},
{
id: "done",
title: "Done",
items: []
}
]
});
console.log(`\n Kanban Result:`, kanbanBoard);
// --- 37. Time Prompt ---
const meetingTime = await MepCLI.time({
message: "Schedule Daily Standup:",
format: "12h",
step: 15,
initial: new Date()
});
console.log(`\n Time Result: ${meetingTime}`);
// --- 38. Heatmap Prompt ---
const weeklyAvailability = await MepCLI.heatmap({
message: "Set Availability (0=Busy, 1=Free, 2=Preferred):",
rows: ["Mon", "Tue", "Wed", "Thu", "Fri"],
columns: ["9AM", "1PM", "5PM"],
legend: [
{ value: 0, char: "x", color: (s) => `\x1b[31m${s}\x1b[0m` }, // Red
{ value: 1, char: "o", color: (s) => `\x1b[33m${s}\x1b[0m` }, // Yellow
{ value: 2, char: "✓", color: (s) => `\x1b[32m${s}\x1b[0m` } // Green
]
});
console.log(`\n Heatmap Result:`, weeklyAvailability);
// --- 39. Byte Prompt ---
const size = await MepCLI.byte({
message: "Set docker container memory limit",
initial: 512 * 1024 * 1024, // 512 MB
min: 1024 * 1024 // Min 1 MB
});
console.log(`Configured: ${size} bytes`);
// --- 40. Slot Machine Prompt ---
const slotPrize = await MepCLI.slot({
message: "Spin for your daily bonus:",
choices: ["💎 Diamond", "🥇 Gold", "🥈 Silver", "🥉 Bronze", "🪵 Wood"],
rows: 5
});
console.log(`\n Slot Result: ${slotPrize}`);
// --- 41. Rhythm Gauge Prompt ---
const gaugeScore = await MepCLI.gauge({
message: "Stop the needle in the GREEN zone!",
width: 40,
safeZone: 0.15 // 15% safe zone
});
console.log(`\n Gauge Result: ${gaugeScore}`);
// --- 42. Calculator Prompt ---
const calcTotal = await MepCLI.calculator({
message: "Calculate invoice total (price * qty):",
initial: "price * qty",
variables: { price: 29.99, qty: 5 },
precision: 2
});
console.log(`\n Calculator Result: ${calcTotal}`);
// --- 43. Emoji Prompt ---
const pickedEmoji = await MepCLI.emoji({
message: "Pick an emoji for your avatar:",
emojis: [
{ char: '😀', name: 'Grinning' },
{ char: '🚀', name: 'Rocket' },
{ char: '💻', name: 'Tech' },
{ char: '🎉', name: 'Party' },
{ char: '🔥', name: 'Fire' }
],
recent: ['Rocket']
});
console.log(`\n Emoji Result: ${pickedEmoji}`);
// --- 44. Match Prompt ---
const linkedItems = await MepCLI.match({
message: "Match capitals to countries:",
source: ['Paris', 'Berlin', 'Tokyo'],
target: ['Germany', 'Japan', 'France'],
constraints: { required: true }
});
console.log(`\n Match Result:`, linkedItems);
// --- 45. Diff Prompt ---
const diffResult = await MepCLI.diff({
message: "Resolve Conflict:",
original: "const x = 10;",
modified: "const x = 20; // Updated value"
});
console.log(`\n Diff Result: ${diffResult}`);
// --- 46. Dial Prompt ---
const dialVal = await MepCLI.dial({
message: "Set Volume:",
min: 0,
max: 100,
initial: 50,
radius: 5
});
console.log(`\n Dial Result: ${dialVal}`);
// --- 47. Draw Prompt ---
const drawing = await MepCLI.draw({
message: "Draw a smiley face:",
width: 20,
height: 10,
exportType: 'text'
});
console.log(`\n Drawing:\n${drawing}`);
// --- 49. Multi-Column Select Prompt ---
const mcSelection = await MepCLI.multiColumnSelect({
message: "Pick a technology (Multi-Column):",
choices: [
{ title: "React", value: "react" },
{ title: "Vue", value: "vue" },
{ title: "Angular", value: "angular" },
{ title: "Svelte", value: "svelte" },
{ title: "Node.js", value: "node" },
{ title: "Python", value: "python" },
{ title: "Ruby", value: "ruby" },
{ title: "Go", value: "go" },
{ title: "Rust", value: "rust" },
{ title: "Java", value: "java" },
{ title: "C#", value: "csharp" },
{ title: "PHP", value: "php" }
],
cols: 4 // or 'auto'
});
console.log(`\n Multi-Column Result: ${mcSelection}`);
// --- 50. Fuzzy Select Prompt ---
const fuzzyResult = await MepCLI.fuzzySelect({
message: "Search a package (Fuzzy):",
choices: [
{ title: "react", value: "react" },
{ title: "react-dom", value: "react-dom" },
{ title: "react-router", value: "react-router" },
{ title: "redux", value: "redux" },
{ title: "vue", value: "vue" },
{ title: "vite", value: "vite" },
{ title: "webpack", value: "webpack" },
{ title: "lodash", value: "lodash" },
{ title: "moment", value: "moment" },
{ title: "express", value: "express" },
{ title: "git status", value: "git-status" },
{ title: "git commit", value: "git-commit" }
]
});
console.log(`\n Fuzzy Result: ${fuzzyResult}`);
// --- 51. Miller Columns Prompt ---
const millerPath = await MepCLI.miller({
message: "Navigate Hierarchy (Miller Columns):",
data: [
{
title: "USA",
value: "usa",
children: [
{
title: "California",
value: "ca",
children: [
{ title: "San Francisco", value: "sf" },
{ title: "Los Angeles", value: "la" }
]
},
{
title: "New York",
value: "ny",
children: [
{ title: "NYC", value: "nyc" },
{ title: "Albany", value: "albany" }
]
}
]
},
{
title: "Canada",
value: "canada",
children: [
{
title: "Ontario",
value: "on",
children: [
{ title: "Toronto", value: "toronto" },
{ title: "Ottawa", value: "ottawa" }
]
},
{
title: "Quebec",
value: "qc",
children: [
{ title: "Montreal", value: "montreal" }
]
}
]
}
]
});
console.log(`\n Miller Result: ${millerPath.join(' -> ')}`);
// --- 52. Pattern Lock Prompt ---
const pattern = await MepCLI.pattern({
message: "Draw a pattern (at least 2 nodes):",
rows: 3,
cols: 3
});
console.log(`\n Pattern Result: ${pattern}`);
// --- 53. Region Selector Prompt ---
const mapArt =
` ___
__/ \\__
/ \\
| |
\\ /
\\__ __/
| |
___| |___
/ \\
| |
\\_________/`;
const region = await MepCLI.region({
message: "Select a region on the map:",
mapArt: mapArt,
regions: [
{ id: 'North', label: 'North Base', x: 8, y: 3, description: 'The northern stronghold' },
{ id: 'South', label: 'South Outpost', x: 8, y: 9, description: 'The southern trading post' }
]
});
console.log(`\n Region Result: ${region}`);
// --- 54. Spreadsheet Prompt ---
const sheetData = await MepCLI.spreadsheet({
message: "Edit User Data (Spreadsheet):",
columns: [
{ name: 'ID', key: 'id', width: 5, editable: false },
{ name: 'Name', key: 'name', width: 15 },
{ name: 'Role', key: 'role', width: 15 },
{ name: 'Active', key: 'active', width: 8 }
],
data: [
{ id: 1, name: 'Alice', role: 'Admin', active: 'Yes' },
{ id: 2, name: 'Bob', role: 'User', active: 'Yes' },
{ id: 3, name: 'Charlie', role: 'Guest', active: 'No' },
{ id: 4, name: 'Dave', role: 'User', active: 'Yes' },
],
rows: 5
});
console.log(`\n Spreadsheet Result:`, sheetData);
// --- 55. Scroll Prompt (License Agreement) ---
const dummyLicense = Array(40).fill("").map((_, i) =>
`Clause ${i + 1}: This is a sample clause text that is quite long to ensure it wraps correctly or at least takes up some space.`
).join('\n');
await MepCLI.scroll({
message: "Read and Accept the License Agreement (Scroll to bottom):",
content: dummyLicense,
height: 10,
requireScrollToBottom: true
});
console.log(`\n Scroll Result: License Accepted`);
// --- 56. Breadcrumb Prompt ---
const breadcrumbPath = await MepCLI.breadcrumb({
message: "Select a folder (Breadcrumb):",
root: process.cwd(),
showHidden: false
});
console.log(`\n Breadcrumb Result: ${breadcrumbPath}`);
// --- 57. Schedule Prompt ---
const timeline = await MepCLI.schedule({
message: "Project Timeline (Shift+Arrows to resize):",
data: [
{ name: "Planning", start: new Date(), end: new Date(Date.now() + 86400000 * 2) },
{ name: "Development", start: new Date(Date.now() + 86400000 * 3), end: new Date(Date.now() + 86400000 * 7) }
]
});
console.log(`\n Schedule Result:`, timeline);
// --- 58. Data Inspector Prompt ---
const finalConfig = await MepCLI.inspector({
message: "Verify Final Configuration (Data Inspector):",
data: {
env: "production",
debug: false,
database: {
host: "10.0.0.5",
port: 5432,
pool: { max: 20, min: 5 }
},
services: ["api", "worker", "auth"]
}
});
console.log(`\n Inspector Result:`, JSON.stringify(finalConfig, null, 2));
// --- 59. Exec Prompt (Background Command) ---
console.log("\n--- Exec Prompt Demo (Simulating Background Task) ---");
try {
await MepCLI.exec({
message: "Simulating a build process...",
command: "node -e \"setTimeout(() => {}, 2000)\"", // 2s delay
timeout: 5000
});
console.log(" -> Build Success!");
} catch (e) {
console.log(" -> Build Failed!", e);
}
// --- 60. Shortcut Prompt ---
const keyShortcut = await MepCLI.shortcut({
message: "Press any key combination (e.g. Ctrl+Shift+A):"
});
console.log(`\n Shortcut Result: ${keyShortcut.name} (Ctrl:${keyShortcut.ctrl}, Alt:${keyShortcut.meta}, Shift:${keyShortcut.shift})`);
// --- 61. Seat Prompt ---
const seats = await MepCLI.seat({
message: "Select your seats (Use arrows, jump over gaps):",
layout: [
"AA_AA",
"AA_AA",
"_____",
"BB_BB",
"XX_BB" // XX is occupied
],
multiple: true
});
console.log(`\n Seat Result: [${seats.join(', ')}]`);
// --- 62. Select Range Prompt ---
const selectedRange = await MepCLI.selectRange({
message: "Select a range of commits (Space to anchor):",
choices: [
{ title: "feat: initial commit", value: "c1" },
{ title: "feat: add login", value: "c2" },
{ title: "fix: login bug", value: "c3" },
{ title: "docs: readme", value: "c4" },
{ title: "chore: cleanup", value: "c5" },
{ title: "feat: dashboard", value: "c6" }
]
});
console.log(`\n SelectRange Result: [${selectedRange.join(', ')}]`);
// --- 63. Sort Grid Prompt ---
const sortedGrid = await MepCLI.sortGrid({
message: "Rearrange the grid (Space to grab):",
data: [
["A", "B", "C"],
["D", "E", "F"],
["G", "H", "I"]
]
});
console.log(`\n SortGrid Result:`, sortedGrid);
// --- 65. Dependency Prompt ---
const deps = await MepCLI.dependency({
message: "Select Features (with Dependencies):",
choices: [
{ title: "Core System", value: "core", selected: true },
{ title: "Plugin A (Requires Core)", value: "plugin-a", dependsOn: ['core'] },
{ title: "Plugin B (Conflicts A)", value: "plugin-b", conflictsWith: ['plugin-a'] },
{ title: "Dev Tools (Triggers Docs)", value: "devtools", triggers: ['docs'] },
{ title: "Documentation", value: "docs" }
],
autoResolve: true
});
console.log(`\n Dependency Result: [${deps.join(', ')}]`);
// --- 66. License Prompt (Split View) ---
const license = await MepCLI.license({
message: "Choose an Open Source License:",
defaultLicense: 'MIT'
});
console.log(`\n License Result: ${license}`);
// --- 67. Regex Prompt ---
const regex = await MepCLI.regex({
message: "Enter a regex to match email-like patterns:",
tests: [
'test@example.com',
'invalid-email',
'user.name@sub.domain.co.uk',
'@missinguser.com',
'123456'
]
});
console.log(`\n Regex Result: ${regex}`);
// --- 68. Box Prompt ---
const box = await MepCLI.box({
message: "Set Box Model (Margin):",
initial: 10,
step: 5,
min: 0,
max: 100
});
console.log(`\n Box Result:`, box);
// --- 69. Connection String Wizard ---
const connString = await MepCLI.connectionString({
message: "Configure Database Connection (Wizard):",
protocols: ['postgres', 'mysql', 'sqlite'] // Custom list
});
console.log(`\n Connection String Result:`, connString.raw);
// --- 70. Curl Prompt ---
const curlReq = await MepCLI.curl({
message: "Build API Request (CURL):",
defaultMethod: "POST",
defaultUrl: "https://api.myapp.com/v1/users",
defaultBody: '{\n "name": "MepCLI"\n}'
});
console.log(`\n Curl Result:`, curlReq.command);
// --- 71. Phone Prompt ---
const phoneNumber = await MepCLI.phone({
message: "Enter Phone Number:",
defaultCountry: "US",
validate: (p) => p.length > 8 || "Too short"
});
console.log(`\n Phone Result: ${phoneNumber}`);
// --- 72. Fuzzy Multi Column Select Prompt ---
const fuzzyMcResult = await MepCLI.fuzzyMultiColumn({
message: "Pick a pokemon (Fuzzy + Grid):",
choices: [
{ title: 'Bulbasaur', value: 'bulbasaur' },
{ title: 'Ivysaur', value: 'ivysaur' },
{ title: 'Venusaur', value: 'venusaur' },
{ title: 'Charmander', value: 'charmander' },
{ title: 'Charmeleon', value: 'charmeleon' },
{ title: 'Charizard', value: 'charizard' },
{ title: 'Squirtle', value: 'squirtle' },
{ title: 'Wartortle', value: 'wartortle' },
{ title: 'Blastoise', value: 'blastoise' }
],
cols: 3
});
console.log(`\n Fuzzy Multi-Column Result: ${fuzzyMcResult}`);
// --- 73. Multi Range Prompt ---
const multiRangeResult = await MepCLI.multiRange({
message: "Select ranges (Space to anchor/commit, Enter to submit):",
choices: Array.from({ length: 15 }, (_, i) => ({ title: `Item ${i + 1}`, value: i + 1 }))
});
console.log(`\n Multi-Range Result:`, multiRangeResult);
// --- 74. Breadcrumb Search Prompt ---
const bcSearchResult = await MepCLI.breadcrumbSearch({
message: "Navigate & Search Files:",
root: process.cwd(),
showHidden: false
});
console.log(`\n Breadcrumb Search Result: ${bcSearchResult}`);
// --- 75. Spin Utility (Loading/Async Task Indicator) ---
const s = MepCLI.spinner("Finalizing configuration and deploying...").start();
await new Promise(resolve => setTimeout(resolve, 1500)); // Simulates a 1.5 second async task
s.success();
console.log("\n--- Deployment successful! All MepCLI features demonstrated! ---");
} catch (e) {
// Global handler for Ctrl+C closure
if (e instanceof Error && e.message === 'User force closed') {
console.log("\nOperation cancelled by user (Ctrl+C).");
} else {
console.error("\nAn error occurred during prompt execution:", e);
}
}
}
runComprehensiveDemo();