@@ -47,12 +47,59 @@ export async function run(
4747 . option ( '--theme <theme>' , 'Color theme to use' , { default : 'vitesse-dark' } )
4848 . option ( '--lang <lang>' , 'Programming language' )
4949 . option ( '--format <format>' , 'Output format (ansi, html)' , { default : 'ansi' } )
50+ . option ( '--list-themes' , 'List all available themes' )
51+ . option ( '--list-langs' , 'List all available languages' )
5052 . help ( )
5153 . version ( version )
5254
5355 const { options, args } = cli . parse ( argv )
56+
57+ if ( options . listThemes ) {
58+ const { bundledThemes } = await import ( 'shiki' )
59+ for ( const theme of Object . keys ( bundledThemes ) )
60+ log ( theme )
61+ return
62+ }
63+
64+ if ( options . listLangs ) {
65+ const { bundledLanguages } = await import ( 'shiki' )
66+ for ( const lang of Object . keys ( bundledLanguages ) )
67+ log ( lang )
68+ return
69+ }
70+
5471 const files = args
5572
73+ if ( files . length === 0 ) {
74+ // If no files provided, verify if we are in a TTY environment
75+ // If NOT in TTY (piped), read from stdin
76+ // If in TTY, show help
77+ if ( ! process . stdin . isTTY ) {
78+ const content = await new Promise < string > ( ( resolve , reject ) => {
79+ let data = ''
80+ process . stdin . on ( 'data' , chunk => data += chunk )
81+ process . stdin . on ( 'end' , ( ) => resolve ( data ) )
82+ process . stdin . on ( 'error' , reject )
83+ } )
84+
85+ const lang = options . lang || 'text'
86+ if ( options . format === 'html' ) {
87+ const { codeToHtml } = await import ( 'shiki' )
88+ log ( await codeToHtml ( content , {
89+ lang : lang as BundledLanguage ,
90+ theme : options . theme ,
91+ } ) )
92+ }
93+ else {
94+ log ( await codeToANSI ( content , lang as BundledLanguage , options . theme ) )
95+ }
96+ return
97+ }
98+
99+ cli . outputHelp ( )
100+ return
101+ }
102+
56103 const codes = await Promise . all ( files . map ( async ( path ) => {
57104 const { content, ext } = await readSource ( path )
58105 const lang = options . lang || ext
0 commit comments