@@ -28,23 +28,46 @@ class CliDumper extends AbstractDumper
28
28
protected $ maxStringWidth = 0 ;
29
29
protected $ styles = array (
30
30
// See http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
31
- 'num ' => '1;38;5;33 ' ,
32
- 'const ' => '1;38;5;33 ' ,
33
- 'str ' => '1;38;5;37 ' ,
31
+ 'default ' => '38;5;208 ' ,
32
+ 'num ' => '1;38;5;38 ' ,
33
+ 'const ' => '1;38;5;208 ' ,
34
+ 'str ' => '1;38;5;113 ' ,
34
35
'cchr ' => '7 ' ,
35
- 'note ' => '38;5;178 ' ,
36
- 'ref ' => '38;5;240 ' ,
37
- 'solo-ref ' => '38;5;240 ' ,
38
- 'public ' => '38;5;28 ' ,
39
- 'protected ' => '38;5;166 ' ,
40
- 'private ' => '38;5;160 ' ,
41
- 'meta ' => '38;5;27 ' ,
42
- 'key ' => '38;5;27 ' ,
43
- 'index ' => '38;5;27 ' ,
36
+ 'note ' => '38;5;38 ' ,
37
+ 'ref ' => '38;5;247 ' ,
38
+ 'public ' => '' ,
39
+ 'protected ' => '' ,
40
+ 'private ' => '' ,
41
+ 'meta ' => '38;5;170 ' ,
42
+ 'key ' => '38;5;113 ' ,
43
+ 'index ' => '38;5;38 ' ,
44
44
);
45
45
46
46
protected static $ controlCharsRx = '/[\x00-\x1F\x7F]/ ' ;
47
47
48
+ /**
49
+ * {@inheritdoc}
50
+ */
51
+ public function __construct ($ output = null )
52
+ {
53
+ parent ::__construct ($ output );
54
+
55
+ if (defined ('PHP_WINDOWS_VERSION_MAJOR ' ) && false !== @getenv ('ANSICON ' )) {
56
+ // Use only the base 16 xterm colors when using ANSICON
57
+ $ this ->setStyles (array (
58
+ 'default ' => '31 ' ,
59
+ 'num ' => '1;34 ' ,
60
+ 'const ' => '1;31 ' ,
61
+ 'str ' => '1;32 ' ,
62
+ 'note ' => '34 ' ,
63
+ 'ref ' => '1;30 ' ,
64
+ 'meta ' => '35 ' ,
65
+ 'key ' => '32 ' ,
66
+ 'index ' => '34 ' ,
67
+ ));
68
+ }
69
+ }
70
+
48
71
/**
49
72
* Enables/disables colored output.
50
73
*
@@ -70,7 +93,7 @@ public function setMaxStringWidth($maxStringWidth)
70
93
/**
71
94
* Configures styles.
72
95
*
73
- * @param array $styles A map of style namaes to style definitions.
96
+ * @param array $styles A map of style names to style definitions.
74
97
*/
75
98
public function setStyles (array $ styles )
76
99
{
@@ -205,10 +228,8 @@ public function enterHash(Cursor $cursor, $type, $class, $hasChild)
205
228
$ prefix = $ class ? $ this ->style ('note ' , 'array: ' .$ class ).' [ ' : '[ ' ;
206
229
}
207
230
208
- if ($ cursor ->softRefCount ) {
231
+ if ($ cursor ->softRefCount || 0 < $ cursor -> softRefHandle ) {
209
232
$ prefix .= $ this ->style ('ref ' , (Cursor::HASH_RESOURCE === $ type ? '@ ' : '# ' ).(0 < $ cursor ->softRefHandle ? $ cursor ->softRefHandle : $ cursor ->softRefTo ), array ('count ' => $ cursor ->softRefCount ));
210
- } elseif (0 < $ cursor ->softRefHandle ) {
211
- $ prefix .= $ this ->style ('solo-ref ' , (Cursor::HASH_RESOURCE === $ type ? '@ ' : '# ' ).$ cursor ->softRefHandle );
212
233
} elseif ($ cursor ->hardRefTo && !$ cursor ->refIndex && $ class ) {
213
234
$ prefix .= $ this ->style ('ref ' , '& ' .$ cursor ->hardRefTo , array ('count ' => $ cursor ->hardRefCount ));
214
235
}
@@ -310,7 +331,7 @@ protected function dumpKey(Cursor $cursor)
310
331
}
311
332
312
333
if ($ cursor ->hardRefTo ) {
313
- $ this ->line .= ( $ cursor -> hardRefCount ? $ this ->style ('ref ' , '& ' .$ cursor ->hardRefTo , array ('count ' => $ cursor ->hardRefCount )) : $ this -> style ( ' solo-ref ' , ' & ' )).' ' ;
334
+ $ this ->line .= $ this ->style ('ref ' , '& ' .$ cursor ->hardRefTo , array ('count ' => $ cursor ->hardRefCount )).' ' ;
314
335
}
315
336
}
316
337
}
@@ -327,7 +348,7 @@ protected function dumpKey(Cursor $cursor)
327
348
protected function style ($ style , $ value , $ attr = array ())
328
349
{
329
350
if (null === $ this ->colors ) {
330
- $ this ->colors = $ this ->supportsColors ($ this -> outputStream );
351
+ $ this ->colors = $ this ->supportsColors ();
331
352
}
332
353
333
354
$ style = $ this ->styles [$ style ];
@@ -336,7 +357,7 @@ protected function style($style, $value, $attr = array())
336
357
return sprintf ($ cchr , "\x7F" === $ r [0 ] ? '? ' : chr (64 + ord ($ r [0 ])));
337
358
}, $ value );
338
359
339
- return $ this ->colors ? sprintf ("\033[%sm%s \033[m " , $ style , $ value ) : $ value ;
360
+ return $ this ->colors ? sprintf ("\033[%sm%s \033[m \033 [%sm " , $ style , $ value, $ this -> styles [ ' default ' ] ) : $ value ;
340
361
}
341
362
342
363
/**
@@ -385,4 +406,15 @@ protected function supportsColors()
385
406
386
407
return static ::$ defaultColors ;
387
408
}
409
+
410
+ /**
411
+ * {@inheritdoc}
412
+ */
413
+ protected function dumpLine ($ depth )
414
+ {
415
+ if ($ this ->colors ) {
416
+ $ this ->line = sprintf ("\033[%sm%s \033[m " , $ this ->styles ['default ' ], $ this ->line );
417
+ }
418
+ parent ::dumpLine ($ depth );
419
+ }
388
420
}
0 commit comments