Console : manage if Console is called from a pipe (without tty available)
This commit is contained in:
@@ -89,13 +89,13 @@ class Console
|
||||
{
|
||||
if (! function_exists ("exec"))
|
||||
throw $this->ConsoleException ("No exec support in PHP");
|
||||
$this->initSttyState = exec ("stty -g");
|
||||
$this->initSttyState = exec ("stty -g 2>/dev/null");
|
||||
// Set the terminal to return the value each time a key is pressed.
|
||||
// Do not display anything, so we don't see the characters when the user is
|
||||
// deleting.
|
||||
// 'intr ^J' allow to redefine the interruption from Ctrl+C to Ctrl+J. It
|
||||
// allow to manage the Ctrl+C key to clean the entry
|
||||
exec ("stty -echo -icanon min 1 time 0");
|
||||
exec ("stty -echo -icanon min 1 time 0 2>/dev/null");
|
||||
$this->updateTerminalSize ();
|
||||
}
|
||||
// }}}
|
||||
@@ -107,7 +107,7 @@ class Console
|
||||
{
|
||||
$this->termWidth = 80;
|
||||
$this->termHeight = 25;
|
||||
$termSize = exec ("stty size", $null, $rc);
|
||||
$termSize = exec ("stty size 2>/dev/null", $null, $rc);
|
||||
if ($rc === 0)
|
||||
{
|
||||
list ($termHeight, $termWidth) = explode (" ", $termSize);
|
||||
@@ -128,7 +128,8 @@ class Console
|
||||
public function __destruct ()
|
||||
// {{{
|
||||
{
|
||||
exec ("stty $this->initSttyState");
|
||||
if ($this->initSttyState !== "")
|
||||
exec ("stty $this->initSttyState");
|
||||
$this->colorReset ();
|
||||
$this->textUnderline (false);
|
||||
$this->textBold (false);
|
||||
@@ -207,7 +208,7 @@ class Console
|
||||
$char = fgetc (STDIN);
|
||||
$sequence .= $char;
|
||||
}
|
||||
elseif (ord ($char2) === 91)
|
||||
elseif (ord ($char2) === 91 || ord($char2) === 93)
|
||||
{
|
||||
// Start an ESC CSI sequence. Do not display it, just return it.
|
||||
// The ESC squences are used to communicate the cursor keys, associated
|
||||
@@ -412,6 +413,13 @@ class Console
|
||||
$this->debug ("Autocompletion : end '$prompt.$string'");
|
||||
}
|
||||
// }}}
|
||||
elseif (ord ($char) === 0)
|
||||
// End of file
|
||||
{
|
||||
$this->debug("Empty File entry : ".ord($char));
|
||||
$string = chr(0);
|
||||
break;
|
||||
}
|
||||
elseif (ord ($char) === 3)
|
||||
// Abort (Ctrl+C)
|
||||
// {{{
|
||||
|
||||
Reference in New Issue
Block a user