Make some code more concise
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
4a5f074f28
commit
7554c69d63
@ -59,8 +59,10 @@ class Termios {
|
||||
|
||||
$termios = clone $instance->originalTermios;
|
||||
|
||||
// Turn on raw mode
|
||||
// Use the stdlib func to set raw mode parameters
|
||||
self::ffi()->cfmakeraw(FFI::addr($termios));
|
||||
|
||||
// Apply raw mode to the terminal
|
||||
$res = self::ffi()
|
||||
->tcsetattr(C::STDIN_FILENO, C::TCSANOW, FFI::addr($termios));
|
||||
|
||||
@ -102,14 +104,9 @@ class Termios {
|
||||
$ws = $ffi->new('struct winsize');
|
||||
if ($ws !== NULL)
|
||||
{
|
||||
if (self::getLibType() === LibType::MUSL)
|
||||
{
|
||||
$res = $ffi->tcgetwinsize(C::STDOUT_FILENO, FFI::addr($ws));
|
||||
}
|
||||
else
|
||||
{
|
||||
$res = $ffi->ioctl(C::STDOUT_FILENO, C::TIOCGWINSZ, FFI::addr($ws));
|
||||
}
|
||||
$res = (self::getLibType() === LibType::MUSL)
|
||||
? $ffi->tcgetwinsize(C::STDOUT_FILENO, FFI::addr($ws))
|
||||
: $ffi->ioctl(C::STDOUT_FILENO, C::TIOCGWINSZ, FFI::addr($ws));
|
||||
|
||||
if ($res === 0 && $ws->ws_col !== 0 && $ws->ws_row !== 0)
|
||||
{
|
||||
@ -126,9 +123,10 @@ class Termios {
|
||||
|
||||
if ($type === NULL)
|
||||
{
|
||||
if (file_exists("/usr/lib/libc.so"))
|
||||
$maybeLibc = "/usr/lib/libc.so";
|
||||
if (file_exists($maybeLibc))
|
||||
{
|
||||
$rawLibInfo = (string)shell_exec("/usr/lib/libc.so");
|
||||
$rawLibInfo = (string)shell_exec($maybeLibc);
|
||||
if (str_contains(strtolower($rawLibInfo), "musl"))
|
||||
{
|
||||
$type = LibType::MUSL;
|
||||
@ -145,10 +143,7 @@ class Termios {
|
||||
{
|
||||
static $instance;
|
||||
|
||||
if ($instance === NULL)
|
||||
{
|
||||
$instance = new self();
|
||||
}
|
||||
$instance ??= new self();
|
||||
|
||||
return $instance;
|
||||
}
|
||||
@ -167,12 +162,11 @@ class Termios {
|
||||
if (self::getLibType() === LibType::MUSL)
|
||||
{
|
||||
$ffi = FFI::load(__DIR__ . '/ffi_musl.h');
|
||||
return $ffi;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
$ffi = FFI::load(__DIR__ . '/ffi.h');
|
||||
}
|
||||
}
|
||||
|
||||
return $ffi;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user