Refactor array_replace_range and syntax_to_color

This commit is contained in:
Timothy Warren 2019-10-25 15:35:20 -04:00
parent e6dc670c1d
commit 4df0644bc2
1 changed files with 16 additions and 24 deletions

View File

@ -269,36 +269,28 @@ function read_stdout(int $len = 128): string
*/
function array_replace_range(array &$array, int $offset, int $length, $value):void
{
$end = $offset + $length;
$replacement = array_fill(0, $length, $value);
array_splice($array, $offset, $length, $replacement);
/* $end = $offset + $length;
for ($i = $offset; $i < $end; $i++)
{
$array[$i] = $value;
}
} */
}
function syntax_to_color(int $hl): int
{
switch ($hl)
{
case Highlight::COMMENT:
return 36; // Foreground Cyan
$map = [
Highlight::COMMENT => 36, // Foreground Cyan,
Highlight::KEYWORD1 => 33, // Foreground Yellow
Highlight::KEYWORD2 => 32, // Foreground Green
Highlight::STRING => 35, // Foreground Magenta
Highlight::NUMBER => 31, // Foreground Red
Highlight::MATCH => 34, // Foreground Blue
];
case Highlight::KEYWORD1:
return 33; // Foreground Yellow
case Highlight::KEYWORD2:
return 32; // Foreground Green
case Highlight::STRING:
return 35; // Foreground Magenta
case Highlight::NUMBER:
return 31; // Foreground Red
case Highlight::MATCH:
return 34; // Foreground Blue
default:
return 37; // Foreground White
}
return (array_key_exists($hl, $map))
? $map[$hl]
: 37; // Foreground White
}