Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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("请继续选择[@全选,#结束,<回退,*清空]");
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

须修改语言包

}
return $r;
Expand Down Expand Up @@ -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));
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$stdin 资源未关闭


if(is_callable($processor)){
$content = call_user_func($processor,$content);
Expand Down