This commit is contained in:
parent
b642ff5c59
commit
825966ac54
@ -6,3 +6,9 @@ parameters:
|
||||
paths:
|
||||
- src
|
||||
- ./kilo
|
||||
ignoreErrors:
|
||||
- '#Call to an undefined method FFI::[a-zA-Z0-9_]+\(\)#'
|
||||
- '#Access to an undefined property FFI\\CData#'
|
||||
- '#Match arm comparison between \*NEVER\*#'
|
||||
universalObjectCratesClasses:
|
||||
- FFI
|
@ -451,7 +451,7 @@ class Editor {
|
||||
if ($match !== FALSE)
|
||||
{
|
||||
$lastMatch = $current;
|
||||
$this->cursorY = $current;
|
||||
$this->cursorY = (int)$current;
|
||||
$this->cursorX = $this->rowRxToCx($row, $match);
|
||||
$this->rowOffset = $this->numRows;
|
||||
|
||||
@ -692,7 +692,7 @@ class Editor {
|
||||
|
||||
$this->outputBuffer .= ANSI::SHOW_CURSOR;
|
||||
|
||||
echo $this->outputBuffer;
|
||||
write_stdout($this->outputBuffer, strlen($this->outputBuffer));
|
||||
}
|
||||
|
||||
public function setStatusMessage(string $fmt, mixed ...$args): void
|
||||
|
@ -59,10 +59,8 @@ class Termios {
|
||||
register_shutdown_function([static::class, 'disableRawMode']);
|
||||
|
||||
$termios = clone $instance->originalTermios;
|
||||
// $termios->c_iflag &= ~(C::BRKINT | C::ICRNL | C::INPCK | C::ISTRIP | C::IXON);
|
||||
// $termios->c_oflag &= ~(C::OPOST);
|
||||
$termios->c_iflag = 0;
|
||||
$termios->c_oflag = 0;
|
||||
$termios->c_iflag &= ~(C::BRKINT | C::ICRNL | C::INPCK | C::ISTRIP | C::IXON);
|
||||
$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;
|
||||
|
@ -21,6 +21,7 @@ class PHP8 extends PhpToken {
|
||||
*/
|
||||
public static function getTokens(string $code): array
|
||||
{
|
||||
// Make the lines/tokens 1-indexed
|
||||
$lines = explode("\n", $code);
|
||||
array_unshift($lines, '');
|
||||
unset($lines[0]);
|
||||
@ -81,7 +82,6 @@ class PHP8 extends PhpToken {
|
||||
if (str_starts_with($char, "\n") && trim($char) === '')
|
||||
{
|
||||
$this->tokens[$currentLine][] = $current;
|
||||
// $this->lineNum++;
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -38,10 +38,13 @@ function get_window_size(): array
|
||||
// First, try to get the answer from ioctl
|
||||
$ffi = get_ffi();
|
||||
$ws = $ffi->new('struct winsize');
|
||||
$res = $ffi->ioctl(C::STDOUT_FILENO, C::TIOCGWINSZ, FFI::addr($ws));
|
||||
if ($res === 0 && $ws->ws_col !== 0 && $ws->ws_row !== 0)
|
||||
if ($ws !== NULL)
|
||||
{
|
||||
return [$ws->ws_row, $ws->ws_col];
|
||||
$res = $ffi->ioctl(C::STDOUT_FILENO, C::TIOCGWINSZ, FFI::addr($ws));
|
||||
if ($res === 0 && $ws->ws_col !== 0 && $ws->ws_row !== 0)
|
||||
{
|
||||
return [$ws->ws_row, $ws->ws_col];
|
||||
}
|
||||
}
|
||||
|
||||
// Try using tput
|
||||
@ -138,8 +141,8 @@ function is_space(string $char): bool
|
||||
KeyCode::NEWLINE,
|
||||
KeyCode::SPACE,
|
||||
KeyCode::TAB,
|
||||
KeyCode::VERTICAL_TAB
|
||||
=> true,
|
||||
KeyCode::VERTICAL_TAB => true,
|
||||
|
||||
default => false,
|
||||
};
|
||||
}
|
||||
@ -193,10 +196,15 @@ function is_separator(string $char): bool
|
||||
function read_stdin(int $len = 128): string
|
||||
{
|
||||
$handle = fopen('php://stdin', 'rb');
|
||||
if ($handle === false)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$input = fread($handle, $len);
|
||||
fclose($handle);
|
||||
|
||||
return $input;
|
||||
return (is_string($input)) ? $input : '';
|
||||
}
|
||||
|
||||
/**
|
||||
@ -205,11 +213,16 @@ function read_stdin(int $len = 128): string
|
||||
* @codeCoverageIgnore
|
||||
* @param string $str
|
||||
* @param int|NULL $len
|
||||
* @return int
|
||||
* @return int|false
|
||||
*/
|
||||
function write_stdout(string $str, int $len = NULL): int
|
||||
function write_stdout(string $str, int $len = NULL): int|false
|
||||
{
|
||||
$handle = fopen('php://stdout', 'ab');
|
||||
if ($handle === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$res = (is_int($len))
|
||||
? fwrite($handle, $str, $len)
|
||||
: fwrite($handle, $str);
|
||||
|
Loading…
Reference in New Issue
Block a user