组件
终端 Terminal
Terminal:终端界面。上方是历史记录,下方是输入行。组件只负责读取输入和显示光标;每行输入以事件发出,调用方通过 lines prop 返回要显示的行,因此历史由调用方控制。
#基础用法
paper 0.1.0
Type help to see what the console knows.
<script setup lang="ts">
import { Terminal } from "@bysages/vue";
import { ref } from "vue";
const lines = ref(["paper 0.1.0", "Type help to see what the console knows."]);
function run(text: string) {
if (text === "clear") {
lines.value = [];
return;
}
lines.value.push(`❯ ${text}`);
lines.value.push(text === "help" ? "Commands: help, clear" : `unknown command: ${text}`);
}
</script>
<template>
<Terminal
:lines="lines"
prompt="❯"
placeholder="Type a command…"
label="Paper console"
class="w-full max-w-xl"
@command="run"
/>
</template>
#属性
#Terminal
Terminal:终端界面。上方是历史记录,下方是输入行。组件只负责读取输入和显示光标;每行输入以事件发出,调用方通过 lines prop 返回要显示的行,因此历史由调用方控制。
| 属性 | 类型 | 默认值 | 描述 |
|---|---|---|---|
lines | Array as PropType<string[]> | () => [] | 终端记录,最早的行在前 |
prompt | String | "$" | 输入行开头的提示符 |
placeholder | String | undefined | — |
label | String | undefined | — |