Merge remote-tracking branch 'origin/master'
Some checks failed
Gitea - Tutorials/php-kilo/master There was a failure building this commit
Some checks failed
Gitea - Tutorials/php-kilo/master There was a failure building this commit
This commit is contained in:
commit
7acf38da9c
@ -14,37 +14,13 @@ use Aviat\Kilo\Enum\{
|
|||||||
// ! Terminal size
|
// ! Terminal size
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
|
||||||
* @TODO fix
|
|
||||||
* @codeCoverageIgnore
|
|
||||||
*/
|
|
||||||
function get_cursor_position()
|
|
||||||
{
|
|
||||||
write_stdout("\x1b[999C\x1b[999B");
|
|
||||||
write_stdout("\x1b[6n");
|
|
||||||
|
|
||||||
$rows = 0;
|
|
||||||
$cols = 0;
|
|
||||||
|
|
||||||
$buffer = read_stdout();
|
|
||||||
|
|
||||||
$res = sscanf($buffer, '\x1b[%d;%dR', $rows, $cols);
|
|
||||||
|
|
||||||
if ($res === -1 || $buffer[0] !== '\x1b' || $buffer[1] !== '[')
|
|
||||||
{
|
|
||||||
die('Failed to get screen size');
|
|
||||||
}
|
|
||||||
|
|
||||||
return [$rows, $cols];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the size of the current terminal window
|
* Get the size of the current terminal window
|
||||||
*
|
*
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function get_window_size()
|
function get_window_size(): array
|
||||||
{
|
{
|
||||||
$ffi = get_ffi();
|
$ffi = get_ffi();
|
||||||
|
|
||||||
@ -53,9 +29,10 @@ function get_window_size()
|
|||||||
|
|
||||||
if ($res === -1 || $ws->ws_col === 0)
|
if ($res === -1 || $ws->ws_col === 0)
|
||||||
{
|
{
|
||||||
// Return a default screen size until get_cursor_position function works
|
$rows = trim(shell_exec('tput lines'));
|
||||||
return [25, 80];
|
$cols = trim(shell_exec('tput cols'));
|
||||||
// return get_cursor_position();
|
|
||||||
|
return [(int)$rows, (int)$cols];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [$ws->ws_row, $ws->ws_col];
|
return [$ws->ws_row, $ws->ws_col];
|
||||||
@ -214,22 +191,6 @@ function write_stdout(string $str, int $len = NULL): int
|
|||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @codeCoverageIgnore
|
|
||||||
* @param int $len
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
function read_stdout(int $len = 128): string
|
|
||||||
{
|
|
||||||
$handle = fopen('php://stdout', 'rb');
|
|
||||||
$input = fread($handle, $len);
|
|
||||||
|
|
||||||
$input = rtrim($input);
|
|
||||||
fclose($handle);
|
|
||||||
|
|
||||||
return $input;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces a slice of an array with the same value
|
* Replaces a slice of an array with the same value
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user