Skip to content

Commit

Permalink
Be more ANSI compilant.
Browse files Browse the repository at this point in the history
  • Loading branch information
onovy committed Mar 27, 2015
1 parent 668781d commit 5f64836
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ReadLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ReadLine {
const ESC_033 = 3; // \033
const ESC_033B = 5; // \033[
const ESC_033O = 6; // \033O
const ESC_033_TWOCHAR = 7; // \033??

private $input = '';
private $line = '';
Expand Down Expand Up @@ -252,12 +253,16 @@ private function parseInput() {
case 'O':
$this->state = self::ESC_033O;
break;
default:
if (ord($ch) >= 64 && ord($ch) <= 95) {
$this->state = self::ESC_033_TWOCHAR;
}
break;
}
break;
case self::ESC_033B:
switch ($ch) {
case 'A': // Up
$this->state = self::READ;
if ($this->historyPos === null) {
if ($this->line === '' && $this->historyNew !== null) {
$this->line = $this->historyNew;
Expand All @@ -276,7 +281,6 @@ private function parseInput() {
$this->pos = mb_strlen($this->line);
break;
case 'B': // Down
$this->state = self::READ;
if ($this->historyPos === null) {
$this->line = '';
} elseif ($this->historyPos < count($this->history) - 1) {
Expand All @@ -289,18 +293,19 @@ private function parseInput() {
$this->pos = mb_strlen($this->line);
break;
case 'C': // Right
$this->state = self::READ;
if (mb_strlen($this->line) > $this->pos) {
$this->pos++;
}
break;
case 'D': // Left
$this->state = self::READ;
if ($this->pos > 0) {
$this->pos--;
}
break;
}
if (ord($ch) >= 64 && ord($ch) <= 126) {
$this->state = self::READ;
}
break;
case self::ESC_033O:
switch ($ch) {
Expand All @@ -313,6 +318,9 @@ private function parseInput() {
}
$this->state = self::READ;
break;
case self::ESC_033_TWOCHAR:
$this->state = self::READ;
break;
}
}
$this->input = mb_substr($this->input, $i + 1);
Expand Down

0 comments on commit 5f64836

Please sign in to comment.