primevue-mirror/components/lib/terminal/Terminal.vue

59 lines
2.2 KiB
Vue
Raw Normal View History

2022-09-06 12:03:37 +00:00
<template>
2024-02-11 23:48:42 +00:00
<div :class="cx('root')" @click="onClick" v-bind="ptmi('root')">
2024-04-08 11:51:39 +00:00
<div v-if="welcomeMessage" :class="cx('welcomeMessage')" v-bind="ptm('welcomeMessage')">{{ welcomeMessage }}</div>
<div :class="cx('commandList')" v-bind="ptm('content')">
<div v-for="(command, i) of commands" :key="command.text + i.toString()" :class="cx('command')" v-bind="ptm('commands')">
<span :class="cx('promptLabel')" v-bind="ptm('prompt')">{{ prompt }}</span>
<span :class="cx('commandValue')" v-bind="ptm('command')">{{ command.text }}</span>
<div :class="cx('commandResponse')" aria-live="polite" v-bind="ptm('response')">{{ command.response }}</div>
2022-09-06 12:03:37 +00:00
</div>
</div>
2024-04-08 11:51:39 +00:00
<div :class="cx('prompt')" v-bind="ptm('container')">
<span :class="cx('promptLabel')" v-bind="ptm('prompt')">{{ prompt }}</span>
<input ref="input" v-model="commandText" :class="cx('promptValue')" type="text" autocomplete="off" @keydown="onKeydown" v-bind="ptm('commandText')" />
2022-09-06 12:03:37 +00:00
</div>
</div>
</template>
<script>
import TerminalService from 'primevue/terminalservice';
2023-05-29 09:19:55 +00:00
import BaseTerminal from './BaseTerminal.vue';
2022-09-06 12:03:37 +00:00
export default {
name: 'Terminal',
2023-05-24 12:53:29 +00:00
extends: BaseTerminal,
2024-02-11 23:48:42 +00:00
inheritAttrs: false,
2022-09-06 12:03:37 +00:00
data() {
return {
commandText: null,
commands: []
2022-09-14 11:26:01 +00:00
};
2022-09-06 12:03:37 +00:00
},
mounted() {
TerminalService.on('response', this.responseListener);
this.$refs.input.focus();
},
updated() {
this.$el.scrollTop = this.$el.scrollHeight;
},
beforeUnmount() {
TerminalService.off('response', this.responseListener);
},
methods: {
onClick() {
this.$refs.input.focus();
},
onKeydown(event) {
if (event.key === 'Enter' && this.commandText) {
2022-09-14 11:26:01 +00:00
this.commands.push({ text: this.commandText });
2022-09-06 12:03:37 +00:00
TerminalService.emit('command', this.commandText);
this.commandText = '';
}
},
responseListener(response) {
this.commands[this.commands.length - 1].response = response;
}
}
2022-09-14 11:26:01 +00:00
};
2022-09-06 12:03:37 +00:00
</script>