From 4878986f240a1ce4c56bf9456511a97b3ae9892c Mon Sep 17 00:00:00 2001 From: "kaixing.wang" Date: Sun, 3 Apr 2022 18:31:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=A4=9A=E9=80=89=E9=A1=B9?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A=E4=B9=89=E9=80=89=E9=A1=B9?= =?UTF-8?q?=E9=94=AE=E5=90=8D=EF=BC=8C=E9=94=AE=E5=90=8D=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=95=B0=E5=AD=97=E5=8F=8A=E8=8B=B1=E6=96=87=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E3=80=82=20=E6=96=B0=E5=A2=9E=E5=A4=9A=E9=80=89=E9=A1=B9@?= =?UTF-8?q?=E7=AC=A6=E5=8F=B7=E5=85=A8=E9=80=89=E5=8A=9F=E8=83=BD=E3=80=82?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9Windows=20PHP7.1=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E4=B8=8B=EF=BC=8C=E6=94=AF=E6=8C=81=E4=B8=AD=E6=96=87=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: kaixing.wang --- Cli.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Cli.php b/Cli.php index 9d5b1d8..2f24519 100644 --- a/Cli.php +++ b/Cli.php @@ -171,7 +171,7 @@ static function select($arr,$colQty=1,$msg='',$mul=false){ $msg = trim($msg)===''?self::_l('请选择'):$msg; while (true){ $tmpRes = self::stdin($msg.":\t",function($v) use ($arr,$mul){ - return (is_numeric($v) && isset($arr[$v])) || ($mul && in_array($v,['#','<','*'])); + return (preg_match("~[0-9a-ZA-Z]+~i",$v) && isset($arr[$v])) || ($mul && in_array($v,['#','<','*','@'])); },function ($v){return trim($v);}); if(!$mul){ @@ -183,13 +183,16 @@ static function select($arr,$colQty=1,$msg='',$mul=false){ array_pop($r); } elseif ($tmpRes === '*') { $r = []; - } else { + }elseif ($tmpRes === '@') { + $r = array_keys($arr); + break; + } else { $r[] = $tmpRes; $r = array_unique($r); } echo "\033[1A\033[K"; self::stdout(self::_l('当前已选择').':[' . implode(',', $r) . ']', 'comment'); - $msg = self::_l("请继续选择[#结束,<回退,*清空]"); + $msg = self::_l("请继续选择[@全选,#结束,<回退,*清空]"); } } return $r; @@ -223,9 +226,14 @@ static function stdin($msg='',$validator=false,$processor = false,$limitLen=1000 self::stdout($msg . ':'); } } - $stdin=fopen('php://stdin','r'); - $content=trim(fgets($stdin,$limitLen)); - fclose($stdin); + if(PHP_OS=='WINNT' && version_compare(PHP_VERSION,'7.1.0', '>')){ + sapi_windows_cp_set(936); + $content=trim(fgets(STDIN)); + $content=@iconv("GBK","UTF-8//IGNORE",$content); + sapi_windows_cp_set(65001); + }else{ + $content=trim(fgets(STDIN)); + } if(is_callable($processor)){ $content = call_user_func($processor,$content);