Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

Commit

Permalink
Print character only if printable.
Browse files Browse the repository at this point in the history
When a character is not printable, the readline did still print it. In
some cases, it could create weird bug (see [1] or [2]). Since we have the
`Hoa\Ustring::isCharPrintable`, we can check whether a character is
printable or not. Consequently, here is the new logic:

  * We read a character,
  * The buffer receives this character,
  * If there is no mapping for this character and if it is not
    printable, then we do not print it. We do nothing with it.

So, if we would like to support a control character that is not
printable, we must associate a mapping to this character (like we do for
`Ctrl-A` for instance).

[1]: #16
[2]: #17
  • Loading branch information
Hywan committed Jul 27, 2015
1 parent e46582a commit e8b8517
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Readline/Readline.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

use Hoa\Console;
use Hoa\Core;
use Hoa\Ustring;

/**
* Class \Hoa\Console\Readline.
Expand Down Expand Up @@ -249,6 +250,8 @@ public function _readLine($char)

if (isset($this->_mapping[$char])) {
$this->_buffer = $this->_mapping[$char];
} elseif (false === Ustring::isCharPrintable($char)) {
return static::STATE_CONTINUE | static::STATE_NO_ECHO;
}

if ($this->getLineLength() == $this->getLineCurrent()) {
Expand Down

0 comments on commit e8b8517

Please sign in to comment.