console : clear line correctely and call it in the rewriteLine method

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4245 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2018-06-13 14:33:05 +00:00
parent 778b3184b6
commit dacdff19ed

View File

@@ -565,21 +565,7 @@ private $usleep = 0;
{ {
if ($this->echoMode) if ($this->echoMode)
{ {
// Based on https://stackoverflow.com/a/27850902/158716 $this->clearLine ();
$oldLength = mb_strlen ($this->lineContent);
// 1. Calculate on which line the cursor is positionned
$cursorLine = 1 + floor ((-1+$this->cursorPos) / $this->termWidth);
$lastLines = 1 + floor ((1+$oldLength) / $this->termWidth);
for ($i = $cursorLine ; $i < $lastLines ; $i++)
echo "\033[1B";
// 3. Remove the lines from lastLines to line 1
if ($lastLines > 1)
{
for ($i = $lastLines ; $i > 1 ; $i--)
echo "\r\033[K\033[1A\r";
}
// 4. Clean the line 1
echo "\r\033[K";
$this->lineContent = $text; $this->lineContent = $text;
echo $this->lineContent; echo $this->lineContent;
$this->cursorPos = mb_strlen ($this->lineContent); $this->cursorPos = mb_strlen ($this->lineContent);
@@ -623,6 +609,19 @@ private $usleep = 0;
public function clearLine () public function clearLine ()
// {{{ // {{{
{ {
$oldLength = mb_strlen ($this->lineContent);
// 1. Calculate on which line the cursor is positionned
$cursorLine = 1 + floor ((-1+$this->cursorPos) / $this->termWidth);
$lastLines = 1 + floor ((1+$oldLength) / $this->termWidth);
for ($i = $cursorLine ; $i < $lastLines ; $i++)
echo "\033[1B";
// 3. Remove the lines from lastLines to line 1
if ($lastLines > 1)
{
for ($i = $lastLines ; $i > 1 ; $i--)
echo "\r\033[K\033[1A\r";
}
// 4. Clean the line 1
echo "\r\033[K"; echo "\r\033[K";
$this->lineContent = ""; $this->lineContent = "";
$this->cursorPos = 0; $this->cursorPos = 0;