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"))
|
if (! function_exists ("exec"))
|
||||||
throw $this->ConsoleException ("No exec support in PHP");
|
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.
|
// 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
|
// Do not display anything, so we don't see the characters when the user is
|
||||||
// deleting.
|
// deleting.
|
||||||
// 'intr ^J' allow to redefine the interruption from Ctrl+C to Ctrl+J. It
|
// '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
|
// 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 ();
|
$this->updateTerminalSize ();
|
||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
@@ -107,7 +107,7 @@ class Console
|
|||||||
{
|
{
|
||||||
$this->termWidth = 80;
|
$this->termWidth = 80;
|
||||||
$this->termHeight = 25;
|
$this->termHeight = 25;
|
||||||
$termSize = exec ("stty size", $null, $rc);
|
$termSize = exec ("stty size 2>/dev/null", $null, $rc);
|
||||||
if ($rc === 0)
|
if ($rc === 0)
|
||||||
{
|
{
|
||||||
list ($termHeight, $termWidth) = explode (" ", $termSize);
|
list ($termHeight, $termWidth) = explode (" ", $termSize);
|
||||||
@@ -128,6 +128,7 @@ class Console
|
|||||||
public function __destruct ()
|
public function __destruct ()
|
||||||
// {{{
|
// {{{
|
||||||
{
|
{
|
||||||
|
if ($this->initSttyState !== "")
|
||||||
exec ("stty $this->initSttyState");
|
exec ("stty $this->initSttyState");
|
||||||
$this->colorReset ();
|
$this->colorReset ();
|
||||||
$this->textUnderline (false);
|
$this->textUnderline (false);
|
||||||
@@ -207,7 +208,7 @@ class Console
|
|||||||
$char = fgetc (STDIN);
|
$char = fgetc (STDIN);
|
||||||
$sequence .= $char;
|
$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.
|
// Start an ESC CSI sequence. Do not display it, just return it.
|
||||||
// The ESC squences are used to communicate the cursor keys, associated
|
// The ESC squences are used to communicate the cursor keys, associated
|
||||||
@@ -412,6 +413,13 @@ class Console
|
|||||||
$this->debug ("Autocompletion : end '$prompt.$string'");
|
$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)
|
elseif (ord ($char) === 3)
|
||||||
// Abort (Ctrl+C)
|
// Abort (Ctrl+C)
|
||||||
// {{{
|
// {{{
|
||||||
|
|||||||
Reference in New Issue
Block a user