Skip to content

Commit

Permalink
Colorized file name and line in console output
Browse files Browse the repository at this point in the history
Fixes #4129
  • Loading branch information
Rarst authored and weirdan committed Nov 27, 2021
1 parent 72de3b6 commit 03ae329
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Psalm/Report/ConsoleReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
use Psalm\Internal\Analyzer\IssueData;
use Psalm\Report;

use function basename;
use function get_cfg_var;
use function ini_get;
use function strlen;
use function strtr;
use function substr;

Expand Down Expand Up @@ -118,6 +120,15 @@ private function getFileReference($data): string
return $reference;
}

$file_basename = basename($data->file_name);
$file_path = substr($data->file_name, 0, -strlen($file_basename));

$reference = $file_path
. "\e[1;31m"
. $file_basename . ':' . $data->line_from . ':' . $data->column_from
. "\e[0m"
;

if (null === $this->link_format) {
// if xdebug is not enabled, use `get_cfg_var` to get the value directly from php.ini
$this->link_format = ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format')
Expand All @@ -127,6 +138,7 @@ private function getFileReference($data): string
$link = strtr($this->link_format, ['%f' => $data->file_path, '%l' => $data->line_from]);
// $reference = $data->file_name . ':' . $data->line_from . ':' . $data->column_from;


return "\033]8;;" . $link . "\033\\" . $reference . "\033]8;;\033\\";
}
}

0 comments on commit 03ae329

Please sign in to comment.