console : clear line correctely with Ctrl+C
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4243 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
14
console.php
14
console.php
@@ -12,7 +12,13 @@
|
||||
* Allow the user to use arrow keys and the shortcuts Ctrl+arrow, Ctrl+L,
|
||||
* Ctrl+U, Ctrl+W
|
||||
* To not allow the stop of the program by Ctrl+C, you can add
|
||||
* exec ("stty intr ^J");
|
||||
* exec ("stty intr ^J");
|
||||
* To update the window size when the terminal is resized, use after console
|
||||
* instanciation :
|
||||
* declare(ticks = 1);
|
||||
* pcntl_signal (SIGWINCH, function () use ($console) {
|
||||
* $console->updateTerminalSize ();
|
||||
* });
|
||||
*/
|
||||
class console
|
||||
{
|
||||
@@ -135,6 +141,7 @@ private $usleep = 0;
|
||||
public function echo ($message)
|
||||
// {{{
|
||||
{
|
||||
$this->debug ("'$message'");
|
||||
echo $message;
|
||||
$this->lineContent .= $message;
|
||||
}
|
||||
@@ -340,7 +347,7 @@ private $usleep = 0;
|
||||
{
|
||||
$this->clearLine ();
|
||||
$this->lineContent = "";
|
||||
$this->echo ($prompt."\n");
|
||||
echo "\r$prompt\n";
|
||||
return "";
|
||||
}
|
||||
// }}}
|
||||
@@ -617,8 +624,9 @@ private $usleep = 0;
|
||||
public function clearLine ()
|
||||
// {{{
|
||||
{
|
||||
echo "\r".str_repeat (" ", mb_strlen ($this->lineContent))."\r";
|
||||
echo "\r\033[K";
|
||||
$this->lineContent = "";
|
||||
$this->cursorPos = 0;
|
||||
}
|
||||
// }}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user