@@ -25,17 +25,17 @@ public function __construct()
2525 parent ::__construct ('clish ' , 'PHP CLI syntax highlight and/or export. ' );
2626
2727 $ this
28- ->option ('-o --output ' , 'Output filepath where PNG image is exported ' )
29- ->option ('-e --echo ' , 'Forces echo to STDOUT when --output is passed ' )
28+ ->option ('-o --output ' , 'Output filepath where PNG image is exported ' , null , '' )
29+ ->option ('-e --echo ' , 'Forces echo to STDOUT when --output is passed ' , null , '' )
3030 ->option ('-f --file ' , \implode ("\n" , [
3131 'Input PHP file to highlight and/or export ' ,
3232 '(will read from piped input if file not given) ' ,
33- ]))
34- ->option ('-F --font ' , 'Font to use for export to png ' )
33+ ]), null , '' )
34+ ->option ('-F --font ' , 'Font to use for export to png ' , null , '' )
3535 ->usage (
3636 '<bold> $0</end> <comment>--file file.php</end> ## print<eol/> '
37- . '<bold > cat file.php | $0</end> ## from piped stream<eol/> '
38- . '<bold> $0</end> <comment>< file.php ## from redirected stdin<eol/> '
37+ . '<comment > cat file.php |</end> <bold> $0</end> ## from piped stream<eol/> '
38+ . '<bold> $0</end> <comment>< file.php</end> ## from redirected stdin<eol/> '
3939 . '<bold> $0</end> <comment>--file file.php --output file.png</end> ## export<eol/> '
4040 . '<bold> $0</end> <comment>--file file.php --output file.png --echo</end> ## print + export<eol/> '
4141 . '<bold> $0</end> <comment>-f file.php -o file.png -F dejavu</end> ## export in dejavu font<eol/> '
@@ -44,7 +44,7 @@ public function __construct()
4444
4545 public function interact (Interactor $ io )
4646 {
47- if (\is_string ( $ this ->file ) ) {
47+ if ($ this ->file ) {
4848 return ;
4949 }
5050
@@ -92,6 +92,23 @@ protected function doExport(string $code = null)
9292 \mkdir (\dirname ($ this ->output ), 0755 , true );
9393 }
9494
95- (new Exporter ($ code ))->export ($ this ->output , \array_filter (['font ' => $ this ->font ]));
95+ $ options = ['font ' => $ this ->fixFont ($ this ->font ?: 'ubuntu ' )];
96+
97+ (new Exporter ($ code ))->export ($ this ->output , $ options );
98+ }
99+
100+ /** @codeCoverageIgnore */
101+ protected function fixFont (string $ font ): string
102+ {
103+ if (\Phar::running ()) {
104+ $ basename = \basename ($ font , '.ttf ' );
105+ $ pharfont = __DIR__ . "/../../font/ $ basename.ttf " ;
106+
107+ if (!\is_file ($ font ) && \is_file ($ pharfont )) {
108+ \copy ($ pharfont , $ font = sys_get_temp_dir () . '/clish.ttf ' );
109+ }
110+ }
111+
112+ return $ font ;
96113 }
97114}
0 commit comments