Skip to content

Commit

Permalink
Don't store text into readline history if it's same as the last one e…
Browse files Browse the repository at this point in the history
…ntered.
  • Loading branch information
smuuf committed Jul 10, 2019
1 parent ab0b985 commit 7d3dc4f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/repl/ReadlineDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,23 @@

class Readline extends \Smuuf\Primi\StrictObject implements IReadlineDriver {

private $lastItem = '';

public function readline(string $prompt): string {
return readline($prompt);
}

public function readlineAddHistory(string $item): void {

// Avoid storing the same value again, if it's the same value
// as before.
if ($this->lastItem === $item) {
return;
}

readline_add_history($item);
$this->lastItem = $item;

}

public function readlineReadHistory(string $path): void {
Expand Down

0 comments on commit 7d3dc4f

Please sign in to comment.