Skip to content

Commit bead39e

Browse files
committed
[vue3] merge from vue2 branch
1 parent 0b2dff5 commit bead39e

File tree

4 files changed

+62
-56
lines changed

4 files changed

+62
-56
lines changed

src/Terminal.vue

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
TerminalAsk,
2020
TerminalFlash,
2121
InputTipsSearchHandlerFunc,
22-
InputTipsSelectHandlerFunc, TerminalElementInfo
22+
InputTipsSelectHandlerFunc, TerminalElementInfo, TerminalCursorStyle
2323
} from "./types";
2424
import {
2525
_copyTextToClipboard, _debounce,
@@ -38,7 +38,7 @@ import {
3838
_isSafari,
3939
_nonEmpty,
4040
_openUrl,
41-
_pointInRect,
41+
_pointInRect, _screenType,
4242
} from "~/common/util.ts";
4343
import api, {register, rename, unregister} from "~/common/api";
4444
import {DEFAULT_COMMANDS} from "~/common/configuration.ts";
@@ -131,15 +131,9 @@ const props = defineProps({
131131
type: Number,
132132
default: 15
133133
},
134-
/**
135-
* 光标样式,可选值:
136-
* - block
137-
* - underline
138-
* - bar
139-
* - none
140-
*/
134+
// 光标样式
141135
cursorStyle: {
142-
type: String,
136+
type: String as PropType<TerminalCursorStyle>,
143137
default: () => "block"
144138
},
145139
// 光标闪烁开关
@@ -197,6 +191,14 @@ const containerStyle = computed(() => {
197191
return ''
198192
})
199193
194+
const isEnableHelpBox = computed<boolean>(() => {
195+
return props.enableHelpBox && tips.items[tips.selectedIndex] && tips.items[tips.selectedIndex].command
196+
})
197+
198+
const selectedTipCommand = computed<Command | null>(() => {
199+
return tips.items[tips.selectedIndex] ? tips.items[tips.selectedIndex].command : null
200+
})
201+
200202
const _name = ref<string>()
201203
const command = ref<string>("")
202204
const cursorConf = reactive({
@@ -696,7 +698,7 @@ const _searchCmd = () => {
696698
items.push({
697699
content: o.keyword,
698700
description: o.item.description,
699-
attach: o.item
701+
command: o.item
700702
})
701703
}
702704
_updateTipsItems(items, cursorInKey)
@@ -1241,21 +1243,27 @@ const _onInput = (e: InputEvent) => {
12411243
12421244
_calculateTipsPos()
12431245
1244-
_checkInputCursor()
1245-
_calculateCursorPos()
1246+
nextTick(() => {
1247+
_checkInputCursor()
1248+
_calculateCursorPos()
1249+
1250+
let helpBoxRef = terminalHelpBoxRef.value
1251+
if (helpBoxRef) {
1252+
let cursorRect = terminalCursorRef.value.getBoundingClientRect()
1253+
let helpBoxRect = tips.helpBox.defaultBoxRect || helpBoxRef.getBoundingClientRect()
1254+
if (cursorRect && helpBoxRect && _pointInRect({
1255+
x: cursorRect.x + byteLen.en * 2,
1256+
y: cursorRect.y + FONT_HEIGHT
1257+
}, helpBoxRect)) {
1258+
tips.helpBox.open = false
1259+
tips.helpBox.defaultBoxRect = helpBoxRect
1260+
} else {
1261+
tips.helpBox.open = true
1262+
tips.helpBox.defaultBoxRect = null
1263+
}
1264+
}
1265+
})
12461266
1247-
let cursorRect = terminalCursorRef.value.getBoundingClientRect()
1248-
let helpBoxRect = tips.helpBox.defaultBoxRect || terminalHelpBoxRef.value.getBoundingClientRect()
1249-
if (cursorRect && helpBoxRect && _pointInRect({
1250-
x: cursorRect.x + byteLen.en * 2,
1251-
y: cursorRect.y + FONT_HEIGHT
1252-
}, helpBoxRect)) {
1253-
tips.helpBox.open = false
1254-
tips.helpBox.defaultBoxRect = helpBoxRect
1255-
} else {
1256-
tips.helpBox.open = true
1257-
tips.helpBox.defaultBoxRect = null
1258-
}
12591267
}
12601268
12611269
const _checkInputCursor = () => {
@@ -1696,7 +1704,7 @@ const _selectTips = () => {
16961704
})
16971705
return
16981706
}
1699-
command.value = selectedItem.attach.key
1707+
command.value = selectedItem.command.key
17001708
_resetCursorPos()
17011709
_jumpToBottom()
17021710
}
@@ -1864,12 +1872,12 @@ defineExpose({
18641872
</p>
18651873
</div>
18661874
</div>
1867-
<div v-if="enableHelpBox">
1868-
<slot name="helpBox" :showHeader="showHeader" :item="tips.items[tips.selectedIndex] ? tips.items[tips.selectedIndex].attach : null">
1869-
<t-help-box ref="terminalHelpBox"
1875+
<div v-if="isEnableHelpBox">
1876+
<slot name="helpBox" :showHeader="showHeader" :item="selectedTipCommand">
1877+
<t-help-box ref="terminalHelpBoxRef"
18701878
:top="headerHeight + 10"
1871-
:content="tips.items[tips.selectedIndex] ? tips.items[tips.selectedIndex].attach : null"
1872-
v-show="tips.helpBox.open"/>
1879+
:content="selectedTipCommand"
1880+
v-show="tips.helpBox.open && !_screenType().xs"/>
18731881
</slot>
18741882
</div>
18751883

src/components/THelpBox.vue

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,40 @@
11
<script setup lang="ts">
22
import {PropType, ref} from "vue";
3-
import {SearchResult} from "~/types";
3+
import {Command} from "~/types";
44
55
defineProps({
66
top: Number,
7-
result: Object as PropType<SearchResult>
7+
content: Object as PropType<Command>
88
})
99
const terminalHelpBoxRef = ref()
10-
const getClientRect = (): DOMRect => {
10+
11+
const getBoundingClientRect = (): DOMRect => {
1112
return terminalHelpBoxRef.value.getBoundingClientRect()
1213
}
1314
1415
defineExpose({
15-
getClientRect
16+
getBoundingClientRect
1617
})
1718
</script>
1819

1920
<template>
2021
<div class="t-cmd-help"
2122
ref="terminalHelpBoxRef"
2223
:style="`top: ${top}px;max-height: calc(100% - ${top}px);`">
23-
<p class="text"
24-
v-if="result.item.description"
25-
style="margin: 15px 0"
26-
v-html="result.item.description"/>
27-
<div v-if="result.item.example && result.item.example.length > 0">
28-
<div v-for="(it,idx) in result.item.example" :key="idx" class="text">
29-
<div v-if="result.item.example.length === 1">
30-
<span>Example: <code>{{ it.cmd }}</code> {{ it.des }}</span>
24+
<div class="t-cmd-help-des" v-if="content.description" v-html="content.description"/>
25+
<div v-if="content.example && content.example.length > 0">
26+
<div v-for="(it,idx) in content.example" :key="idx" class="text">
27+
<div v-if="content.example.length === 1">
28+
<span>Example: <code class="t-code-inline">{{ it.cmd }}</code> {{ it.des }}</span>
3129
</div>
3230
<div v-else>
3331
<div class="t-cmd-help-eg">
34-
eg{{ (result.item.example.length > 1 ? (idx + 1) : '') }}:
32+
eg{{ (content.example.length > 1 ? (idx + 1) : '') }}:
3533
</div>
3634
<div class="t-cmd-help-example">
3735
<ul class="t-example-ul">
38-
<li class="t-example-li"><code>{{ it.cmd }}</code></li>
39-
<li class="t-example-li"><span v-if="it.des != null" class="t-cmd-help-des">{{ it.des }}</span></li>
36+
<li class="t-example-li"><code class="t-code-inline">{{ it.cmd }}</code></li>
37+
<li class="t-example-li"><span v-if="it.des != null" class="t-cmd-help-des-item">{{ it.des }}</span></li>
4038
</ul>
4139
</div>
4240
</div>

src/types/index.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
export type TerminalMessageClass = 'success' | 'error' | 'info' | 'warning' | 'system'
2+
3+
export type TerminalMessageType = 'cmdLine' | 'normal' | 'json' | 'code' | 'table' | 'html' | 'ansi'
4+
5+
export type TerminalCursorStyle = 'block' | 'underline' | 'bar' | 'none'
6+
17
export interface EditorConfig {
28
open: boolean
39
focus: boolean
@@ -20,12 +26,6 @@ export type DragConfig = {
2026
pinned?: boolean
2127
}
2228

23-
export type SearchResult = {
24-
show: boolean
25-
defaultBoxRect: null
26-
item?: Command
27-
}
28-
2929
export type ScreenType = {
3030
xs?: boolean
3131
sm?: boolean
@@ -70,9 +70,9 @@ export type MessageGroup = {
7070
}
7171

7272
export type Message = {
73-
type?: 'normal' | 'json' | 'code' | 'table' | 'html' | 'ansi' | 'cmdLine'
73+
type?: TerminalMessageType
7474
content: string | number | object | MessageContentTable | Array<any>
75-
class?: 'success' | 'error' | 'info' | 'warning' | 'system'
75+
class?: TerminalMessageClass
7676
tag?: string,
7777
depth?: number
7878
}
@@ -87,7 +87,7 @@ export type AskConfig = {
8787
export type InputTipItem = {
8888
content: string,
8989
description?: string,
90-
attach?: Command
90+
command?: Command
9191
}
9292

9393
export type CharWidth = {

test/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ const setCommand = () => {
275275
:show-header="item.showHeader"
276276
:push-message-before="pushMessageBefore"
277277
:log-size-limit="20"
278-
cursor-style="bar"
278+
cursor-style="block"
279279
:enable-cursor-blink="true"
280280
:line-space="15"
281281
enable-hover-stripe

0 commit comments

Comments
 (0)