From 59debe7f04d855fddb45458c0dcfa80dde89f223 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Tue, 10 Dec 2019 03:08:09 +0000 Subject: [PATCH] console : add getTermHeight getTermWidth methods git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5829 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- console.php | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/console.php b/console.php index fd1a3bc..930c595 100644 --- a/console.php +++ b/console.php @@ -69,6 +69,10 @@ class console */ private $termWidth; + /** Set the height of the terminal in chars + */ + private $termHeight; + /** Store the last cursor position in the last readline */ private $cursorPos = 1; @@ -98,6 +102,8 @@ class console public function updateTerminalSize () // {{{ { + $this->termWidth = 80; + $this->termHeight = 25; $termSize = exec ("stty size", $null, $rc); if ($rc === 0) { @@ -106,9 +112,11 @@ class console $this->termWidth = 80; else $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 * The function must get the partial text as first parameter, and must return * an array with the possibilities