console : add getTermHeight getTermWidth methods

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5829 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2019-12-10 03:08:09 +00:00
parent f1b4c48eb0
commit 59debe7f04

View File

@@ -69,6 +69,10 @@ class console
*/ */
private $termWidth; private $termWidth;
/** Set the height of the terminal in chars
*/
private $termHeight;
/** Store the last cursor position in the last readline /** Store the last cursor position in the last readline
*/ */
private $cursorPos = 1; private $cursorPos = 1;
@@ -98,6 +102,8 @@ class console
public function updateTerminalSize () public function updateTerminalSize ()
// {{{ // {{{
{ {
$this->termWidth = 80;
$this->termHeight = 25;
$termSize = exec ("stty size", $null, $rc); $termSize = exec ("stty size", $null, $rc);
if ($rc === 0) if ($rc === 0)
{ {
@@ -106,9 +112,11 @@ class console
$this->termWidth = 80; $this->termWidth = 80;
else else
$this->termWidth = intval ($termWidth); $this->termWidth = intval ($termWidth);
if (is_null ($termHeight) || is_bool ($termHeight))
$this->termHeight = 25;
else
$this->termHeight = intval ($termHeight);
} }
else
$this->termWidth = 80;
} }
// }}} // }}}
@@ -734,6 +742,24 @@ class console
} }
// }}} // }}}
/** Get the terminal Height
*/
public function getTermHeight ()
// {{{
{
return $this->termHeight;
}
// }}}
/** Get the terminal Width
*/
public function getTermWidth ()
// {{{
{
return $this->termWidth;
}
// }}}
/** Call a specific function when a completion key is pressed /** Call a specific function when a completion key is pressed
* The function must get the partial text as first parameter, and must return * The function must get the partial text as first parameter, and must return
* an array with the possibilities * an array with the possibilities