php-kilo/src/functions.php

40 lines
732 B
PHP
Raw Normal View History

2019-10-10 12:28:46 -04:00
<?php declare(strict_types=1);
namespace Kilo;
use FFI;
// require_once 'constants.php';
function enableRawMode(): void
{
global $ffi;
global $original_termios;
// Populate the original terminal settings
$ffi->tcgetattr(STDIN_FILENO, FFI::addr($original_termios));
$termios = clone $original_termios;
$termios->c_lflag &= ~(_ECHO | ICANON);
// Turn on raw mode
$ffi->tcsetattr(STDIN_FILENO, TCSAFLUSH, FFI::addr($termios));
}
function disableRawMode(): void
{
global $ffi;
global $original_termios;
$ffi->tcsetattr(STDIN_FILENO, TCSAFLUSH, FFI::addr($original_termios));
}
function read_stdin() {
$handle = fopen('php://stdin', 'r');
$input = rtrim(fgets($handle, 128));
fclose($handle);
return $input;
}