作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Term::Shell包来实现 CLI 工具。这个包提供了一个 API:comp_CMD
。
只要用户按下 TAB 键,就会调用此函数。我的要求是:
shell> 堆栈
TAB
超过
`shell>堆栈TAB
流样本垃圾
但默认的 comp_CMD
只提供一组 TAB 选项,例如
shell> 堆栈
TAB
超过
`shell>堆栈TAB
over under
### 问题就在这里
我不想在此处over under,而是获取flow sample junk。
最佳答案
使用 comp_*
风格的处理程序,只能将完成的单词与最后一个未完成的单词进行匹配。然而,幸运的是,您可以通过重写 catch_comp 函数来获得所需的结果,如下所示;它让一个匹配整个命令行:
my %completion_tree = (
stack => { under => [],
over => [qw(flow sample junk)] }
);
sub catch_comp {
my $o = shift;
my ($cmd, $word, $line, $start) = @_;
my $completed = substr $line, 0, $start;
$completed =~ s/^\s*//;
my $tree = \%completion_tree;
foreach (split m'\s+', $completed) {
last if ref($tree) ne 'HASH';
$tree = $tree->{$_};
}
my @completions;
$_ = ref($tree);
@completions = @$tree if /ARRAY/;
@completions = keys %$tree if /HASH/;
@completions = ($tree)if /SCALAR/;
return $o->completions($word, [@completions]);
}
关于perl - 如何在 Perl 的 Term::Shell 中自定义制表符补全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1177227/
补: Rest 风格请求处理的的内容补充(1) Rest风格请求:注意事项和细节 客户端是PostMan 可以直接发送Put,delete等方式请求,可不设置Filter 如果哟啊
我是一名优秀的程序员,十分优秀!