mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
CLISetup/OSCompatibility
- generally check for readline handler - only ignore \r for WIN
This commit is contained in:
@@ -176,7 +176,7 @@ class SpellList extends BaseType
|
|||||||
if ($mv < 0) // all stats
|
if ($mv < 0) // all stats
|
||||||
{
|
{
|
||||||
for ($iMod = ITEM_MOD_AGILITY; $iMod <= ITEM_MOD_STAMINA; $iMod++)
|
for ($iMod = ITEM_MOD_AGILITY; $iMod <= ITEM_MOD_STAMINA; $iMod++)
|
||||||
Util::arraySumByKey($stats, [iMod => $pts]);
|
Util::arraySumByKey($stats, [$iMod => $pts]);
|
||||||
}
|
}
|
||||||
else if ($mv == STAT_STRENGTH) // one stat
|
else if ($mv == STAT_STRENGTH) // one stat
|
||||||
Util::arraySumByKey($stats, [ITEM_MOD_STRENGTH => $pts]);
|
Util::arraySumByKey($stats, [ITEM_MOD_STRENGTH => $pts]);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ class CLISetup
|
|||||||
const LOG_INFO = 3;
|
const LOG_INFO = 3;
|
||||||
|
|
||||||
private static $win = true;
|
private static $win = true;
|
||||||
|
private static $hasReadline = false;
|
||||||
private static $logFile = '';
|
private static $logFile = '';
|
||||||
private static $logHandle = null;
|
private static $logHandle = null;
|
||||||
|
|
||||||
@@ -45,6 +46,7 @@ class CLISetup
|
|||||||
public static function init()
|
public static function init()
|
||||||
{
|
{
|
||||||
self::$win = substr(PHP_OS, 0, 3) == 'WIN';
|
self::$win = substr(PHP_OS, 0, 3) == 'WIN';
|
||||||
|
self::$hasReadline = function_exists('readline_callback_handler_install');
|
||||||
|
|
||||||
if ($_ = getopt('d', ['log::', 'locales::', 'mpqDataDir::', 'delete']))
|
if ($_ = getopt('d', ['log::', 'locales::', 'mpqDataDir::', 'delete']))
|
||||||
{
|
{
|
||||||
@@ -342,8 +344,8 @@ class CLISetup
|
|||||||
|
|
||||||
public static function readInput(&$fields, $singleChar = false)
|
public static function readInput(&$fields, $singleChar = false)
|
||||||
{
|
{
|
||||||
// prevent default output on *nix (readline doen't exist for WIN)
|
// prevent default output if able
|
||||||
if (!self::$win)
|
if (self::$hasReadline)
|
||||||
readline_callback_handler_install('', function() { });
|
readline_callback_handler_install('', function() { });
|
||||||
|
|
||||||
foreach ($fields as $name => $data)
|
foreach ($fields as $name => $data)
|
||||||
@@ -366,13 +368,16 @@ class CLISetup
|
|||||||
$char = stream_get_contents(STDIN, 1);
|
$char = stream_get_contents(STDIN, 1);
|
||||||
$keyId = ord($char);
|
$keyId = ord($char);
|
||||||
|
|
||||||
if ($keyId == self::CHR_TAB) // ignore this one
|
// ignore this one
|
||||||
|
if ($keyId == self::CHR_TAB)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ($keyId == self::CHR_CR) // also ignore this bastard!
|
// WIN sends \r\n as sequence, ignore one
|
||||||
|
if ($keyId == self::CHR_CR && self::$win)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ($keyId == self::CHR_ESC) // will not be send on WIN .. other ways of returning from setup? (besides ctrl + c)
|
// will not be send on WIN .. other ways of returning from setup? (besides ctrl + c)
|
||||||
|
if ($keyId == self::CHR_ESC)
|
||||||
{
|
{
|
||||||
echo chr(self::CHR_BELL);
|
echo chr(self::CHR_BELL);
|
||||||
return false;
|
return false;
|
||||||
@@ -393,10 +398,10 @@ class CLISetup
|
|||||||
else if (!$validPattern || preg_match($validPattern, $char))
|
else if (!$validPattern || preg_match($validPattern, $char))
|
||||||
{
|
{
|
||||||
$charBuff .= $char;
|
$charBuff .= $char;
|
||||||
if (!$isHidden && !self::$win) // see note above
|
if (!$isHidden && self::$hasReadline)
|
||||||
echo $char;
|
echo $char;
|
||||||
|
|
||||||
if ($singleChar && !self::$win) // see note above
|
if ($singleChar && self::$hasReadline)
|
||||||
{
|
{
|
||||||
$fields[$name] = $charBuff;
|
$fields[$name] = $charBuff;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user