Skip to content

Commit

Permalink
New methods: Console::showCursor() and hideCursor()
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Aug 21, 2018
1 parent 84f1bc8 commit 57f6780
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,32 @@ public function restoreCursorPosition() : void
$this->writeSequence('[u');
}

/**
* Shows the cursor.
*
* If run outside a terminal, this method throws an exception.
*
* @return void
*/
public function showCursor() : void
{
$this->checkTerminal(__FUNCTION__);
$this->writeSequence('[?25h');
}

/**
* Hides the cursor.
*
* If run outside a terminal, this method throws an exception.
*
* @return void
*/
public function hideCursor() : void
{
$this->checkTerminal(__FUNCTION__);
$this->writeSequence('[?25l');
}

/**
* Erases from the current cursor position to the end of the current line.
*
Expand Down
9 changes: 9 additions & 0 deletions tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,13 @@
$console->eraseDown();
$console->restoreCursorPosition();

echo 'Showing/hiding cursor... ';
for ($i = 0; $i < 10; $i++) {
$console->hideCursor();
usleep(100000);
$console->showCursor();
usleep(100000);
}
echo "\n";

echo "End of tests.\n";

0 comments on commit 57f6780

Please sign in to comment.