1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of graze/console-diff-renderer. |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2017 Nature Delivered Ltd. <https://www.graze.com> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @license https://github.com/graze/console-diff-renderer/blob/master/LICENSE.md |
11
|
|
|
* @link https://github.com/graze/console-diff-renderer |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Graze\DiffRenderer\Terminal; |
15
|
|
|
|
16
|
|
|
use Symfony\Component\Console\Terminal as SymfonyTerminal; |
17
|
|
|
|
18
|
|
|
class Terminal implements TerminalInterface |
19
|
|
|
{ |
20
|
|
|
/** @var CursorInterface */ |
21
|
|
|
protected $cursor; |
22
|
|
|
/** @var int */ |
23
|
|
|
private $width = self::DEFAULT_WIDTH; |
24
|
|
|
/** @var int */ |
25
|
|
|
private $height = self::DEFAULT_HEIGHT; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Terminal will provide cursor and dimension information to the outputter |
29
|
|
|
* |
30
|
|
|
* @param CursorInterface|null $cursor |
31
|
|
|
* @param SymfonyTerminal $terminal |
32
|
|
|
*/ |
33
|
|
|
public function __construct(CursorInterface $cursor = null, SymfonyTerminal $terminal = null) |
34
|
|
|
{ |
35
|
|
|
$this->cursor = $cursor ?: new ANSI(); |
36
|
|
|
$terminal = $terminal ?: new SymfonyTerminal(); |
37
|
|
|
$this->width = $terminal->getWidth(); |
38
|
|
|
$this->height = $terminal->getHeight(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return int |
43
|
|
|
*/ |
44
|
|
|
public function getWidth() |
45
|
|
|
{ |
46
|
|
|
return $this->width; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return int |
51
|
|
|
*/ |
52
|
|
|
public function getHeight() |
53
|
|
|
{ |
54
|
|
|
return $this->height; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Move the cursor to y,x |
59
|
|
|
* |
60
|
|
|
* @param int $line |
61
|
|
|
* @param int $column |
62
|
|
|
* |
63
|
|
|
* @return string |
64
|
|
|
*/ |
65
|
|
|
public function move($line, $column) |
66
|
|
|
{ |
67
|
|
|
return $this->cursor->move($line, $column); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Move up n Lines |
72
|
|
|
* |
73
|
|
|
* @param int $lines |
74
|
|
|
* |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
|
|
public function moveUp($lines) |
78
|
|
|
{ |
79
|
|
|
return $this->cursor->moveUp($lines); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Move down n Lines |
84
|
|
|
* |
85
|
|
|
* @param int $lines |
86
|
|
|
* |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
public function moveDown($lines) |
90
|
|
|
{ |
91
|
|
|
return $this->cursor->moveDown($lines); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Move left n Columns |
96
|
|
|
* |
97
|
|
|
* @param int $columns |
98
|
|
|
* |
99
|
|
|
* @return string |
100
|
|
|
*/ |
101
|
|
|
public function moveLeft($columns) |
102
|
|
|
{ |
103
|
|
|
return $this->cursor->moveLeft($columns); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Move right n Columns |
108
|
|
|
* |
109
|
|
|
* @param int $columns |
110
|
|
|
* |
111
|
|
|
* @return string |
112
|
|
|
*/ |
113
|
|
|
public function moveRight($columns) |
114
|
|
|
{ |
115
|
|
|
return $this->cursor->moveRight($columns); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Erase to the end of the line |
120
|
|
|
* |
121
|
|
|
* @return string |
122
|
|
|
*/ |
123
|
|
|
public function eraseToEnd() |
124
|
|
|
{ |
125
|
|
|
return $this->cursor->eraseToEnd(); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Erase to the start of the line |
130
|
|
|
* |
131
|
|
|
* @return string |
132
|
|
|
*/ |
133
|
|
|
public function eraseToStart() |
134
|
|
|
{ |
135
|
|
|
return $this->cursor->eraseToStart(); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Erase Down |
140
|
|
|
* |
141
|
|
|
* @return string |
142
|
|
|
*/ |
143
|
|
|
public function eraseDown() |
144
|
|
|
{ |
145
|
|
|
return $this->cursor->eraseDown(); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Erase Up |
150
|
|
|
* |
151
|
|
|
* @return string |
152
|
|
|
*/ |
153
|
|
|
public function eraseUp() |
154
|
|
|
{ |
155
|
|
|
return $this->cursor->eraseUp(); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Erase entire screen |
160
|
|
|
* |
161
|
|
|
* @return string |
162
|
|
|
*/ |
163
|
|
|
public function eraseScreen() |
164
|
|
|
{ |
165
|
|
|
return $this->cursor->eraseScreen(); |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|