Make operator highlighting optional
timw4mail/php-kilo/pipeline/head This commit looks good Details

This commit is contained in:
Timothy Warren 2021-04-14 17:19:01 -04:00
parent d0817b62c4
commit e22bb0545d
3 changed files with 24 additions and 3 deletions

View File

@ -18,9 +18,15 @@ class FileType {
return match ($ext) { return match ($ext) {
'.sh', '.bash' => Syntax::new( '.sh', '.bash' => Syntax::new(
'Shell', 'Shell',
[
'case', 'do', 'done', 'elif', 'else', 'esac', 'fi', 'for', 'function', 'if', 'in',
'select', 'then', 'time', 'until', 'while', 'declare',
],
['set'],
slcs: '#', slcs: '#',
mcs: '', mcs: '',
mce: '', mce: '',
highlightNumbers: false,
), ),
'.php', 'kilo' => Syntax::new( '.php', 'kilo' => Syntax::new(
'PHP', 'PHP',
@ -49,6 +55,7 @@ class FileType {
'.css', '.less', '.sass', '.scss' => Syntax::new( '.css', '.less', '.sass', '.scss' => Syntax::new(
'CSS', 'CSS',
slcs: '', slcs: '',
hasCommonOperators: false,
), ),
'.go' => Syntax::new( '.go' => Syntax::new(
'Go', 'Go',

View File

@ -257,7 +257,7 @@ class Row {
|| $this->highlightString($i, $syntax) || $this->highlightString($i, $syntax)
|| $this->highlightOperators($i, $syntax) || $this->highlightOperators($i, $syntax)
|| $this->highlightCommonDelimeters($i) || $this->highlightCommonDelimeters($i)
|| $this->highlightCommonOperators($i) || $this->highlightCommonOperators($i, $syntax)
|| $this->highlightNumber($i, $syntax) || $this->highlightNumber($i, $syntax)
) { ) {
continue; continue;
@ -376,8 +376,13 @@ class Row {
return $this->highlightWord($i, $opts->operators, Highlight::OPERATOR); return $this->highlightWord($i, $opts->operators, Highlight::OPERATOR);
} }
protected function highlightCommonOperators(int &$i): bool protected function highlightCommonOperators(int &$i, Syntax $opts): bool
{ {
if ( ! $opts->commonOperators())
{
return false;
}
return $this->highlightChar( return $this->highlightChar(
$i, $i,
['+', '-', '*', '/', '<', '^', '>', '%', '=', ':', ',', ';', '&', '~'], ['+', '-', '*', '/', '<', '^', '>', '%', '=', ':', ',', ';', '&', '~'],

View File

@ -19,6 +19,7 @@ class Syntax {
bool $highlightComments = true, bool $highlightComments = true,
bool $hasCharType = false, bool $hasCharType = false,
bool $highlightCharacters = false, bool $highlightCharacters = false,
bool $hasCommonOperators = true,
): self ): self
{ {
return new self( return new self(
@ -34,12 +35,13 @@ class Syntax {
$highlightCharacters, $highlightCharacters,
$highlightStrings, $highlightStrings,
$highlightComments, $highlightComments,
$hasCommonOperators,
); );
} }
public static function default(): self public static function default(): self
{ {
return self::new('No filetype', slcs: '', mcs: '', mce: '', highlightNumbers: false, highlightStrings: false); return self::new('No filetype', slcs: '', mcs: '', mce: '', highlightNumbers: false, highlightStrings: false, hasCommonOperators: false);
} }
private function __construct( private function __construct(
@ -67,6 +69,8 @@ class Syntax {
private bool $highlightStrings, private bool $highlightStrings,
/** should we highlight comments? */ /** should we highlight comments? */
private bool $highlightComments, private bool $highlightComments,
/** should we highlight common operators? */
private bool $hasCommonOperators,
) {} ) {}
public function numbers(): bool public function numbers(): bool
@ -100,4 +104,9 @@ class Syntax {
{ {
return $this->highlightComments && strlen($this->singleLineCommentStart) !== 0; return $this->highlightComments && strlen($this->singleLineCommentStart) !== 0;
} }
public function commonOperators(): bool
{
return $this->hasCommonOperators;
}
} }