1818 */
1919class AnsiToHtmlConverter
2020{
21- protected $ theme ;
22- protected $ charset ;
23- protected $ inlineStyles ;
2421 protected $ inlineColors ;
2522 protected $ colorNames ;
2623
27- public function __construct (? Theme $ theme = null , $ inlineStyles = true , $ charset = ' UTF-8 ' )
28- {
29- $ this -> theme = null === $ theme ? new Theme () : $ theme ;
30- $ this -> inlineStyles = $ inlineStyles ;
31- $ this -> charset = $ charset ;
24+ public function __construct (
25+ protected Theme $ theme = new Theme (),
26+ protected bool $ inlineStyles = true ,
27+ protected string $ charset = ' UTF-8 ' ,
28+ ) {
3229 $ this ->inlineColors = $ this ->theme ->asArray ();
3330 $ this ->colorNames = [
3431 'black ' , 'red ' , 'green ' , 'yellow ' , 'blue ' , 'magenta ' , 'cyan ' , 'white ' ,
@@ -37,7 +34,7 @@ public function __construct(?Theme $theme = null, $inlineStyles = true, $charset
3734 ];
3835 }
3936
40- public function convert ($ text )
37+ public function convert (string $ text ): string
4138 {
4239 // remove cursor movement sequences
4340 $ text = preg_replace ('#\e\[(K|s|u|2J|2K|\d+(A|B|C|D|E|F|G|J|K|S|T)|\d+;\d+(H|f))# ' , '' , $ text );
@@ -86,12 +83,12 @@ public function convert($text)
8683 return $ html ;
8784 }
8885
89- public function getTheme ()
86+ public function getTheme (): Theme
9087 {
9188 return $ this ->theme ;
9289 }
9390
94- protected function convertAnsiToColor ($ ansi )
91+ protected function convertAnsiToColor (string $ ansi ): string
9592 {
9693 $ bg = 0 ;
9794 $ fg = 7 ;
@@ -173,7 +170,7 @@ protected function convertAnsiToColor($ansi)
173170 }
174171 }
175172
176- protected function tokenize ($ text )
173+ protected function tokenize (string $ text ): array
177174 {
178175 $ tokens = [];
179176 preg_match_all ("/(?: \e\[(.*?)m|( \x08))/ " , $ text , $ matches , \PREG_OFFSET_CAPTURE );
0 commit comments