Make ANSI escape colors into constants
This commit is contained in:
parent
ae5228a6f1
commit
bb10b69e12
46
src/Color.php
Normal file
46
src/Color.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Kilo;
|
||||
|
||||
/**
|
||||
* ANSI Color escape sequences
|
||||
*/
|
||||
class Color {
|
||||
// Foreground colors
|
||||
public const FG_BLACK = 30;
|
||||
public const FG_RED = 31;
|
||||
public const FG_GREEN = 32;
|
||||
public const FG_YELLOW = 33;
|
||||
public const FG_BLUE = 34;
|
||||
public const FG_MAGENTA = 35;
|
||||
public const FG_CYAN = 36;
|
||||
public const FG_WHITE = 37;
|
||||
public const FG_BRIGHT_BLACK = 90;
|
||||
public const FG_BRIGHT_RED = 91;
|
||||
public const FG_BRIGHT_GREEN = 92;
|
||||
public const FG_BRIGHT_YELLOW = 93;
|
||||
public const FG_BRIGHT_BLUE = 94;
|
||||
public const FG_BRIGHT_MAGENTA = 95;
|
||||
public const FG_BRIGHT_CYAN = 96;
|
||||
public const FG_BRIGHT_WHITE = 97;
|
||||
|
||||
// Background colors
|
||||
public const BG_BLACK = 40;
|
||||
public const BG_RED = 41;
|
||||
public const BG_GREEN = 42;
|
||||
public const BG_YELLOW = 43;
|
||||
public const BG_BLUE = 44;
|
||||
public const BG_MAGENTA = 45;
|
||||
public const BG_CYAN = 46;
|
||||
public const BG_WHITE = 47;
|
||||
public const BG_BRIGHT_BLACK = 100;
|
||||
public const BG_BRIGHT_RED = 101;
|
||||
public const BG_BRIGHT_GREEN = 102;
|
||||
public const BG_BRIGHT_YELLOW = 103;
|
||||
public const BG_BRIGHT_BLUE = 104;
|
||||
public const BG_BRIGHT_MAGENTA = 105;
|
||||
public const BG_BRIGHT_CYAN = 106;
|
||||
public const BG_BRIGHT_WHITE = 107;
|
||||
|
||||
public const INVERT = 7;
|
||||
}
|
@ -294,22 +294,22 @@ function array_replace_range(array &$array, int $offset, int $length, $value):vo
|
||||
function syntax_to_color(int $hl): int
|
||||
{
|
||||
$map = [
|
||||
Highlight::COMMENT => 36, // Foreground Cyan,
|
||||
Highlight::ML_COMMENT => 90, // Foreground Bright Black
|
||||
Highlight::KEYWORD1 => 33, // Foreground Yellow
|
||||
Highlight::KEYWORD2 => 32, // Foreground Green
|
||||
Highlight::STRING => 35, // Foreground Magenta
|
||||
Highlight::NUMBER => 31, // Foreground Red
|
||||
Highlight::OPERATOR => 92, // Foreground Bright Green
|
||||
Highlight::VARIABLE => 96, // Foreground Bright Cyan
|
||||
Highlight::DELIMITER => 34, // Foreground Blue
|
||||
Highlight::INVALID => 101, // Background Bright Red
|
||||
Highlight::MATCH => 7, // Reverse!
|
||||
Highlight::COMMENT => Color::FG_CYAN,
|
||||
Highlight::ML_COMMENT => Color::FG_BRIGHT_BLACK,
|
||||
Highlight::KEYWORD1 => Color::FG_YELLOW,
|
||||
Highlight::KEYWORD2 => Color::FG_GREEN,
|
||||
Highlight::STRING => Color::FG_MAGENTA,
|
||||
Highlight::NUMBER => Color::FG_RED,
|
||||
Highlight::OPERATOR => Color::FG_BRIGHT_GREEN,
|
||||
Highlight::VARIABLE => Color::FG_BRIGHT_CYAN,
|
||||
Highlight::DELIMITER => Color::FG_BLUE,
|
||||
Highlight::INVALID => Color::BG_BRIGHT_RED,
|
||||
Highlight::MATCH => Color::INVERT,
|
||||
];
|
||||
|
||||
return (array_key_exists($hl, $map))
|
||||
? $map[$hl]
|
||||
: 37; // Foreground White
|
||||
: Color::FG_WHITE;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -350,7 +350,7 @@ function get_php_tokens(string $code): array
|
||||
'type' => $type,
|
||||
'typeName' => token_name($type),
|
||||
'char' => $char,
|
||||
// 'line' => $currentLine,
|
||||
'line' => $currentLine,
|
||||
];
|
||||
|
||||
if ($currentLine !== $lineNum)
|
||||
|
Loading…
Reference in New Issue
Block a user