Refactor to use new enums
This commit is contained in:
parent
9214c16595
commit
36da56c519
@ -1,4 +1,4 @@
|
|||||||
FROM php:8-alpine3.13
|
FROM php:alpine
|
||||||
|
|
||||||
RUN apk add --no-cache --virtual .persistent-deps libffi-dev \
|
RUN apk add --no-cache --virtual .persistent-deps libffi-dev \
|
||||||
&& docker-php-ext-configure ffi --with-ffi \
|
&& docker-php-ext-configure ffi --with-ffi \
|
||||||
|
2
Jenkinsfile
vendored
2
Jenkinsfile
vendored
@ -5,7 +5,7 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
stages {
|
stages {
|
||||||
stage('PHP 7.4') {
|
stage('PHP 8.1') {
|
||||||
steps {
|
steps {
|
||||||
sh 'apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing php8-phpdbg'
|
sh 'apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing php8-phpdbg'
|
||||||
sh 'curl -sS https://getcomposer.org/installer | php'
|
sh 'curl -sS https://getcomposer.org/installer | php'
|
||||||
|
@ -58,12 +58,12 @@ class ANSI {
|
|||||||
/**
|
/**
|
||||||
* Generate the ascii sequence for basic foreground text color
|
* Generate the ascii sequence for basic foreground text color
|
||||||
*
|
*
|
||||||
* @param int $color
|
* @param Enum\Color $color
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function color(int $color): string
|
public static function color(Enum\Color $color): string
|
||||||
{
|
{
|
||||||
return self::escapeSequence('%dm', $color);
|
return self::escapeSequence('%dm', $color->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -95,14 +95,14 @@ class Document {
|
|||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function insert(Point $at, string $c): void
|
public function insert(Point $at, string|KeyType $c): void
|
||||||
{
|
{
|
||||||
if ($at->y > $this->numRows)
|
if ($at->y > $this->numRows)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($c === KeyType::ENTER || $c === RawKeyCode::CARRIAGE_RETURN)
|
if ($c === KeyType::Enter || $c === RawKeyCode::CARRIAGE_RETURN)
|
||||||
{
|
{
|
||||||
$this->insertNewline($at);
|
$this->insertNewline($at);
|
||||||
$this->dirty = true;
|
$this->dirty = true;
|
||||||
|
@ -233,7 +233,7 @@ class Editor {
|
|||||||
// ! Find
|
// ! Find
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
protected function findCallback(string $query, string $key): void
|
protected function findCallback(string $query, string|KeyType $key): void
|
||||||
{
|
{
|
||||||
static $lastMatch = NO_MATCH;
|
static $lastMatch = NO_MATCH;
|
||||||
static $direction = SearchDirection::FORWARD;
|
static $direction = SearchDirection::FORWARD;
|
||||||
@ -254,11 +254,11 @@ class Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$direction = match ($key) {
|
$direction = match ($key) {
|
||||||
KeyType::ARROW_UP, KeyType::ARROW_LEFT => SearchDirection::BACKWARD,
|
KeyType::ArrowUp, KeyType::ArrowLeft => SearchDirection::BACKWARD,
|
||||||
default => SearchDirection::FORWARD
|
default => SearchDirection::FORWARD
|
||||||
};
|
};
|
||||||
|
|
||||||
$arrowKeys = [KeyType::ARROW_UP, KeyType::ARROW_DOWN, KeyType::ARROW_LEFT, KeyType::ARROW_RIGHT];
|
$arrowKeys = [KeyType::ArrowUp, KeyType::ArrowDown, KeyType::ArrowLeft, KeyType::ArrowRight];
|
||||||
|
|
||||||
// Reset search state with non arrow-key input
|
// Reset search state with non arrow-key input
|
||||||
if ( ! in_array($key, $arrowKeys, true))
|
if ( ! in_array($key, $arrowKeys, true))
|
||||||
@ -286,7 +286,7 @@ class Editor {
|
|||||||
|
|
||||||
for ($i = 0; $i < $this->document->numRows; $i++)
|
for ($i = 0; $i < $this->document->numRows; $i++)
|
||||||
{
|
{
|
||||||
$current += $direction;
|
$current += $direction->value;
|
||||||
if ($current === -1)
|
if ($current === -1)
|
||||||
{
|
{
|
||||||
$current = $this->document->numRows - 1;
|
$current = $this->document->numRows - 1;
|
||||||
@ -313,7 +313,7 @@ class Editor {
|
|||||||
$savedHlLine = $current;
|
$savedHlLine = $current;
|
||||||
$savedHl = $row->hl;
|
$savedHl = $row->hl;
|
||||||
// Update the highlight array of the relevant row with the 'MATCH' type
|
// Update the highlight array of the relevant row with the 'MATCH' type
|
||||||
array_replace_range($row->hl, $match, strlen($query), Highlight::MATCH);
|
array_replace_range($row->hl, $match, strlen($query), Highlight::SearchMatch);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -432,7 +432,7 @@ class Editor {
|
|||||||
$this->outputBuffer .= ANSI::color($currentColor);
|
$this->outputBuffer .= ANSI::color($currentColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ($hl[$i] === Highlight::NORMAL)
|
else if ($hl[$i] === Highlight::Normal)
|
||||||
{
|
{
|
||||||
if ($currentColor !== -1)
|
if ($currentColor !== -1)
|
||||||
{
|
{
|
||||||
@ -574,7 +574,7 @@ class Editor {
|
|||||||
$c = Terminal::readKey();
|
$c = Terminal::readKey();
|
||||||
$isModifier = in_array($c, $modifiers, TRUE);
|
$isModifier = in_array($c, $modifiers, TRUE);
|
||||||
|
|
||||||
if ($c === KeyType::ESCAPE || ($c === RawKeyCode::ENTER && $buffer !== ''))
|
if ($c === KeyType::Escape || ($c === RawKeyCode::ENTER && $buffer !== ''))
|
||||||
{
|
{
|
||||||
$this->setStatusMessage('');
|
$this->setStatusMessage('');
|
||||||
if ($callback !== NULL)
|
if ($callback !== NULL)
|
||||||
@ -584,7 +584,7 @@ class Editor {
|
|||||||
return ($c === RawKeyCode::ENTER) ? $buffer : '';
|
return ($c === RawKeyCode::ENTER) ? $buffer : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($c === KeyType::DELETE || $c === KeyType::BACKSPACE)
|
if ($c === KeyType::Delete || $c === KeyType::Backspace)
|
||||||
{
|
{
|
||||||
$buffer = substr($buffer, 0, -1);
|
$buffer = substr($buffer, 0, -1);
|
||||||
}
|
}
|
||||||
@ -626,24 +626,24 @@ class Editor {
|
|||||||
$this->find();
|
$this->find();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KeyType::DELETE:
|
case KeyType::Delete:
|
||||||
case KeyType::BACKSPACE:
|
case KeyType::Backspace:
|
||||||
$this->removeChar($c);
|
$this->removeChar($c);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KeyType::ARROW_UP:
|
case KeyType::ArrowUp:
|
||||||
case KeyType::ARROW_DOWN:
|
case KeyType::ArrowDown:
|
||||||
case KeyType::ARROW_LEFT:
|
case KeyType::ArrowLeft:
|
||||||
case KeyType::ARROW_RIGHT:
|
case KeyType::ArrowRight:
|
||||||
case KeyType::PAGE_UP:
|
case KeyType::PageUp:
|
||||||
case KeyType::PAGE_DOWN:
|
case KeyType::PageDown:
|
||||||
case KeyType::HOME:
|
case KeyType::Home:
|
||||||
case KeyType::END:
|
case KeyType::End:
|
||||||
$this->moveCursor($c);
|
$this->moveCursor($c);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RawKeyCode::CTRL('l'):
|
case RawKeyCode::CTRL('l'):
|
||||||
case KeyType::ESCAPE:
|
case KeyType::Escape:
|
||||||
// Do nothing
|
// Do nothing
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -664,7 +664,7 @@ class Editor {
|
|||||||
// ! Editor operation helpers
|
// ! Editor operation helpers
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
protected function moveCursor(string $key): void
|
protected function moveCursor(KeyType $key): void
|
||||||
{
|
{
|
||||||
$x = $this->cursor->x;
|
$x = $this->cursor->x;
|
||||||
$y = $this->cursor->y;
|
$y = $this->cursor->y;
|
||||||
@ -676,7 +676,7 @@ class Editor {
|
|||||||
|
|
||||||
switch ($key)
|
switch ($key)
|
||||||
{
|
{
|
||||||
case KeyType::ARROW_LEFT:
|
case KeyType::ArrowLeft:
|
||||||
if ($x !== 0)
|
if ($x !== 0)
|
||||||
{
|
{
|
||||||
$x--;
|
$x--;
|
||||||
@ -689,7 +689,7 @@ class Editor {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KeyType::ARROW_RIGHT:
|
case KeyType::ArrowRight:
|
||||||
if ($x < $row->size)
|
if ($x < $row->size)
|
||||||
{
|
{
|
||||||
$x++;
|
$x++;
|
||||||
@ -701,33 +701,33 @@ class Editor {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KeyType::ARROW_UP:
|
case KeyType::ArrowUp:
|
||||||
if ($y !== 0)
|
if ($y !== 0)
|
||||||
{
|
{
|
||||||
$y--;
|
$y--;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KeyType::ARROW_DOWN:
|
case KeyType::ArrowDown:
|
||||||
if ($y < $this->document->numRows)
|
if ($y < $this->document->numRows)
|
||||||
{
|
{
|
||||||
$y++;
|
$y++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KeyType::PAGE_UP:
|
case KeyType::PageUp:
|
||||||
$y = saturating_sub($y, $this->terminalSize->rows);
|
$y = saturating_sub($y, $this->terminalSize->rows);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KeyType::PAGE_DOWN:
|
case KeyType::PageDown:
|
||||||
$y = saturating_add($y, $this->terminalSize->rows, $this->document->numRows);
|
$y = saturating_add($y, $this->terminalSize->rows, $this->document->numRows);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KeyType::HOME:
|
case KeyType::Home:
|
||||||
$x = 0;
|
$x = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KeyType::END:
|
case KeyType::End:
|
||||||
if ($y < $this->document->numRows)
|
if ($y < $this->document->numRows)
|
||||||
{
|
{
|
||||||
$x = $row->size;
|
$x = $row->size;
|
||||||
@ -753,22 +753,22 @@ class Editor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function insertChar(string $c): void
|
protected function insertChar(string|KeyType $c): void
|
||||||
{
|
{
|
||||||
$this->document->insert($this->cursor, $c);
|
$this->document->insert($this->cursor, $c);
|
||||||
$this->moveCursor(KeyType::ARROW_RIGHT);
|
$this->moveCursor(KeyType::ArrowRight);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function removeChar(string $ch): void
|
protected function removeChar(string|KeyType $ch): void
|
||||||
{
|
{
|
||||||
if ($ch === KeyType::DELETE)
|
if ($ch === KeyType::Delete)
|
||||||
{
|
{
|
||||||
$this->document->delete($this->cursor);
|
$this->document->delete($this->cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($ch === KeyType::BACKSPACE && ($this->cursor->x > 0 || $this->cursor->y > 0))
|
if ($ch === KeyType::Backspace && ($this->cursor->x > 0 || $this->cursor->y > 0))
|
||||||
{
|
{
|
||||||
$this->moveCursor(KeyType::ARROW_LEFT);
|
$this->moveCursor(KeyType::ArrowLeft);
|
||||||
$this->document->delete($this->cursor);
|
$this->document->delete($this->cursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
62
src/Row.php
62
src/Row.php
@ -197,7 +197,7 @@ class Row {
|
|||||||
*/
|
*/
|
||||||
public function highlight(): void
|
public function highlight(): void
|
||||||
{
|
{
|
||||||
$this->hl = array_fill(0, $this->rsize, Highlight::NORMAL);
|
$this->hl = array_fill(0, $this->rsize, Highlight::Normal);
|
||||||
|
|
||||||
if ($this->parent->fileType->name === 'PHP')
|
if ($this->parent->fileType->name === 'PHP')
|
||||||
{
|
{
|
||||||
@ -230,10 +230,10 @@ class Row {
|
|||||||
{
|
{
|
||||||
if ($inComment)
|
if ($inComment)
|
||||||
{
|
{
|
||||||
$this->hl[$i] = Highlight::ML_COMMENT;
|
$this->hl[$i] = Highlight::MultiLineComment;
|
||||||
if (substr($this->render, $i, $mceLen) === $mce)
|
if (substr($this->render, $i, $mceLen) === $mce)
|
||||||
{
|
{
|
||||||
array_replace_range($this->hl, $i, $mceLen, Highlight::ML_COMMENT);
|
array_replace_range($this->hl, $i, $mceLen, Highlight::MultiLineComment);
|
||||||
$i += $mceLen;
|
$i += $mceLen;
|
||||||
$inComment = FALSE;
|
$inComment = FALSE;
|
||||||
continue;
|
continue;
|
||||||
@ -245,7 +245,7 @@ class Row {
|
|||||||
|
|
||||||
if (substr($this->render, $i, $mcsLen) === $mcs)
|
if (substr($this->render, $i, $mcsLen) === $mcs)
|
||||||
{
|
{
|
||||||
array_replace_range($this->hl, $i, $mcsLen, Highlight::ML_COMMENT);
|
array_replace_range($this->hl, $i, $mcsLen, Highlight::MultiLineComment);
|
||||||
$i += $mcsLen;
|
$i += $mcsLen;
|
||||||
$inComment = TRUE;
|
$inComment = TRUE;
|
||||||
continue;
|
continue;
|
||||||
@ -287,7 +287,7 @@ class Row {
|
|||||||
protected function highlightNumber(int &$i, Syntax $opts): bool
|
protected function highlightNumber(int &$i, Syntax $opts): bool
|
||||||
{
|
{
|
||||||
$char = $this->render[$i];
|
$char = $this->render[$i];
|
||||||
if ($opts->numbers() && is_digit($char) && $this->hl[$i] === Highlight::NORMAL)
|
if ($opts->numbers() && is_digit($char) && $this->hl[$i] === Highlight::Normal)
|
||||||
{
|
{
|
||||||
if ($i > 0)
|
if ($i > 0)
|
||||||
{
|
{
|
||||||
@ -300,7 +300,7 @@ class Row {
|
|||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
$this->hl[$i] = Highlight::NUMBER;
|
$this->hl[$i] = Highlight::Number;
|
||||||
$i++;
|
$i++;
|
||||||
|
|
||||||
if ($i < strlen($this->render))
|
if ($i < strlen($this->render))
|
||||||
@ -326,11 +326,11 @@ class Row {
|
|||||||
*
|
*
|
||||||
* @param int $i
|
* @param int $i
|
||||||
* @param array $keywords
|
* @param array $keywords
|
||||||
* @param int $syntaxType
|
* @param Highlight $syntaxType
|
||||||
* @param bool $requireSeparator
|
* @param bool $requireSeparator
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function highlightWord(int &$i, array $keywords, int $syntaxType, bool $requireSeparator = true): bool
|
protected function highlightWord(int &$i, array $keywords, Highlight $syntaxType, bool $requireSeparator = true): bool
|
||||||
{
|
{
|
||||||
if ($i > 0 && $requireSeparator)
|
if ($i > 0 && $requireSeparator)
|
||||||
{
|
{
|
||||||
@ -365,12 +365,12 @@ class Row {
|
|||||||
*
|
*
|
||||||
* @param int $i
|
* @param int $i
|
||||||
* @param array $chars
|
* @param array $chars
|
||||||
* @param int $syntaxType
|
* @param Highlight $syntaxType
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function highlightChar(int &$i, array $chars, int $syntaxType): bool
|
protected function highlightChar(int &$i, array $chars, Highlight $syntaxType): bool
|
||||||
{
|
{
|
||||||
if ($this->hl[$i] !== Highlight::NORMAL)
|
if ($this->hl[$i] !== Highlight::Normal)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -397,7 +397,7 @@ class Row {
|
|||||||
*/
|
*/
|
||||||
protected function highlightPrimaryKeywords(int &$i, Syntax $opts): bool
|
protected function highlightPrimaryKeywords(int &$i, Syntax $opts): bool
|
||||||
{
|
{
|
||||||
return $this->highlightWord($i, $opts->keywords1, Highlight::KEYWORD1);
|
return $this->highlightWord($i, $opts->keywords1, Highlight::Keyword1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -409,7 +409,7 @@ class Row {
|
|||||||
*/
|
*/
|
||||||
protected function highlightSecondaryKeywords(int &$i, Syntax $opts): bool
|
protected function highlightSecondaryKeywords(int &$i, Syntax $opts): bool
|
||||||
{
|
{
|
||||||
return $this->highlightWord($i, $opts->keywords2, Highlight::KEYWORD2);
|
return $this->highlightWord($i, $opts->keywords2, Highlight::Keyword2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -421,7 +421,7 @@ class Row {
|
|||||||
*/
|
*/
|
||||||
protected function highlightOperators(int &$i, Syntax $opts): bool
|
protected function highlightOperators(int &$i, Syntax $opts): bool
|
||||||
{
|
{
|
||||||
return $this->highlightWord($i, $opts->operators, Highlight::OPERATOR, false);
|
return $this->highlightWord($i, $opts->operators, Highlight::Operator, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -441,7 +441,7 @@ class Row {
|
|||||||
return $this->highlightChar(
|
return $this->highlightChar(
|
||||||
$i,
|
$i,
|
||||||
['+', '-', '*', '/', '<', '^', '>', '%', '=', ':', ',', ';', '&', '~', '!', '|', '.'],
|
['+', '-', '*', '/', '<', '^', '>', '%', '=', ':', ',', ';', '&', '~', '!', '|', '.'],
|
||||||
Highlight::OPERATOR
|
Highlight::Operator
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -456,7 +456,7 @@ class Row {
|
|||||||
return $this->highlightChar(
|
return $this->highlightChar(
|
||||||
$i,
|
$i,
|
||||||
['{', '}', '[', ']', '(', ')'],
|
['{', '}', '[', ']', '(', ')'],
|
||||||
Highlight::DELIMITER
|
Highlight::Delimiter
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -489,7 +489,7 @@ class Row {
|
|||||||
$closingChar = $this->render[$closingIndex];
|
$closingChar = $this->render[$closingIndex];
|
||||||
if ($closingChar === "'")
|
if ($closingChar === "'")
|
||||||
{
|
{
|
||||||
array_replace_range($this->hl, $i, $closingIndex - $i + 1, Highlight::CHARACTER);
|
array_replace_range($this->hl, $i, $closingIndex - $i + 1, Highlight::Character);
|
||||||
$i = $closingIndex + 1;
|
$i = $closingIndex + 1;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -518,7 +518,7 @@ class Row {
|
|||||||
|
|
||||||
if ($scsLen > 0 && substr($this->render, $i, $scsLen) === $scs)
|
if ($scsLen > 0 && substr($this->render, $i, $scsLen) === $scs)
|
||||||
{
|
{
|
||||||
array_replace_range($this->hl, $i, $this->rsize - $i, Highlight::COMMENT);
|
array_replace_range($this->hl, $i, $this->rsize - $i, Highlight::Comment);
|
||||||
$i = $this->rsize;
|
$i = $this->rsize;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -547,18 +547,18 @@ class Row {
|
|||||||
if ($opts->strings() && ($char === '"' || $char === '\''))
|
if ($opts->strings() && ($char === '"' || $char === '\''))
|
||||||
{
|
{
|
||||||
$quote = $char;
|
$quote = $char;
|
||||||
$this->hl[$i] = Highlight::STRING;
|
$this->hl[$i] = Highlight::String;
|
||||||
$i++;
|
$i++;
|
||||||
|
|
||||||
while ($i < $this->rsize)
|
while ($i < $this->rsize)
|
||||||
{
|
{
|
||||||
$char = $this->render[$i];
|
$char = $this->render[$i];
|
||||||
$this->hl[$i] = Highlight::STRING;
|
$this->hl[$i] = Highlight::String;
|
||||||
|
|
||||||
// Check for escaped character
|
// Check for escaped character
|
||||||
if ($char === '\\' && $i+1 < $this->rsize)
|
if ($char === '\\' && $i+1 < $this->rsize)
|
||||||
{
|
{
|
||||||
$this->hl[$i + 1] = Highlight::STRING;
|
$this->hl[$i + 1] = Highlight::String;
|
||||||
$i += 2;
|
$i += 2;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -617,14 +617,14 @@ class Row {
|
|||||||
if ($commentEnd !== FALSE)
|
if ($commentEnd !== FALSE)
|
||||||
{
|
{
|
||||||
$inComment = FALSE;
|
$inComment = FALSE;
|
||||||
array_replace_range($this->hl, 0, $commentEnd + 2, Highlight::ML_COMMENT);
|
array_replace_range($this->hl, 0, $commentEnd + 2, Highlight::MultiLineComment);
|
||||||
$offset = $commentEnd;
|
$offset = $commentEnd;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, just set the whole row
|
// Otherwise, just set the whole row
|
||||||
$this->hl = array_fill(0, $this->rsize, Highlight::ML_COMMENT);
|
$this->hl = array_fill(0, $this->rsize, Highlight::MultiLineComment);
|
||||||
$this->hl[$offset] = Highlight::ML_COMMENT;
|
$this->hl[$offset] = Highlight::MultiLineComment;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -647,7 +647,7 @@ class Row {
|
|||||||
// Single line comments
|
// Single line comments
|
||||||
if (str_contains($char, '//') || str_contains($char, '#'))
|
if (str_contains($char, '//') || str_contains($char, '#'))
|
||||||
{
|
{
|
||||||
array_replace_range($this->hl, $charStart, $charLen, Highlight::COMMENT);
|
array_replace_range($this->hl, $charStart, $charLen, Highlight::Comment);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -662,13 +662,13 @@ class Row {
|
|||||||
if ($hasEnd)
|
if ($hasEnd)
|
||||||
{
|
{
|
||||||
$len = $end - $start + 2;
|
$len = $end - $start + 2;
|
||||||
array_replace_range($this->hl, $start, $len, Highlight::ML_COMMENT);
|
array_replace_range($this->hl, $start, $len, Highlight::MultiLineComment);
|
||||||
$inComment = FALSE;
|
$inComment = FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$inComment = TRUE;
|
$inComment = TRUE;
|
||||||
array_replace_range($this->hl, $start, $charLen - $offset, Highlight::ML_COMMENT);
|
array_replace_range($this->hl, $start, $charLen - $offset, Highlight::MultiLineComment);
|
||||||
$offset = $start + $charLen - $offset;
|
$offset = $start + $charLen - $offset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -684,16 +684,16 @@ class Row {
|
|||||||
|
|
||||||
$highlight = match(true) {
|
$highlight = match(true) {
|
||||||
// Matches a predefined PHP token
|
// Matches a predefined PHP token
|
||||||
$token['type'] !== T_RAW && $tokenHighlight !== Highlight::NORMAL
|
$token['type'] !== T_RAW && $tokenHighlight !== Highlight::Normal
|
||||||
=> $tokenHighlight,
|
=> $tokenHighlight,
|
||||||
|
|
||||||
// Matches a specific syntax character
|
// Matches a specific syntax character
|
||||||
$charHighlight !== Highlight::NORMAL => $charHighlight,
|
$charHighlight !== Highlight::Normal => $charHighlight,
|
||||||
|
|
||||||
default => Highlight::NORMAL,
|
default => Highlight::Normal,
|
||||||
};
|
};
|
||||||
|
|
||||||
if ($highlight !== Highlight::NORMAL)
|
if ($highlight !== Highlight::Normal)
|
||||||
{
|
{
|
||||||
array_replace_range($this->hl, $charStart, $charLen, $highlight);
|
array_replace_range($this->hl, $charStart, $charLen, $highlight);
|
||||||
$offset = $charEnd;
|
$offset = $charEnd;
|
||||||
|
@ -22,7 +22,7 @@ class Syntax {
|
|||||||
bool $hasCharType = false,
|
bool $hasCharType = false,
|
||||||
bool $highlightCharacters = false,
|
bool $highlightCharacters = false,
|
||||||
bool $hasCommonOperators = true,
|
bool $hasCommonOperators = true,
|
||||||
string $syntaxFamily = SyntaxFamily::C,
|
SyntaxFamily $syntaxFamily = SyntaxFamily::C,
|
||||||
): self
|
): self
|
||||||
{
|
{
|
||||||
return new self(
|
return new self(
|
||||||
@ -84,7 +84,7 @@ class Syntax {
|
|||||||
/** should we highlight common operators? */
|
/** should we highlight common operators? */
|
||||||
private bool $hasCommonOperators,
|
private bool $hasCommonOperators,
|
||||||
/** What kind of general syntax family does this file belong to? */
|
/** What kind of general syntax family does this file belong to? */
|
||||||
private string $syntaxFamily,
|
private SyntaxFamily $syntaxFamily,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function numbers(): bool
|
public function numbers(): bool
|
||||||
@ -124,7 +124,7 @@ class Syntax {
|
|||||||
return $this->hasCommonOperators;
|
return $this->hasCommonOperators;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function syntaxFamily(): string
|
public function syntaxFamily(): SyntaxFamily
|
||||||
{
|
{
|
||||||
return $this->syntaxFamily;
|
return $this->syntaxFamily;
|
||||||
}
|
}
|
||||||
|
@ -81,35 +81,35 @@ class Terminal {
|
|||||||
* Get the last key input from the terminal and convert to a
|
* Get the last key input from the terminal and convert to a
|
||||||
* more useful format
|
* more useful format
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string|KeyType
|
||||||
*/
|
*/
|
||||||
public static function readKey(): string
|
public static function readKey(): string|KeyType
|
||||||
{
|
{
|
||||||
$c = Terminal::read();
|
$c = Terminal::read();
|
||||||
|
|
||||||
return match($c)
|
return match($c)
|
||||||
{
|
{
|
||||||
// Unambiguous mappings
|
// Unambiguous mappings
|
||||||
RawKeyCode::ARROW_DOWN => KeyType::ARROW_DOWN,
|
RawKeyCode::ARROW_DOWN => KeyType::ArrowDown,
|
||||||
RawKeyCode::ARROW_LEFT => KeyType::ARROW_LEFT,
|
RawKeyCode::ARROW_LEFT => KeyType::ArrowLeft,
|
||||||
RawKeyCode::ARROW_RIGHT => KeyType::ARROW_RIGHT,
|
RawKeyCode::ARROW_RIGHT => KeyType::ArrowRight,
|
||||||
RawKeyCode::ARROW_UP => KeyType::ARROW_UP,
|
RawKeyCode::ARROW_UP => KeyType::ArrowUp,
|
||||||
RawKeyCode::DELETE => KeyType::DELETE,
|
RawKeyCode::DELETE => KeyType::Delete,
|
||||||
RawKeyCode::ENTER => KeyType::ENTER,
|
RawKeyCode::ENTER => KeyType::Enter,
|
||||||
RawKeyCode::PAGE_DOWN => KeyType::PAGE_DOWN,
|
RawKeyCode::PAGE_DOWN => KeyType::PageDown,
|
||||||
RawKeyCode::PAGE_UP => KeyType::PAGE_UP,
|
RawKeyCode::PAGE_UP => KeyType::PageUp,
|
||||||
|
|
||||||
// Backspace
|
// Backspace
|
||||||
RawKeyCode::CTRL('h'), RawKeyCode::BACKSPACE => KeyType::BACKSPACE,
|
RawKeyCode::CTRL('h'), RawKeyCode::BACKSPACE => KeyType::Backspace,
|
||||||
|
|
||||||
// Escape
|
// Escape
|
||||||
RawKeyCode::CTRL('l'), RawKeyCode::ESCAPE => KeyType::ESCAPE,
|
RawKeyCode::CTRL('l'), RawKeyCode::ESCAPE => KeyType::Escape,
|
||||||
|
|
||||||
// Home Key
|
// Home Key
|
||||||
"\eOH", "\e[7~", "\e[1~", ANSI::RESET_CURSOR => KeyType::HOME,
|
"\eOH", "\e[7~", "\e[1~", ANSI::RESET_CURSOR => KeyType::Home,
|
||||||
|
|
||||||
// End Key
|
// End Key
|
||||||
"\eOF", "\e[4~", "\e[8~", "\e[F" => KeyType::END,
|
"\eOF", "\e[4~", "\e[8~", "\e[F" => KeyType::End,
|
||||||
|
|
||||||
default => $c,
|
default => $c,
|
||||||
};
|
};
|
||||||
|
@ -8,25 +8,25 @@ use Aviat\Kilo\Enum\Highlight;
|
|||||||
/**
|
/**
|
||||||
* Configure syntax highlighting colors
|
* Configure syntax highlighting colors
|
||||||
*
|
*
|
||||||
* @param int $hl
|
* @param Highlight $hl
|
||||||
* @return int
|
* @return Color
|
||||||
*/
|
*/
|
||||||
function get_syntax_color(int $hl): int {
|
function get_syntax_color(Highlight $hl): Color {
|
||||||
return match ($hl)
|
return match ($hl)
|
||||||
{
|
{
|
||||||
Highlight::COMMENT => Color::FG_CYAN,
|
Highlight::Comment => Color::FG_CYAN,
|
||||||
Highlight::ML_COMMENT => Color::FG_BRIGHT_BLACK,
|
Highlight::MultiLineComment => Color::FG_BRIGHT_BLACK,
|
||||||
Highlight::KEYWORD1 => Color::FG_YELLOW,
|
Highlight::Keyword1 => Color::FG_YELLOW,
|
||||||
Highlight::KEYWORD2 => Color::FG_GREEN,
|
Highlight::Keyword2 => Color::FG_GREEN,
|
||||||
Highlight::STRING => Color::FG_MAGENTA,
|
Highlight::String => Color::FG_MAGENTA,
|
||||||
Highlight::CHARACTER => Color::FG_BRIGHT_MAGENTA,
|
Highlight::Character => Color::FG_BRIGHT_MAGENTA,
|
||||||
Highlight::NUMBER => Color::FG_BRIGHT_RED,
|
Highlight::Number => Color::FG_BRIGHT_RED,
|
||||||
Highlight::OPERATOR => Color::FG_BRIGHT_GREEN,
|
Highlight::Operator => Color::FG_BRIGHT_GREEN,
|
||||||
Highlight::VARIABLE => Color::FG_BRIGHT_CYAN,
|
Highlight::Variable => Color::FG_BRIGHT_CYAN,
|
||||||
Highlight::DELIMITER => Color::FG_BLUE,
|
Highlight::Delimiter => Color::FG_BLUE,
|
||||||
Highlight::INVALID => Color::BG_BRIGHT_RED,
|
Highlight::Invalid => Color::BG_BRIGHT_RED,
|
||||||
Highlight::MATCH => Color::INVERT,
|
Highlight::SearchMatch => Color::INVERT,
|
||||||
Highlight::IDENTIFIER => Color::FG_BRIGHT_WHITE,
|
Highlight::Identifier => Color::FG_BRIGHT_WHITE,
|
||||||
default => Color::FG_WHITE,
|
default => Color::FG_WHITE,
|
||||||
};
|
};
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user