Skip to content

Commit b044b34

Browse files
committed
More clearing methods
1 parent a6ad7c4 commit b044b34

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

src/Terminal.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ public function clear() : void;
8080
* Clear the current cursors line
8181
*/
8282
public function clearLine() : void;
83+
84+
/**
85+
* Erase the entire current line
86+
*/
87+
public function clearEntireLine() : void;
88+
89+
/**
90+
* Erase screen from the current line down to the bottom of the screen
91+
*/
92+
public function clearDown() : void;
8393

8494
/**
8595
* Clean the whole console without jumping the window

src/UnixTerminal.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,22 @@ public function clearLine() : void
196196
$this->output->write(sprintf("\033[%dD\033[K", $this->getWidth()));
197197
}
198198

199+
/**
200+
* Erase the entire current line
201+
*/
202+
public function clearEntireLine() : void
203+
{
204+
$this->output->write("\033[2K");
205+
}
206+
207+
/**
208+
* Erase screen from the current line down to the bottom of the screen
209+
*/
210+
public function clearDown() : void
211+
{
212+
$this->output->write("\033[J");
213+
}
214+
199215
public function clean() : void
200216
{
201217
foreach (range(0, $this->getHeight()) as $rowNum) {

test/UnixTerminalTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,28 @@ public function testClearLine() : void
155155
self::assertEquals("\033[23D\033[K", $output->fetch());
156156
}
157157

158+
public function testClearEntireLine() : void
159+
{
160+
$input = $this->createMock(InputStream::class);
161+
$output = new BufferedOutput;
162+
163+
$terminal = new UnixTerminal($input, $output);
164+
$terminal->clearEntireLine();
165+
166+
self::assertEquals("\033[2K", $output->fetch());
167+
}
168+
169+
public function testClearDown() : void
170+
{
171+
$input = $this->createMock(InputStream::class);
172+
$output = new BufferedOutput;
173+
174+
$terminal = new UnixTerminal($input, $output);
175+
$terminal->clearDown();
176+
177+
self::assertEquals("\033[J", $output->fetch());
178+
}
179+
158180
public function testClean() : void
159181
{
160182
$input = $this->createMock(InputStream::class);

0 commit comments

Comments
 (0)