Merge 1.x into master #1

Merged
sikofitt merged 14 commits from 1.x into master 2022-05-17 10:29:27 -07:00
7 changed files with 551 additions and 453 deletions

View File

@ -2,15 +2,16 @@
This simply uses the FFI extension to enable _getch and _ungetch in Windows and linux. This simply uses the FFI extension to enable _getch and _ungetch in Windows and linux.
[![pipeline status](https://repos.bgemi.net/sikofitt/getch/badges/1.x/pipeline.svg)](https://repos.bgemi.net/sikofitt/getch/-/commits/1.x) [![Pipeline status](https://code.bgemi.net/olive/PHP/getch/badges/1.x/pipeline.svg)](https://code.bgemi.net/olive/PHP/getch/-/commits/1.x)
[![coverage report](https://repos.bgemi.net/sikofitt/getch/badges/1.x/coverage.svg)](https://repos.bgemi.net/sikofitt/getch/-/commits/1.x) [![Coverage report](https://code.bgemi.net/olive/PHP/getch/badges/1.x/coverage.svg)](https://code.bgemi.net/olive/PHP/getch/-/commits/1.x)
[![Latest Release](https://code.bgemi.net/olive/PHP/getch/-/badges/release.svg)](https://code.bgemi.net/olive/PHP/getch/-/releases)
```shell script ```shell script
$ composer require sikofitt/getch:dev-master $ composer require olivebbs/getch
``` ```
```php ```php
use Sikofitt\Console\Getch; use Olive\Console\Getch;
$g = new Getch($linuxLibrary = null); // can also be a library that implements a function called _getch; $g = new Getch($linuxLibrary = null); // can also be a library that implements a function called _getch;
// by default uses the bundled Resources/libgetch.so // by default uses the bundled Resources/libgetch.so
// on windows uses the built in _getch function. // on windows uses the built in _getch function.
@ -45,7 +46,7 @@ Note that if you want to put a word into the STDIN stack, you need to do it in r
There are also helper functions called getch() and ungetch(); There are also helper functions called getch() and ungetch();
```php ```php
use function Sikofitt\Console\getch; use function Olive\Console\getch;
$ord = getch($linuxLibrary = null); $ord = getch($linuxLibrary = null);
print \chr($ord); print \chr($ord);

View File

@ -1,5 +1,5 @@
{ {
"name": "sikofitt/getch", "name": "olivebbs/getch",
"description": "Implements _getch and _ungetch for windows and linux using ffi", "description": "Implements _getch and _ungetch for windows and linux using ffi",
"type": "library", "type": "library",
"require": { "require": {
@ -8,12 +8,11 @@
}, },
"require-dev": { "require-dev": {
"friendsofphp/php-cs-fixer": "^2.18", "friendsofphp/php-cs-fixer": "^2.18",
"jetbrains/phpstorm-stubs": "dev-master",
"phpunit/phpunit": "^9.5" "phpunit/phpunit": "^9.5"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Sikofitt\\Console\\": "src/Console/" "Olive\\Console\\": "src/Console/"
}, },
"files": [ "files": [
"functions.php" "functions.php"
@ -21,7 +20,7 @@
}, },
"autoload-dev": { "autoload-dev": {
"psr-4": { "psr-4": {
"Sikofitt\\Tests\\Console\\": "tests/" "Olive\\Tests\\Console\\": "tests/"
} }
}, },
"license": "MPL-2.0", "license": "MPL-2.0",

967
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,7 @@ declare(strict_types=1);
* You can obtain one at https://mozilla.org/MPL/2.0/. * You can obtain one at https://mozilla.org/MPL/2.0/.
*/ */
use Sikofitt\Console\Getch; use Olive\Console\Getch;
if (!function_exists('getch')) { if (!function_exists('getch')) {
function getch(string $linuxLibrary = null): int function getch(string $linuxLibrary = null): int

View File

@ -12,7 +12,7 @@ declare(strict_types=1);
* You can obtain one at https://mozilla.org/MPL/2.0/. * You can obtain one at https://mozilla.org/MPL/2.0/.
*/ */
namespace Sikofitt\Console; namespace Olive\Console;
use FFI; use FFI;
use RuntimeException; use RuntimeException;
@ -72,13 +72,13 @@ final class Getch
if (null === self::$ffi) { if (null === self::$ffi) {
$osFamily = PHP_OS_FAMILY; $osFamily = PHP_OS_FAMILY;
if ('Windows' === $osFamily) { if ('Windows' === $osFamily) {
$declarations = self::DECLARATIONS . ' int _kbhit();'; $declarations = self::DECLARATIONS.' int _kbhit();';
self::$ffi = FFI::cdef($declarations, self::WINDOWS_LIBRARY); self::$ffi = FFI::cdef($declarations, self::WINDOWS_LIBRARY);
} elseif ('Linux' === $osFamily) { } elseif ('Linux' === $osFamily) {
if (!file_exists($linuxLibrary)) { if (!file_exists($linuxLibrary)) {
throw new RuntimeException(sprintf('Could not find library file %s.', $linuxLibrary)); throw new RuntimeException(sprintf('Could not find library file %s.', $linuxLibrary));
} }
$declarations = self::DECLARATIONS . ' int cinPeek();'; $declarations = self::DECLARATIONS.' int cinPeek();';
self::$ffi = FFI::cdef($declarations, $linuxLibrary); self::$ffi = FFI::cdef($declarations, $linuxLibrary);
} else { } else {
throw new RuntimeException(sprintf('Sorry, %s is not supported yet.', $osFamily)); throw new RuntimeException(sprintf('Sorry, %s is not supported yet.', $osFamily));
@ -92,10 +92,13 @@ final class Getch
if ($ffi->_kbhit()) { if ($ffi->_kbhit()) {
$result = $ffi->_getch(); $result = $ffi->_getch();
$ffi->_ungetch($result); $ffi->_ungetch($result);
return $result; return $result;
} }
return -1; return -1;
} }
return $ffi->cinPeek(); return $ffi->cinPeek();
} }

View File

@ -1,9 +1,9 @@
<?php <?php
namespace Sikofitt\Tests\Console\Getch; namespace Olive\Tests\Console\Getch;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Sikofitt\Console\Getch; use Olive\Console\Getch;
class GetchTest extends TestCase class GetchTest extends TestCase
{ {

View File

@ -1,9 +1,9 @@
<?php <?php
namespace Sikofitt\Tests\Console\Ungetch; namespace Olive\Tests\Console\Ungetch;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Sikofitt\Console\Getch; use Olive\Console\Getch;
class UngetchTest extends TestCase class UngetchTest extends TestCase
{ {