Minor code tweaks, consolidate non-autoloaded code into one file
Some checks failed
timw4mail/php-kilo/pipeline/head There was a failure building this commit
Some checks failed
timw4mail/php-kilo/pipeline/head There was a failure building this commit
This commit is contained in:
parent
dd4b707d12
commit
fd478b697f
@ -1,9 +1,7 @@
|
||||
{
|
||||
"autoload": {
|
||||
"files": [
|
||||
"src/constants.php",
|
||||
"src/config.php",
|
||||
"src/functions.php"
|
||||
"src/Kilo.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Aviat\\Kilo\\": "src/"
|
||||
|
454
composer.lock
generated
454
composer.lock
generated
File diff suppressed because it is too large
Load Diff
21
kilo
21
kilo
@ -3,13 +3,11 @@
|
||||
|
||||
namespace Aviat\Kilo;
|
||||
|
||||
require_once __DIR__ . '/src/constants.php';
|
||||
require_once __DIR__ . '/src/config.php';
|
||||
require_once __DIR__ . '/src/functions.php';
|
||||
require_once __DIR__ . '/src/Kilo.php';
|
||||
|
||||
// Remove the composer install requirement by
|
||||
// Remove the composer install requirement by
|
||||
// manually handling autoloading
|
||||
spl_autoload_register(function (string $class) {
|
||||
spl_autoload_register(static function (string $class): void {
|
||||
$nsParts = explode('\\', $class);
|
||||
array_shift($nsParts);
|
||||
array_shift($nsParts);
|
||||
@ -20,20 +18,17 @@ spl_autoload_register(function (string $class) {
|
||||
if (file_exists($file))
|
||||
{
|
||||
require_once($file);
|
||||
return true;
|
||||
return;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
});
|
||||
|
||||
|
||||
// Log notices/errors/warnings to file
|
||||
set_error_handler(static function (
|
||||
$errno,
|
||||
$errstr,
|
||||
$errfile,
|
||||
$errline
|
||||
int $errno,
|
||||
string $errstr,
|
||||
string $errfile,
|
||||
int $errline,
|
||||
) {
|
||||
$msg = print_r([
|
||||
'code' => error_code_name($errno),
|
||||
|
@ -695,7 +695,7 @@ class Editor {
|
||||
$y--;
|
||||
$x = $row->size - 1;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case KeyType::ArrowRight:
|
||||
if ($x < $row->size)
|
||||
@ -707,40 +707,40 @@ class Editor {
|
||||
$y++;
|
||||
$x = 0;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case KeyType::ArrowUp:
|
||||
if ($y !== 0)
|
||||
{
|
||||
$y--;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case KeyType::ArrowDown:
|
||||
if ($y < $this->document->numRows)
|
||||
{
|
||||
$y++;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case KeyType::PageUp:
|
||||
$y = saturating_sub($y, $this->terminalSize->rows);
|
||||
break;
|
||||
break;
|
||||
|
||||
case KeyType::PageDown:
|
||||
$y = saturating_add($y, $this->terminalSize->rows, $this->document->numRows);
|
||||
break;
|
||||
break;
|
||||
|
||||
case KeyType::Home:
|
||||
$x = 0;
|
||||
break;
|
||||
break;
|
||||
|
||||
case KeyType::End:
|
||||
if ($y < $this->document->numRows)
|
||||
{
|
||||
$x = $row->size;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
default:
|
||||
// Do nothing
|
||||
|
@ -2,7 +2,51 @@
|
||||
|
||||
namespace Aviat\Kilo;
|
||||
|
||||
use Aviat\Kilo\Enum\{Color, Highlight, RawKeyCode};
|
||||
use Aviat\Kilo\Enum\Color;
|
||||
use Aviat\Kilo\Enum\Color256;
|
||||
use Aviat\Kilo\Enum\Highlight;
|
||||
use Aviat\Kilo\Enum\RawKeyCode;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// ! App Constants
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
const KILO_VERSION = '0.3.0';
|
||||
const KILO_TAB_STOP = 4;
|
||||
const KILO_QUIT_TIMES = 3;
|
||||
|
||||
const NO_MATCH = -1;
|
||||
const T_RAW = -1;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// ! App Config
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Configure syntax highlighting colors
|
||||
*
|
||||
* @param Highlight $hl
|
||||
* @return Color | Color256 | int
|
||||
*/
|
||||
function get_syntax_color(Highlight $hl): Color | Color256 | int {
|
||||
return match ($hl)
|
||||
{
|
||||
Highlight::Comment => Color::FG_CYAN,
|
||||
Highlight::MultiLineComment => Color::FG_BRIGHT_BLACK,
|
||||
Highlight::Keyword1 => Color::FG_YELLOW,
|
||||
Highlight::Keyword2 => Color::FG_GREEN,
|
||||
Highlight::String => Color::FG_MAGENTA,
|
||||
Highlight::Character => Color::FG_BRIGHT_MAGENTA,
|
||||
Highlight::Number => Color::FG_BRIGHT_RED,
|
||||
Highlight::Operator => Color::FG_BRIGHT_GREEN,
|
||||
Highlight::Variable => Color::FG_BRIGHT_CYAN,
|
||||
Highlight::Delimiter => Color::FG_BLUE,
|
||||
Highlight::Invalid => Color::BG_BRIGHT_RED,
|
||||
Highlight::SearchMatch => Color::INVERT,
|
||||
Highlight::Identifier => Color::FG_BRIGHT_WHITE,
|
||||
default => Color::FG_WHITE,
|
||||
};
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ! C function/macro equivalents
|
@ -58,7 +58,7 @@ class Termios {
|
||||
|
||||
$termios = clone $instance->originalTermios;
|
||||
$termios->c_iflag &= ~(C::BRKINT | C::ICRNL | C::INPCK | C::ISTRIP | C::IXON);
|
||||
$termios->c_oflag = 0; // &= ~(C::OPOST);
|
||||
$termios->c_oflag &= ~(C::OPOST);
|
||||
$termios->c_cflag |= (C::CS8);
|
||||
$termios->c_lflag &= ~( C::ECHO | C::ICANON | C::IEXTEN | C::ISIG );
|
||||
$termios->c_cc[C::VMIN] = 0;
|
||||
@ -95,7 +95,6 @@ class Termios {
|
||||
/**
|
||||
* Get the size of the current terminal window
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return array|null
|
||||
*/
|
||||
public static function getWindowSize(): ?array
|
||||
|
@ -1,33 +0,0 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Aviat\Kilo;
|
||||
|
||||
use Aviat\Kilo\Enum\Color;
|
||||
use Aviat\Kilo\Enum\Color256;
|
||||
use Aviat\Kilo\Enum\Highlight;
|
||||
|
||||
/**
|
||||
* Configure syntax highlighting colors
|
||||
*
|
||||
* @param Highlight $hl
|
||||
* @return Color | Color256 | int
|
||||
*/
|
||||
function get_syntax_color(Highlight $hl): Color | Color256 | int {
|
||||
return match ($hl)
|
||||
{
|
||||
Highlight::Comment => Color::FG_CYAN,
|
||||
Highlight::MultiLineComment => Color::FG_BRIGHT_BLACK,
|
||||
Highlight::Keyword1 => Color::FG_YELLOW,
|
||||
Highlight::Keyword2 => Color::FG_GREEN,
|
||||
Highlight::String => Color::FG_MAGENTA,
|
||||
Highlight::Character => Color::FG_BRIGHT_MAGENTA,
|
||||
Highlight::Number => Color::FG_BRIGHT_RED,
|
||||
Highlight::Operator => Color::FG_BRIGHT_GREEN,
|
||||
Highlight::Variable => Color::FG_BRIGHT_CYAN,
|
||||
Highlight::Delimiter => Color::FG_BLUE,
|
||||
Highlight::Invalid => Color::BG_BRIGHT_RED,
|
||||
Highlight::SearchMatch => Color::INVERT,
|
||||
Highlight::Identifier => Color::FG_BRIGHT_WHITE,
|
||||
default => Color::FG_WHITE,
|
||||
};
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Aviat\Kilo;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// ! App Constants
|
||||
// -----------------------------------------------------------------------------
|
||||
const KILO_VERSION = '0.3.0';
|
||||
const KILO_TAB_STOP = 4;
|
||||
const KILO_QUIT_TIMES = 3;
|
||||
|
||||
const NO_MATCH = -1;
|
||||
const T_RAW = -1;
|
Loading…
Reference in New Issue
Block a user