Improve terminal size checking
Some checks failed
timw4mail/php-kilo/master There was a failure building this commit
Some checks failed
timw4mail/php-kilo/master There was a failure building this commit
This commit is contained in:
parent
83c5c51b58
commit
24baca3cb8
@ -36,7 +36,7 @@ class Editor {
|
|||||||
protected string $statusMsg = '';
|
protected string $statusMsg = '';
|
||||||
protected int $statusMsgTime;
|
protected int $statusMsgTime;
|
||||||
|
|
||||||
public ?Syntax $syntax;
|
public ?Syntax $syntax = NULL;
|
||||||
|
|
||||||
// Tokens for highlighting PHP
|
// Tokens for highlighting PHP
|
||||||
public array $tokens = [];
|
public array $tokens = [];
|
||||||
|
@ -18,7 +18,7 @@ use Aviat\Kilo\Enum\{
|
|||||||
*/
|
*/
|
||||||
function has_tput(): bool
|
function has_tput(): bool
|
||||||
{
|
{
|
||||||
return shell_exec('type tput') === 0;
|
return (int)shell_exec('type tput') === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -33,26 +33,29 @@ function has_tput(): bool
|
|||||||
*/
|
*/
|
||||||
function get_window_size(): array
|
function get_window_size(): array
|
||||||
{
|
{
|
||||||
|
// First, try to get the answer from ioctl
|
||||||
$ffi = get_ffi();
|
$ffi = get_ffi();
|
||||||
|
|
||||||
$ws = $ffi->new('struct winsize');
|
$ws = $ffi->new('struct winsize');
|
||||||
$res = $ffi->ioctl(C::STDOUT_FILENO, C::TIOCGWINSZ, FFI::addr($ws));
|
$res = $ffi->ioctl(C::STDOUT_FILENO, C::TIOCGWINSZ, FFI::addr($ws));
|
||||||
|
if ($res === 0 && $ws->ws_col !== 0 && $ws->ws_row !== 0)
|
||||||
if ($res === -1 || $ws->ws_col === 0)
|
|
||||||
{
|
{
|
||||||
if (has_tput())
|
return [$ws->ws_row, $ws->ws_col];
|
||||||
{
|
|
||||||
$rows = trim(shell_exec('tput lines'));
|
|
||||||
$cols = trim(shell_exec('tput cols'));
|
|
||||||
|
|
||||||
return [(int)$rows, (int)$cols];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Worst-case, return an arbitrary 'standard' size
|
|
||||||
return [80, 25];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return [$ws->ws_row, $ws->ws_col];
|
// Try using tput
|
||||||
|
if (has_tput())
|
||||||
|
{
|
||||||
|
$rows = (int)trim(shell_exec('tput lines'));
|
||||||
|
$cols = (int)trim(shell_exec('tput cols'));
|
||||||
|
|
||||||
|
if ($rows > 0 && $cols > 0)
|
||||||
|
{
|
||||||
|
return [$rows, $cols];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Worst-case, return an arbitrary 'standard' size
|
||||||
|
return [25, 80];
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user