Add basic line numbers
timw4mail/php-kilo/pipeline/head There was a failure building this commit Details

This commit is contained in:
Timothy Warren 2023-10-17 16:15:00 -04:00
parent 7554c69d63
commit 573f8c0cde
2 changed files with 23 additions and 5 deletions

View File

@ -13,6 +13,14 @@ use Aviat\Kilo\Type\TerminalSize;
* // Don't highlight this!
*/
class Editor {
/**
* @var bool Whether to render line numbers
*/
public bool $showLineNumbers = true;
/**
* @var int The size of the line number Gutter in characters
*/
public int $numberGutter = 5;
/**
* @var string The screen buffer
*/
@ -411,6 +419,11 @@ class Editor {
$len = $this->terminalSize->cols;
}
if ($this->showLineNumbers)
{
$this->outputBuffer .= sprintf("%-{$this->numberGutter}s", ($rowIdx+1));
}
$chars = substr($row->render, $this->offset->x, (int)$len);
$hl = array_slice($row->hl, $this->offset->x, (int)$len);
@ -544,10 +557,12 @@ class Editor {
$this->drawStatusBar();
$this->drawMessageBar();
$gutter = ($this->showLineNumbers) ? $this->numberGutter : 0;
// Specify the current cursor position
$this->outputBuffer .= ANSI::moveCursor(
$this->cursor->y - $this->offset->y,
$this->renderX - $this->offset->x
($this->renderX - $this->offset->x) + $gutter,
);
$this->outputBuffer .= ANSI::SHOW_CURSOR;

View File

@ -4,6 +4,9 @@ namespace Aviat\Kilo;
use Aviat\Kilo\Enum\SyntaxFamily;
/**
* A representation of the syntax of a programming language
*/
class Syntax {
// Tokens for PHP files
public array $tokens = [];
@ -46,10 +49,10 @@ class Syntax {
public static function default(): self
{
return self::new(
'No filetype', slcs:
'', mcs:
'', mce:
'',
'No filetype',
slcs: '',
mcs: '',
mce: '',
highlightNumbers: false,
highlightStrings: false,
hasCommonOperators: false,