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:
2018-06-13 14:26:01 +00:00
parent d708af89c6
commit 46a63f57f9

View File

@@ -13,6 +13,12 @@
* Ctrl+U, Ctrl+W
* To not allow the stop of the program by Ctrl+C, you can add
* 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;
}
// }}}