@@ -25,17 +25,17 @@ public function __construct()
25
25
parent ::__construct ('clish ' , 'PHP CLI syntax highlight and/or export. ' );
26
26
27
27
$ 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 , '' )
30
30
->option ('-f --file ' , \implode ("\n" , [
31
31
'Input PHP file to highlight and/or export ' ,
32
32
'(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 , '' )
35
35
->usage (
36
36
'<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/> '
39
39
. '<bold> $0</end> <comment>--file file.php --output file.png</end> ## export<eol/> '
40
40
. '<bold> $0</end> <comment>--file file.php --output file.png --echo</end> ## print + export<eol/> '
41
41
. '<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()
44
44
45
45
public function interact (Interactor $ io )
46
46
{
47
- if (\is_string ( $ this ->file ) ) {
47
+ if ($ this ->file ) {
48
48
return ;
49
49
}
50
50
@@ -92,6 +92,23 @@ protected function doExport(string $code = null)
92
92
\mkdir (\dirname ($ this ->output ), 0755 , true );
93
93
}
94
94
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 ;
96
113
}
97
114
}
0 commit comments