Refactor array_replace_range and syntax_to_color
This commit is contained in:
parent
e6dc670c1d
commit
4df0644bc2
@ -269,36 +269,28 @@ function read_stdout(int $len = 128): string
|
|||||||
*/
|
*/
|
||||||
function array_replace_range(array &$array, int $offset, int $length, $value):void
|
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++)
|
for ($i = $offset; $i < $end; $i++)
|
||||||
{
|
{
|
||||||
$array[$i] = $value;
|
$array[$i] = $value;
|
||||||
}
|
} */
|
||||||
}
|
}
|
||||||
|
|
||||||
function syntax_to_color(int $hl): int
|
function syntax_to_color(int $hl): int
|
||||||
{
|
{
|
||||||
switch ($hl)
|
$map = [
|
||||||
{
|
Highlight::COMMENT => 36, // Foreground Cyan,
|
||||||
case Highlight::COMMENT:
|
Highlight::KEYWORD1 => 33, // Foreground Yellow
|
||||||
return 36; // Foreground Cyan
|
Highlight::KEYWORD2 => 32, // Foreground Green
|
||||||
|
Highlight::STRING => 35, // Foreground Magenta
|
||||||
|
Highlight::NUMBER => 31, // Foreground Red
|
||||||
|
Highlight::MATCH => 34, // Foreground Blue
|
||||||
|
];
|
||||||
|
|
||||||
case Highlight::KEYWORD1:
|
return (array_key_exists($hl, $map))
|
||||||
return 33; // Foreground Yellow
|
? $map[$hl]
|
||||||
|
: 37; // Foreground White
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user