More cleanup
All checks were successful
timw4mail/php-kilo/pipeline/head This commit looks good

This commit is contained in:
Timothy Warren 2021-03-04 16:41:12 -05:00
parent b642ff5c59
commit 825966ac54
5 changed files with 33 additions and 16 deletions

View File

@ -5,4 +5,10 @@ parameters:
level: 8
paths:
- src
- ./kilo
- ./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

View File

@ -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

View File

@ -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;

View File

@ -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;
}

View File

@ -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);