Skip to content

Commit bfd095d

Browse files
committed
Debug info now looks clean again on Windows
1 parent d9c86c5 commit bfd095d

File tree

4 files changed

+199
-56
lines changed

4 files changed

+199
-56
lines changed

CodeSniffer/File.php

+44-10
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,10 @@ public function start($contents=null)
520520
if (PHP_CODESNIFFER_VERBOSITY > 2) {
521521
$type = $token['type'];
522522
$content = str_replace($this->eolChar, '\n', $token['content']);
523-
$content = str_replace(' ', "\033[30;1m·\033[0m", $content);
523+
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
524+
$content = str_replace(' ', "\033[30;1m·\033[0m", $content);
525+
}
526+
524527
echo "\t\tProcess token $stackPtr: $type => $content".PHP_EOL;
525528
}
526529

@@ -1596,16 +1599,25 @@ private static function _createScopeMap(&$tokens, $tokenizer, $eolChar)
15961599
{
15971600
if (PHP_CODESNIFFER_VERBOSITY > 1) {
15981601
echo "\t*** START SCOPE MAP ***".PHP_EOL;
1602+
$isWin = false;
1603+
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
1604+
$isWin = true;
1605+
}
15991606
}
16001607

16011608
$numTokens = count($tokens);
16021609
for ($i = 0; $i < $numTokens; $i++) {
16031610
// Check to see if the current token starts a new scope.
16041611
if (isset($tokenizer->scopeOpeners[$tokens[$i]['code']]) === true) {
16051612
if (PHP_CODESNIFFER_VERBOSITY > 1) {
1606-
$type = $tokens[$i]['type'];
1607-
$content = str_replace($eolChar, "\033[30;1m\\n\033[0m", $tokens[$i]['content']);
1608-
$content = str_replace(' ', "\033[30;1m·\033[0m", $content);
1613+
$type = $tokens[$i]['type'];
1614+
if ($isWin === true) {
1615+
$content = str_replace($eolChar, '\n', $tokens[$i]['content']);
1616+
} else {
1617+
$content = str_replace($eolChar, "\033[30;1m\\n\033[0m", $tokens[$i]['content']);
1618+
$content = str_replace(' ', "\033[30;1m·\033[0m", $content);
1619+
}
1620+
16091621
echo "\tStart scope map at $i:$type => $content".PHP_EOL;
16101622
}
16111623

@@ -1649,6 +1661,14 @@ private static function _recurseScopeMap(
16491661
$depth=1,
16501662
&$ignore=0
16511663
) {
1664+
if (PHP_CODESNIFFER_VERBOSITY > 1) {
1665+
echo "\t*** START SCOPE MAP ***".PHP_EOL;
1666+
$isWin = false;
1667+
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
1668+
$isWin = true;
1669+
}
1670+
}
1671+
16521672
$opener = null;
16531673
$currType = $tokens[$stackPtr]['code'];
16541674
$startLine = $tokens[$stackPtr]['line'];
@@ -1669,8 +1689,13 @@ private static function _recurseScopeMap(
16691689

16701690
if (PHP_CODESNIFFER_VERBOSITY > 1) {
16711691
$type = $tokens[$i]['type'];
1672-
$content = str_replace($eolChar, "\033[30;1m\\n\033[0m", $tokens[$i]['content']);
1673-
$content = str_replace(' ', "\033[30;1m·\033[0m", $content);
1692+
if ($isWin === true) {
1693+
$content = str_replace($eolChar, '\n', $tokens[$i]['content']);
1694+
} else {
1695+
$content = str_replace($eolChar, "\033[30;1m\\n\033[0m", $tokens[$i]['content']);
1696+
$content = str_replace(' ', "\033[30;1m·\033[0m", $content);
1697+
}
1698+
16741699
echo str_repeat("\t", $depth);
16751700
echo "Process token $i [";
16761701
if ($opener !== null) {
@@ -1993,6 +2018,10 @@ private static function _createLevelMap(&$tokens, $tokenizer, $eolChar)
19932018
{
19942019
if (PHP_CODESNIFFER_VERBOSITY > 1) {
19952020
echo "\t*** START LEVEL MAP ***".PHP_EOL;
2021+
$isWin = false;
2022+
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
2023+
$isWin = true;
2024+
}
19962025
}
19972026

19982027
$numTokens = count($tokens);
@@ -2003,10 +2032,15 @@ private static function _createLevelMap(&$tokens, $tokenizer, $eolChar)
20032032

20042033
for ($i = 0; $i < $numTokens; $i++) {
20052034
if (PHP_CODESNIFFER_VERBOSITY > 1) {
2006-
$type = $tokens[$i]['type'];
2007-
$line = $tokens[$i]['line'];
2008-
$content = str_replace($eolChar, "\033[30;1m\\n\033[0m", $tokens[$i]['content']);
2009-
$content = str_replace(' ', "\033[30;1m·\033[0m", $content);
2035+
$type = $tokens[$i]['type'];
2036+
$line = $tokens[$i]['line'];
2037+
if ($isWin === true) {
2038+
$content = str_replace($eolChar, '\n', $tokens[$i]['content']);
2039+
} else {
2040+
$content = str_replace($eolChar, "\033[30;1m\\n\033[0m", $tokens[$i]['content']);
2041+
$content = str_replace(' ', "\033[30;1m·\033[0m", $content);
2042+
}
2043+
20102044
echo str_repeat("\t", ($level + 1));
20112045
echo "Process token $i on line $line [lvl:$level;";
20122046
if (empty($conditions) !== true) {

CodeSniffer/Tokenizers/CSS.php

+19-5
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public function tokenizeString($string, $eolChar='\n')
4545
{
4646
if (PHP_CODESNIFFER_VERBOSITY > 1) {
4747
echo "\t*** START CSS TOKENIZING ***".PHP_EOL;
48+
$isWin = false;
49+
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
50+
$isWin = true;
51+
}
4852
}
4953

5054
// If the content doesn't have an EOL char on the end, add one so
@@ -79,9 +83,14 @@ public function tokenizeString($string, $eolChar='\n')
7983
}
8084

8185
if (PHP_CODESNIFFER_VERBOSITY > 1) {
82-
$type = $token['type'];
83-
$content = str_replace($eolChar, "\033[30;1m\\n\033[0m", $token['content']);
84-
$content = str_replace(' ', "\033[30;1m·\033[0m", $content);
86+
$type = $token['type'];
87+
if ($isWin === true) {
88+
$content = str_replace($eolChar, '\n', $token['content']);
89+
} else {
90+
$content = str_replace($eolChar, "\033[30;1m\\n\033[0m", $token['content']);
91+
$content = str_replace(' ', "\033[30;1m·\033[0m", $content);
92+
}
93+
8594
echo "\tProcess token $stackPtr: $type => $content".PHP_EOL;
8695
}
8796

@@ -110,8 +119,13 @@ public function tokenizeString($string, $eolChar='\n')
110119

111120
if (PHP_CODESNIFFER_VERBOSITY > 1) {
112121
echo "\t\t=> Found premature closing tag at $stackPtr".PHP_EOL;
113-
$cleanContent = str_replace($eolChar, "\033[30;1m\\n\033[0m", $content);
114-
$cleanContent = str_replace(' ', "\033[30;1m·\033[0m", $cleanContent);
122+
if ($isWin === true) {
123+
$cleanContent = str_replace($eolChar, '\n', $content);
124+
} else {
125+
$cleanContent = str_replace($eolChar, "\033[30;1m\\n\033[0m", $content);
126+
$cleanContent = str_replace(' ', "\033[30;1m·\033[0m", $cleanContent);
127+
}
128+
115129
echo "\t\tcontent: $cleanContent".PHP_EOL;
116130
$oldNumTokens = $numTokens;
117131
}

0 commit comments

Comments
 (0)