1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Component\Console; |
4
|
|
|
|
5
|
|
|
use App\Component\Console\Dimensions; |
6
|
|
|
use App\Component\Console\Process; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Console terminal is a terminal for console. |
10
|
|
|
* |
11
|
|
|
* @todo A lot of stuff |
12
|
|
|
*/ |
13
|
|
|
class Terminal |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
const TTY_DIM_COMMAND_0 = "bash -c 'stty size'"; |
17
|
|
|
const TTY_DIM_COMMAND_1 = "bash -c 'stty -a | grep rows'"; |
18
|
|
|
const _S = ' '; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* terminal dimensions |
22
|
|
|
* |
23
|
|
|
* @var Dimensions |
24
|
|
|
*/ |
25
|
|
|
protected $dimensions; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* terminal processor |
29
|
|
|
* |
30
|
|
|
* @var Process |
31
|
|
|
*/ |
32
|
|
|
protected $processor; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* instanciate |
36
|
|
|
*/ |
37
|
4 |
|
public function __construct() |
38
|
|
|
{ |
39
|
4 |
|
$this->processor = new Process(); |
40
|
4 |
|
$this->setDimensions(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* setDimensions |
45
|
|
|
* |
46
|
|
|
* @return void |
47
|
|
|
*/ |
48
|
1 |
|
protected function setDimensions(): Terminal |
49
|
|
|
{ |
50
|
1 |
|
$this->dimensions = new Dimensions(); |
51
|
1 |
|
$this->dimensions->set(0, 0); |
52
|
1 |
|
if (!$this->isWindows()) { |
53
|
1 |
|
$matcher = [0, 0, 0]; |
54
|
1 |
|
$ttyDims = $this->processor->setCommand(self::TTY_DIM_COMMAND_0)->run(); |
55
|
1 |
|
if ($this->processor->isError()) { |
56
|
1 |
|
return $this; |
57
|
|
|
} |
58
|
|
|
//$ttyDims = Process::readFromProcess(self::TTY_DIM_COMMAND_0); |
59
|
|
|
//echo $ttyDims;die;*/ |
60
|
|
|
//var_dump($ttyDims); |
61
|
|
|
if (!empty($ttyDims)) { |
62
|
|
|
$matcher = explode(self::_S, self::_S . $ttyDims); |
63
|
|
|
} else { |
64
|
|
|
$ttyDims = Process::readFromProcess(self::TTY_DIM_COMMAND_1); |
|
|
|
|
65
|
|
|
$ttyDims = 'speed 38400 baud; rows 96; columns 126; line = 0;'; |
66
|
|
|
//var_dump($ttyDims); |
67
|
|
|
if (preg_match('/(\d+)+;.\w{7}.(\d+)+;/', $ttyDims, $matches)) { |
68
|
|
|
$matcher = $matches; |
69
|
|
|
} elseif (preg_match('/;(\d+).\w{4};.(\d+)/i', $ttyDims, $matches)) { |
70
|
|
|
$matcher = $matches; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
//var_dump($matcher, $ttyDims); |
74
|
|
|
$this->dimensions->set((int) $matcher[2], (int) $matcher[1]); |
75
|
|
|
} |
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* returns terminal dimensions |
81
|
|
|
* |
82
|
|
|
* @return Dimensions |
83
|
|
|
*/ |
84
|
1 |
|
protected function getDimensions(): Dimensions |
85
|
|
|
{ |
86
|
1 |
|
return $this->dimensions; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* return true if microsoft platform |
91
|
|
|
* |
92
|
|
|
* @return boolean |
93
|
|
|
*/ |
94
|
1 |
|
protected function isWindows(): bool |
95
|
|
|
{ |
96
|
1 |
|
return (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.