Skip to content

Commit

Permalink
edit changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Jul 28, 2018
1 parent 3b8bf4d commit 066e412
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 254 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `phpunit-watcher` will be documented in this file

## 1.6.0 - 2018-07-28

- add autocomplete when filtering on file names

## 1.5.1 - 2018-05-15

- fix a bug around screen switching
Expand Down
190 changes: 0 additions & 190 deletions src/Screens/Completers/Completer.php

This file was deleted.

34 changes: 0 additions & 34 deletions src/Screens/Completers/FilenameCompleter.php

This file was deleted.

66 changes: 36 additions & 30 deletions src/Screens/FilterFileName.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Spatie\PhpUnitWatcher\Screens;

use Spatie\PhpUnitWatcher\Screens\Completers\FilenameCompleter;

class FilterFileName extends Screen
{
public function draw()
Expand All @@ -13,23 +11,16 @@ public function draw()
->write('Type a pattern and press Enter to only run tests in the giving path or file.')
->write('Press Enter with an empty pattern to execute all tests in all files.')
->emptyLine()
->comment('Start typing to filter by file name.')
->comment('Start typing to filter by a test name.')
->prompt('pattern > ');

return $this;
}

public function registerListeners()
{
$this->registerDataListener();

$this->registerAutocompleter();

return $this;
}
$readline = $this->terminal->getReadline();

protected function registerDataListener()
{
$this->terminal->on('data', function ($line) {
if ($line == '') {
$this->terminal->goBack();
Expand All @@ -47,36 +38,51 @@ protected function registerDataListener()

$this->terminal->displayScreen(new Phpunit($options));
});

$this->registerAutocompleter($readline);

return $this;
}

protected function registerAutocompleter()
protected function registerAutocompleter($readline)
{
$readline = $this->terminal->getReadline();
$readline->setAutocomplete(function ($word, $startOffset, $endOffset) use ($readline) {
$input = $readline->getInput();

$filenameAutocompleter = new FilenameCompleter($readline);
$paths = glob("$word*", GLOB_MARK);

$filenameAutocompleter->onSuggestions(function ($suggestions) {
$this->refreshScreenWithSuggestions($suggestions, 10);
});
if (empty($paths)) {
return;
}

$readline->setAutocomplete($filenameAutocompleter);
}
if (count($paths) > 1) {
$this->terminal->getStdio()->write(implode(' ', $paths) . "\n");
return;
}

protected function refreshScreenWithSuggestions($suggestions, $limit)
{
$firstSuggestions = array_slice($suggestions, 0 , $limit);
$path = $paths[0];

$this->terminal->refreshScreen();
$lineStart = mb_substr($input, 0, $startOffset);
$lineEnd = mb_substr($input, $endOffset);

$stdio = $this->terminal->getStdio();
$path = $this->sanitzeOffset($startOffset, $path, $input);

$stdio->write("\n" . implode("\n", $firstSuggestions) . "\n");
$newInput = $lineStart . $path . $lineEnd;

$count = count($suggestions) - $limit;
if ($count > 0) {
$stdio->write("(+$count others)\n");
}
$readline->setInput($newInput);

$stdio->write("\n");
$readline->moveCursorTo($startOffset + mb_strlen($path));
});
}

protected function sanitzeOffset($startOffset, $path, $input): string
{
if ($startOffset > 0 && mb_strlen($path) > 1 && mb_substr($path, -1) != DIRECTORY_SEPARATOR) {
$previousChar = mb_substr($input, $startOffset - 1, 1);
if ($previousChar === '"' || $previousChar === '\'') {
$path .= $previousChar;
}
}
return $path;
}
}

0 comments on commit 066e412

Please sign in to comment.