Skip to content

Commit bdca268

Browse files
committed
some update
1 parent 9c7db43 commit bdca268

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

src/Utils/CliUtil.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414
*/
1515
final class CliUtil
1616
{
17+
/**
18+
* get bash is available
19+
* @return bool
20+
*/
21+
public static function bashIsAvailable()
22+
{
23+
// $checkCmd = "/usr/bin/env bash -c 'echo OK'";
24+
// $shell = 'echo $0';
25+
$checkCmd = "bash -c 'echo OK'";
26+
27+
return self::runCommand($checkCmd, false) === 'OK';
28+
}
1729

1830
/**
1931
* @return string

src/Utils/Helper.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -393,21 +393,14 @@ public static function getScreenSize($refresh = false)
393393
return $size;
394394
}
395395

396-
if (self::isOnWindows()) {
397-
$output = [];
398-
exec('mode con', $output);
399-
400-
if (isset($output[1]) && strpos($output[1], 'CON') !== false) {
401-
return ($size = [
402-
(int)preg_replace('~\D~', '', $output[3]),
403-
(int)preg_replace('~\D~', '', $output[4])
404-
]);
405-
}
406-
} else {
396+
if (CliUtil::bashIsAvailable()) {
407397
// try stty if available
408398
$stty = [];
409-
if (exec('stty -a 2>&1', $stty) && preg_match('/rows\s+(\d+);\s*columns\s+(\d+);/mi', implode(' ', $stty),
410-
$matches)) {
399+
400+
if (
401+
exec('stty -a 2>&1', $stty) &&
402+
preg_match('/rows\s+(\d+);\s*columns\s+(\d+);/mi', implode(' ', $stty), $matches)
403+
) {
411404
return ($size = [$matches[2], $matches[1]]);
412405
}
413406

@@ -422,6 +415,18 @@ public static function getScreenSize($refresh = false)
422415
}
423416
}
424417

418+
if (self::isOnWindows()) {
419+
$output = [];
420+
exec('mode con', $output);
421+
422+
if (isset($output[1]) && strpos($output[1], 'CON') !== false) {
423+
return ($size = [
424+
(int)preg_replace('~\D~', '', $output[3]),
425+
(int)preg_replace('~\D~', '', $output[4])
426+
]);
427+
}
428+
}
429+
425430
return ($size = false);
426431
}
427432

src/Utils/Interact.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,10 +428,9 @@ public static function promptSilent(string $prompt = 'Enter Password:')
428428

429429
// $checkCmd = "/usr/bin/env bash -c 'echo OK'";
430430
// $shell = 'echo $0';
431-
$checkCmd = "bash -c 'echo OK'";
432431

433432
// linux, unix, git-bash
434-
if (CliUtil::runCommand($checkCmd, false) === 'OK') {
433+
if (CliUtil::bashIsAvailable()) {
435434
// COMMAND: bash -c 'read -p "Enter Password:" -s user_input && echo $user_input'
436435
$command = sprintf('bash -c "read -p \'%s\' -s user_input && echo $user_input"', $prompt);
437436
$password = CliUtil::runCommand($command, false);

0 commit comments

Comments
 (0)