Skip to content

Commit 838d8d7

Browse files
authored
Merge pull request #4 from php-school/switch-buffer
Switch screen functionality
2 parents c3a87b9 + 78b2f18 commit 838d8d7

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/UnixTerminal.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,16 @@ public function moveCursorToColumn(int $column) : void
229229
$this->output->write(sprintf("\033[%dC", $column));
230230
}
231231

232+
public function showSecondaryScreen() : void
233+
{
234+
$this->output->write("\033[?47h");
235+
}
236+
237+
public function showPrimaryScreen() : void
238+
{
239+
$this->output->write("\033[?47l");
240+
}
241+
232242
/**
233243
* Read bytes from the input stream
234244
*/

test/UnixTerminalTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,28 @@ public function testMoveCursorToColumn() : void
229229
self::assertEquals("\033[10C", $output->fetch());
230230
}
231231

232+
public function testShowAlternateScreen() : void
233+
{
234+
$input = $this->createMock(InputStream::class);
235+
$output = new BufferedOutput;
236+
237+
$terminal = new UnixTerminal($input, $output);
238+
$terminal->showSecondaryScreen();
239+
240+
self::assertEquals("\033[?47h", $output->fetch());
241+
}
242+
243+
public function testShowMainScreen() : void
244+
{
245+
$input = $this->createMock(InputStream::class);
246+
$output = new BufferedOutput;
247+
248+
$terminal = new UnixTerminal($input, $output);
249+
$terminal->showPrimaryScreen();
250+
251+
self::assertEquals("\033[?47l", $output->fetch());
252+
}
253+
232254
public function testRead() : void
233255
{
234256
$tempStream = fopen('php://temp', 'r+');

0 commit comments

Comments
 (0)