rodent / readline
This package is abandoned and no longer maintained.
No replacement package was suggested.
native readline implementation forked from ridzhi/readline
v0.2.0
2017-03-28 09:15 UTC
Requires
- php: >=7.0
- donatj/cli-toolkit: ^0.1.1
- hoa/console: 3.17.*
Requires (Dev)
- phpunit/phpunit: ^6.0
This package is auto-updated.
Last update: 2020-05-09 11:15:20 UTC
README
native readline implementation
Installation
composer require ridzhi/readline
Controls
Line
- Arrow left/right - move cursor left/right
- Home - move cursor to begin
- End - move cursor to end
- Ctrl+Delete - clear line
- Page up/down - navigate by history
- Tab - complete
Dropdown
- Arrow up/down - scroll up/down
- Enter - select
- Esc - remove focus/move to line context
Autocomplete
For autocompletion implement CompleteInterface
. Also you can use Parser
helper, which return Info
object. Info has API for writting completers practically any complexity. For more details see example
dir.
use \Ridzhi\Readline\Info\InfoInterface as IInfo; class TestCompleter implements \Ridzhi\Readline\CompleteInterface { public function complete(string $input): array { $info = \Ridzhi\Readline\Info\Parser::parse($input); switch ($info->getType()) { case IInfo::TYPE_ARG: // arg completion case IInfo::TYPE_OPTION_SHORT: // option completion case IInfo::TYPE_OPTION_LONG: // option completion case IInfo::TYPE_OPTION_VALUE: // option values completion default: return []; } } }
For most popular frameworks (Yii2, Symfony, Laravel) completers will be written at soon.
Custom handlers
Remove line from current cursor position to end.
$readline = new \Ridzhi\Readline\Readline(); //Alt+d $readline->bind("\033d", function (\Ridzhi\Readline\Line $line) { $current = $line->getCurrent(); $line->clear(); $line->insert($current); });
Close open parenthesis.
$readline = new \Ridzhi\Readline\Readline(); $readline->bind("(", function (\Ridzhi\Readline\Line $line) { $line->insert("()"); $line->cursorPrev(); });
Theming
For custom stylish use ThemeInterface
implementation.
// dark theme file class DarkTheme implements Ridzhi\Readline\Dropdown\ThemeInterface { } // console app file // ThemeInterface implements $readline = new \Ridzhi\Readline\Readline(new DarkTheme());
Also you can use CustomTheme
class, it has ready setters API for you design.