rodent/readline

此包已被弃用且不再维护。未建议替代包。

从 ridzhi/readline 分支的本地 readline 实现

v0.2.0 2017-03-28 09:15 UTC

This package is auto-updated.

Last update: 2020-05-09 11:15:20 UTC


README

本地 readline 实现

CompletionGif

安装

composer require ridzhi/readline

控制

  • 箭头左/右 - 光标左右移动
  • Home - 移动光标到行首
  • End - 移动光标到行尾
  • Ctrl+Delete - 清除行
  • Page up/down - 通过历史记录导航
  • Tab - 完成

下拉菜单

  • 箭头上/下 - 滚动上/下
  • Enter - 选择
  • Esc - 移除焦点/移动到行上下文

自动完成

为自动完成实现 CompleteInterface。您还可以使用 Parser 辅助工具,它返回 Info 对象。Info 对象具有用于编写各种复杂度的补全器的 API。有关更多详细信息,请参阅 example 目录。

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 [];
        }

    } 

}

对于最受欢迎的框架(Yii2、Symfony、Laravel),补全器将很快编写。

自定义处理程序

从当前光标位置到行尾删除行。

$readline = new \Ridzhi\Readline\Readline();
//Alt+d
$readline->bind("\033d", function (\Ridzhi\Readline\Line $line) {
    $current = $line->getCurrent();
    $line->clear();
    $line->insert($current);
});

关闭未闭合的括号。

$readline = new \Ridzhi\Readline\Readline();

$readline->bind("(", function (\Ridzhi\Readline\Line $line) {
    $line->insert("()");
    $line->cursorPrev();
});

主题

对于自定义样式,使用 ThemeInterface 实现。

// dark theme file

class DarkTheme implements Ridzhi\Readline\Dropdown\ThemeInterface
{
}

// console app file

// ThemeInterface implements
$readline = new \Ridzhi\Readline\Readline(new DarkTheme());

您还可以使用 CustomTheme 类,它提供了您设计的准备好的设置 API。