Skip to content

Commit b6d780e

Browse files
committed
feat help命令支持分组搜;输入支持过滤;支持隐藏命令样例提示框
1 parent 53ae1ed commit b6d780e

File tree

4 files changed

+78
-29
lines changed

4 files changed

+78
-29
lines changed

README.md

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,23 @@ body, html, #app {
111111

112112
terminal标签支持属性参数表
113113

114-
| 参数 | 说明 | 类型 | 默认值 |
115-
|---------------------|-----------------------------------------|----------|-------------------|
116-
| name | Terminal实例名称,同一页面的name必须唯一,Api中使用也需用到此值 | string | terminal |
117-
| context | 初始化上下文文本 | string | /vue-web-terminal |
118-
| title | header中显示的标题 | string | vue-web-terminal |
119-
| show-header | 是否显示header | boolean | true |
120-
| init-log | Terminal初始化时显示的日志,是由[消息对象](#消息对象)组成的数组 | array ||
121-
| init-log-delay | 初始化显示日志时每条日志之间的间隔时间,单位毫秒 ms | number | 150 |
122-
| show-log-time | 当消息**type**`normal`时是否显示时间 | boolean | true |
123-
| warnLogByteLimit | 当前Terminal日志占用内存大小超出此限制会发出警告,单位`byte` | number | 1024 * 1024 * 10 |
124-
| warnLogCountLimit | 当前Terminal日志条数超出此限制会发出警告 | number | 200 |
125-
| warnLogLimitEnable | 是否开启日志限制警告 | boolean | true |
126-
| auto-help | 是否打开命令行自动搜索提示功能 | boolean | true |
127-
| help-style | help自定义样式 | string | |
128-
| command-store | 自定义的命令库,见[命令定义格式](#命令定义) | array | [内置命令行](#内置命令行) |
129-
| command-store-sort | 命令行库排序 | function | function(a,b) {} |
114+
| 参数 | 说明 | 类型 | 默认值 |
115+
|--------------------|-----------------------------------------|----------|----------------------------------------------------|
116+
| name | Terminal实例名称,同一页面的name必须唯一,Api中使用也需用到此值 | string | terminal |
117+
| context | 初始化上下文文本 | string | /vue-web-terminal |
118+
| title | header中显示的标题 | string | vue-web-terminal |
119+
| show-header | 是否显示header | boolean | true |
120+
| init-log | Terminal初始化时显示的日志,是由[消息对象](#消息对象)组成的数组 | array ||
121+
| init-log-delay | 初始化显示日志时每条日志之间的间隔时间,单位毫秒 ms | number | 150 |
122+
| show-log-time | 当消息**type**`normal`时是否显示时间 | boolean | true |
123+
| warnLogByteLimit | 当前Terminal日志占用内存大小超出此限制会发出警告,单位`byte` | number | 1024 * 1024 * 10 |
124+
| warnLogCountLimit | 当前Terminal日志条数超出此限制会发出警告 | number | 200 |
125+
| warnLogLimitEnable | 是否开启日志限制警告 | boolean | true |
126+
| auto-help | 是否打开命令行自动搜索提示功能 | boolean | true |
127+
| enableExampleHint | 是否显示样例提示 | boolean | true |
128+
| command-store | 自定义的命令库,见[命令定义格式](#命令定义) | array | [内置命令行](#内置命令行) |
129+
| command-store-sort | 命令行库排序 | function | function(a,b) {} |
130+
| inputFilter | 自定义输入过滤,返回值为过滤后的字符串 | function | function(当前输入字符char,输入框内字符串value, input时间event) {} |
130131

131132
## Select Events
132133

@@ -382,6 +383,25 @@ execCmd(key, command, success)
382383
]
383384
```
384385

386+
### 命令Help
387+
388+
插件内置了help命令可以方便使用者搜索命令库,通过help命令可以查看命令的key、分组、解释样例信息。
389+
```shell
390+
391+
# 显示全部命令信息
392+
help
393+
394+
# 模糊搜索命令,搜索build前缀的命令
395+
help build*
396+
397+
# 模糊搜索名,搜索带有event的命令
398+
help *event*
399+
400+
# 按分组搜索,搜索关键词需要以":"开头,搜索分组为server的所有命令
401+
help :server
402+
403+
```
404+
385405
### 内置命令
386406

387407
Terminal默认内置有以下命令,且不可替代
@@ -442,4 +462,4 @@ Terminal默认内置有以下命令,且不可替代
442462
]
443463
}
444464
]
445-
```
465+
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-web-terminal",
3-
"version": "2.0.3",
3+
"version": "2.0.4",
44
"description": "网页端命令行插件,适配vue3",
55
"private": false,
66
"scripts": {

src/Terminal.js

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ export default {
3737
cmd: 'help refresh'
3838
},
3939
{
40-
des:"Get help documentation for fuzzy matching commands.",
40+
des: "Get help documentation for fuzzy matching commands.",
4141
cmd: 'help *e*'
42+
},
43+
{
44+
des: "Get help documentation for specified group, match key must start with ':'.",
45+
cmd: 'help groupA:'
4246
}
4347
]
4448
}, {
@@ -131,9 +135,12 @@ export default {
131135
type: Boolean,
132136
default: true
133137
},
134-
helpStyle: {
135-
type: String,
136-
default: ''
138+
enableExampleHint: {
139+
type: Boolean,
140+
default: true
141+
},
142+
inputFilter: {
143+
type: Function
137144
}
138145
},
139146
created() {
@@ -239,13 +246,26 @@ export default {
239246
this.$refs.inputCmd.focus()
240247
})
241248
},
242-
_printHelp(regExp) {
249+
/**
250+
* help命令执行后调用此方法
251+
*
252+
* 命令搜索:comm*、command
253+
* 分组搜索::groupA
254+
*/
255+
_printHelp(regExp, srcStr) {
243256
let content = {
244257
head: ['KEY', 'GROUP', 'DETAIL'],
245258
rows: []
246259
}
260+
let findGroup = srcStr && srcStr.length > 1 && srcStr.startsWith(":")
261+
? srcStr.substring(1).toLowerCase()
262+
: null
247263
this.allCommandStore.forEach(command => {
248-
if (!regExp.test(command.key)) {
264+
if (findGroup) {
265+
if (_isEmpty(command.group) || findGroup !== command.group.toLowerCase()) {
266+
return;
267+
}
268+
} else if (!regExp.test(command.key)) {
249269
return
250270
}
251271
let row = []
@@ -312,7 +332,7 @@ export default {
312332
case 'help': {
313333
let reg = `^${split.length > 1 && _nonEmpty(split[1]) ? split[1] : "*"}$`
314334
reg = reg.replace(/\*/g, ".*")
315-
this._printHelp(new RegExp(reg, "i"))
335+
this._printHelp(new RegExp(reg, "i"), split[1])
316336
break;
317337
}
318338
case 'clear':
@@ -625,6 +645,16 @@ export default {
625645
this._searchCmd()
626646
}
627647
}
648+
},
649+
_onInput(e) {
650+
if (this.inputFilter != null) {
651+
let value = e.target.value
652+
let newStr = this.inputFilter(e.data, value, e)
653+
if (newStr == null) {
654+
newStr = value
655+
}
656+
this.command = newStr
657+
}
628658
}
629659
}
630-
}
660+
}

src/Terminal.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
<span> > </span>
120120
</span><span v-html="require('./Util.js')._html(command)"></span><span v-show="cursorConf.show" class="cursor"
121121
:style="`width:${cursorConf.width}px;margin-left:${cursorConf.left}px`">&nbsp;</span>
122-
<input type="text" autofocus="autofocus" id="command-input" v-model="command" class="input-box"
122+
<input type="text" autofocus="autofocus" id="command-input" v-model="command" @input="_onInput" class="input-box"
123123
ref="inputCmd"
124124
autocomplete="off"
125125
auto-complete="new-password"
@@ -137,8 +137,7 @@
137137
<p class="help-msg" v-if="searchCmd.item != null" @click.self="_activeCursor">{{ searchCmd.item.usage }}</p>
138138
</div>
139139
</div>
140-
<div class="cmd-help" :style="helpStyle"
141-
v-if="searchCmd.item != null && !(require('./Util.js'))._screenType().xs">
140+
<div class="cmd-help" v-if="enableExampleHint && searchCmd.item != null && !(require('./Util.js'))._screenType().xs">
142141
<p class="text" v-if="searchCmd.item.description != null" style="margin: 15px 0"
143142
v-html="searchCmd.item.description"></p>
144143
<div v-if="searchCmd.item.example != null && searchCmd.item.example.length > 0">

0 commit comments

Comments
 (0)