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

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

View File

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