Skip to content

Commit f98c611

Browse files
authored
Merge pull request #7 from php-school/add-clearing-methods
More clearing methods
2 parents a6ad7c4 + 61d9d24 commit f98c611

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

src/Terminal.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ public function clear() : void;
8181
*/
8282
public function clearLine() : void;
8383

84+
/**
85+
* Erase screen from the current line down to the bottom of the screen
86+
*/
87+
public function clearDown() : void;
88+
8489
/**
8590
* Clean the whole console without jumping the window
8691
*/

src/UnixTerminal.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,15 @@ public function clear() : void
193193

194194
public function clearLine() : void
195195
{
196-
$this->output->write(sprintf("\033[%dD\033[K", $this->getWidth()));
196+
$this->output->write("\033[2K");
197+
}
198+
199+
/**
200+
* Erase screen from the current line down to the bottom of the screen
201+
*/
202+
public function clearDown() : void
203+
{
204+
$this->output->write("\033[J");
197205
}
198206

199207
public function clean() : void

test/UnixTerminalTest.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,20 @@ public function testClearLine() : void
145145
$output = new BufferedOutput;
146146

147147
$terminal = new UnixTerminal($input, $output);
148-
$rf = new \ReflectionObject($terminal);
149-
$rp = $rf->getProperty('width');
150-
$rp->setAccessible(true);
151-
$rp->setValue($terminal, 23);
152-
153148
$terminal->clearLine();
154149

155-
self::assertEquals("\033[23D\033[K", $output->fetch());
150+
self::assertEquals("\033[2K", $output->fetch());
151+
}
152+
153+
public function testClearDown() : void
154+
{
155+
$input = $this->createMock(InputStream::class);
156+
$output = new BufferedOutput;
157+
158+
$terminal = new UnixTerminal($input, $output);
159+
$terminal->clearDown();
160+
161+
self::assertEquals("\033[J", $output->fetch());
156162
}
157163

158164
public function testClean() : void
@@ -171,7 +177,7 @@ public function testClean() : void
171177

172178
$terminal->clean();
173179

174-
self::assertEquals("\033[0;0H\033[23D\033[K\033[1;0H\033[23D\033[K\033[2;0H\033[23D\033[K", $output->fetch());
180+
self::assertEquals("\033[0;0H\033[2K\033[1;0H\033[2K\033[2;0H\033[2K", $output->fetch());
175181
}
176182

177183
public function testEnableCursor() : void

0 commit comments

Comments
 (0)