@@ -7,86 +7,94 @@ import color from 'picocolors';
7
7
*/
8
8
9
9
async function main ( ) {
10
- console . clear ( ) ;
10
+ console . clear ( ) ;
11
11
12
- p . intro ( `${ color . bgCyan ( color . black ( ' Integrated Autocomplete Multiselect Example ' ) ) } ` ) ;
12
+ p . intro ( `${ color . bgCyan ( color . black ( ' Integrated Autocomplete Multiselect Example ' ) ) } ` ) ;
13
13
14
- p . note ( `
14
+ p . note (
15
+ `
15
16
${ color . cyan ( 'Filter and select multiple items in a single interface:' ) }
16
17
- ${ color . yellow ( 'Type' ) } to filter the list in real-time
17
18
- Use ${ color . yellow ( 'up/down arrows' ) } to navigate with improved stability
18
19
- Press ${ color . yellow ( 'Space' ) } to select/deselect the highlighted item ${ color . green ( '(multiple selections allowed)' ) }
19
20
- Use ${ color . yellow ( 'Backspace' ) } to modify your filter text when searching for different options
20
21
- Press ${ color . yellow ( 'Enter' ) } when done selecting all items
21
22
- Press ${ color . yellow ( 'Ctrl+C' ) } to cancel
22
- ` , 'Instructions' ) ;
23
+ ` ,
24
+ 'Instructions'
25
+ ) ;
23
26
24
- // Frameworks in alphabetical order
25
- const frameworks = [
26
- { value : 'angular' , label : 'Angular' , hint : 'Frontend/UI' } ,
27
- { value : 'django' , label : 'Django' , hint : 'Python Backend' } ,
28
- { value : 'dotnet' , label : '.NET Core' , hint : 'C# Backend' } ,
29
- { value : 'electron' , label : 'Electron' , hint : 'Desktop' } ,
30
- { value : 'express' , label : 'Express' , hint : 'Node.js Backend' } ,
31
- { value : 'flask' , label : 'Flask' , hint : 'Python Backend' } ,
32
- { value : 'flutter' , label : 'Flutter' , hint : 'Mobile' } ,
33
- { value : 'laravel' , label : 'Laravel' , hint : 'PHP Backend' } ,
34
- { value : 'nestjs' , label : 'NestJS' , hint : 'Node.js Backend' } ,
35
- { value : 'nextjs' , label : 'Next.js' , hint : 'React Framework' } ,
36
- { value : 'nuxt' , label : 'Nuxt.js' , hint : 'Vue Framework' } ,
37
- { value : 'rails' , label : 'Ruby on Rails' , hint : 'Ruby Backend' } ,
38
- { value : 'react' , label : 'React' , hint : 'Frontend/UI' } ,
39
- { value : 'reactnative' , label : 'React Native' , hint : 'Mobile' } ,
40
- { value : 'spring' , label : 'Spring Boot' , hint : 'Java Backend' } ,
41
- { value : 'svelte' , label : 'Svelte' , hint : 'Frontend/UI' } ,
42
- { value : 'tauri' , label : 'Tauri' , hint : 'Desktop' } ,
43
- { value : 'vue' , label : 'Vue.js' , hint : 'Frontend/UI' } ,
44
- ] ;
27
+ // Frameworks in alphabetical order
28
+ const frameworks = [
29
+ { value : 'angular' , label : 'Angular' , hint : 'Frontend/UI' } ,
30
+ { value : 'django' , label : 'Django' , hint : 'Python Backend' } ,
31
+ { value : 'dotnet' , label : '.NET Core' , hint : 'C# Backend' } ,
32
+ { value : 'electron' , label : 'Electron' , hint : 'Desktop' } ,
33
+ { value : 'express' , label : 'Express' , hint : 'Node.js Backend' } ,
34
+ { value : 'flask' , label : 'Flask' , hint : 'Python Backend' } ,
35
+ { value : 'flutter' , label : 'Flutter' , hint : 'Mobile' } ,
36
+ { value : 'laravel' , label : 'Laravel' , hint : 'PHP Backend' } ,
37
+ { value : 'nestjs' , label : 'NestJS' , hint : 'Node.js Backend' } ,
38
+ { value : 'nextjs' , label : 'Next.js' , hint : 'React Framework' } ,
39
+ { value : 'nuxt' , label : 'Nuxt.js' , hint : 'Vue Framework' } ,
40
+ { value : 'rails' , label : 'Ruby on Rails' , hint : 'Ruby Backend' } ,
41
+ { value : 'react' , label : 'React' , hint : 'Frontend/UI' } ,
42
+ { value : 'reactnative' , label : 'React Native' , hint : 'Mobile' } ,
43
+ { value : 'spring' , label : 'Spring Boot' , hint : 'Java Backend' } ,
44
+ { value : 'svelte' , label : 'Svelte' , hint : 'Frontend/UI' } ,
45
+ { value : 'tauri' , label : 'Tauri' , hint : 'Desktop' } ,
46
+ { value : 'vue' , label : 'Vue.js' , hint : 'Frontend/UI' } ,
47
+ ] ;
45
48
46
- // Use the new integrated autocompleteMultiselect component
47
- const result = await p . autocompleteMultiselect < string > ( {
48
- message : 'Select frameworks (type to filter)' ,
49
- options : frameworks ,
50
- placeholder : 'Type to filter...' ,
51
- maxItems : 8
52
- } ) ;
49
+ // Use the new integrated autocompleteMultiselect component
50
+ const result = await p . autocompleteMultiselect < string > ( {
51
+ message : 'Select frameworks (type to filter)' ,
52
+ options : frameworks ,
53
+ placeholder : 'Type to filter...' ,
54
+ maxItems : 8 ,
55
+ } ) ;
53
56
54
- if ( p . isCancel ( result ) ) {
55
- p . cancel ( 'Operation cancelled.' ) ;
56
- process . exit ( 0 ) ;
57
- }
57
+ if ( p . isCancel ( result ) ) {
58
+ p . cancel ( 'Operation cancelled.' ) ;
59
+ process . exit ( 0 ) ;
60
+ }
58
61
59
- // Type guard: if not a cancel symbol, result must be a string array
60
- function isStringArray ( value : unknown ) : value is string [ ] {
61
- return Array . isArray ( value ) && value . every ( item => typeof item === 'string' ) ;
62
- }
62
+ // Type guard: if not a cancel symbol, result must be a string array
63
+ function isStringArray ( value : unknown ) : value is string [ ] {
64
+ return Array . isArray ( value ) && value . every ( ( item ) => typeof item === 'string' ) ;
65
+ }
63
66
64
- // We can now use the type guard to ensure type safety
65
- if ( ! isStringArray ( result ) ) {
66
- throw new Error ( 'Unexpected result type' ) ;
67
- }
67
+ // We can now use the type guard to ensure type safety
68
+ if ( ! isStringArray ( result ) ) {
69
+ throw new Error ( 'Unexpected result type' ) ;
70
+ }
68
71
69
- const selectedFrameworks = result ;
72
+ const selectedFrameworks = result ;
70
73
71
- // If no items selected, show a message
72
- if ( selectedFrameworks . length === 0 ) {
73
- p . note ( 'No frameworks were selected' , 'Empty Selection' ) ;
74
- process . exit ( 0 ) ;
75
- }
74
+ // If no items selected, show a message
75
+ if ( selectedFrameworks . length === 0 ) {
76
+ p . note ( 'No frameworks were selected' , 'Empty Selection' ) ;
77
+ process . exit ( 0 ) ;
78
+ }
76
79
77
- // Display selected frameworks with detailed information
78
- p . note ( `You selected ${ color . green ( selectedFrameworks . length ) } frameworks:` , 'Selection Complete' ) ;
79
-
80
- // Show each selected framework with its details
81
- const selectedDetails = selectedFrameworks
82
- . map ( value => {
83
- const framework = frameworks . find ( f => f . value === value ) ;
84
- return framework ? `${ color . cyan ( framework . label ) } ${ color . dim ( `- ${ framework . hint } ` ) } ` : value ;
85
- } )
86
- . join ( '\n' ) ;
80
+ // Display selected frameworks with detailed information
81
+ p . note (
82
+ `You selected ${ color . green ( selectedFrameworks . length ) } frameworks:` ,
83
+ 'Selection Complete'
84
+ ) ;
87
85
88
- p . log . message ( selectedDetails ) ;
89
- p . outro ( `Successfully selected ${ color . green ( selectedFrameworks . length ) } frameworks.` ) ;
86
+ // Show each selected framework with its details
87
+ const selectedDetails = selectedFrameworks
88
+ . map ( ( value ) => {
89
+ const framework = frameworks . find ( ( f ) => f . value === value ) ;
90
+ return framework
91
+ ? `${ color . cyan ( framework . label ) } ${ color . dim ( `- ${ framework . hint } ` ) } `
92
+ : value ;
93
+ } )
94
+ . join ( '\n' ) ;
95
+
96
+ p . log . message ( selectedDetails ) ;
97
+ p . outro ( `Successfully selected ${ color . green ( selectedFrameworks . length ) } frameworks.` ) ;
90
98
}
91
99
92
- main ( ) . catch ( console . error ) ;
100
+ main ( ) . catch ( console . error ) ;
0 commit comments