Fix some issues with search function
timw4mail/php-kilo/pipeline/head There was a failure building this commit Details

This commit is contained in:
Timothy Warren 2023-10-10 15:21:24 -04:00
parent b8cb08c8a8
commit 4a5f074f28
2 changed files with 20 additions and 13 deletions

View File

@ -470,17 +470,14 @@ class Editor {
$welcomelen = $this->terminalSize->cols; $welcomelen = $this->terminalSize->cols;
} }
$padding = ($this->terminalSize->cols - $welcomelen) / 2; $padding = (int)floor(($this->terminalSize->cols - $welcomelen) / 2);
if ($padding > 0) if ($padding > 0)
{ {
$this->outputBuffer .= '~'; $this->outputBuffer .= '~';
$padding--; $padding--;
} }
for ($i = 0; $i < $padding; $i++)
{
$this->outputBuffer .= ' ';
}
$this->outputBuffer .= str_repeat(' ', $padding);
$this->outputBuffer .= substr($welcome, 0, $welcomelen); $this->outputBuffer .= substr($welcome, 0, $welcomelen);
} }
else else
@ -574,21 +571,21 @@ class Editor {
$c = Terminal::readKey(); $c = Terminal::readKey();
$isModifier = in_array($c, $modifiers, TRUE); $isModifier = in_array($c, $modifiers, TRUE);
if ($c === KeyType::Escape || ($c === RawKeyCode::ENTER && $buffer !== '')) if ($c === KeyType::Escape || ($c === KeyType::Enter && $buffer !== ''))
{ {
$this->setStatusMessage(''); $this->setStatusMessage('');
if ($callback !== NULL) if ($callback !== NULL)
{ {
$callback($buffer, $c); $callback($buffer, $c);
} }
return ($c === RawKeyCode::ENTER) ? $buffer : ''; return ($c === KeyType::Enter) ? $buffer : '';
} }
if ($c === KeyType::Delete || $c === KeyType::Backspace) if ($c === KeyType::Delete || $c === KeyType::Backspace)
{ {
$buffer = substr($buffer, 0, -1); $buffer = substr($buffer, 0, -1);
} }
else if (is_ascii($c) && ( ! (is_ctrl($c) || $isModifier))) else if (is_string($c) && is_ascii($c) && ( ! (is_ctrl($c) || $isModifier)))
{ {
$buffer .= $c; $buffer .= $c;
} }

View File

@ -10,17 +10,27 @@ use JsonSerializable;
*/ */
enum KeyType implements JsonSerializable { enum KeyType implements JsonSerializable {
use Traits\EnumTrait; use Traits\EnumTrait;
use Traits\ConstList;
// ------------------------------------------------------------------------
// Movement Keys
// ------------------------------------------------------------------------
case ArrowUp;
case ArrowDown; case ArrowDown;
case ArrowLeft; case ArrowLeft;
case ArrowRight; case ArrowRight;
case ArrowUp; case Home;
case End;
case PageUp;
case PageDown;
// ------------------------------------------------------------------------
// Editing Keys
// ------------------------------------------------------------------------
case Backspace; case Backspace;
case Delete; case Delete;
case End;
case Enter; case Enter;
// ------------------------------------------------------------------------
// Others
// ------------------------------------------------------------------------
case Escape; case Escape;
case Home;
case PageDown;
case PageUp;
} }