primevue-mirror/doc/terminal/BasicDoc.vue

171 lines
4.7 KiB
Vue
Raw Normal View History

2023-02-28 08:29:30 +00:00
<template>
<DocSectionText v-bind="$attrs">
<p>
Commands are processed using an EventBus implementation called <i>TerminalService</i>. Import this service into your component and subscribe to the <i>command</i> event to process the commands by sending replies with the
<i>response</i> event.
</p>
</DocSectionText>
<div class="card">
<p>Enter "<strong>date</strong>" to display the current date, "<strong>greet {0}</strong>" for a message and "<strong>random</strong>" to get a random number.</p>
2023-10-23 21:19:52 +00:00
<Terminal
welcomeMessage="Welcome to PrimeVue"
prompt="primevue $"
aria-label="PrimeVue Terminal Service"
/>
2023-02-28 08:29:30 +00:00
</div>
<DocSectionCode :code="code" />
</template>
<script>
import TerminalService from 'primevue/terminalservice';
2023-04-24 08:34:08 +00:00
2023-02-28 08:29:30 +00:00
export default {
data() {
return {
code: {
2023-09-22 12:54:14 +00:00
basic: `
2023-10-23 21:19:52 +00:00
<Terminal
welcomeMessage="Welcome to PrimeVue"
prompt="primevue $"
aria-label="PrimeVue Terminal Service"
/>
2023-10-15 09:38:39 +00:00
`,
2023-09-22 12:54:14 +00:00
options: `
<template>
2023-02-28 08:29:30 +00:00
<div>
<p>Enter "date" to display the current date, "greet {0}" for a message and "random" to get a random number.</p>
2023-10-23 21:19:52 +00:00
<Terminal
welcomeMessage="Welcome to PrimeVue"
prompt="primevue $"
aria-label="PrimeVue Terminal Service"
/>
2023-02-28 08:29:30 +00:00
</div>
</template>
<script>
import TerminalService from "primevue/terminalservice";
export default {
methods: {
commandHandler(text) {
let response;
let argsIndex = text.indexOf(' ');
let command = argsIndex !== -1 ? text.substring(0, argsIndex) : text;
switch(command) {
case "date":
response = 'Today is ' + new Date().toDateString();
break;
case "greet":
response = 'Hola ' + text.substring(argsIndex + 1);
break;
case "random":
response = Math.floor(Math.random() * 100);
break;
default:
response = "Unknown command: " + command;
}
TerminalService.emit('response', response);
}
},
mounted() {
TerminalService.on('command', this.commandHandler);
},
beforeUnmount() {
TerminalService.off('command', this.commandHandler);
}
}
<\/script>
2023-10-15 09:38:39 +00:00
`,
2023-09-22 12:54:14 +00:00
composition: `
<template>
2023-02-28 08:29:30 +00:00
<div>
<p>Enter "date" to display the current date, "greet {0}" for a message and "random" to get a random number.</p>
2023-10-23 21:19:52 +00:00
<Terminal
welcomeMessage="Welcome to PrimeVue"
prompt="primevue $"
aria-label="PrimeVue Terminal Service"
/>
2023-02-28 08:29:30 +00:00
</div>
</template>
<script setup>
import { onMounted, onBeforeUnmount } from 'vue';
import TerminalService from "primevue/terminalservice";
onMounted(() => {
TerminalService.on('command', commandHandler);
})
onBeforeUnmount(() => {
TerminalService.off('command', commandHandler);
})
const commandHandler = (text) => {
let response;
let argsIndex = text.indexOf(' ');
let command = argsIndex !== -1 ? text.substring(0, argsIndex) : text;
switch(command) {
case "date":
response = 'Today is ' + new Date().toDateString();
break;
case "greet":
response = 'Hola ' + text.substring(argsIndex + 1);
break;
case "random":
response = Math.floor(Math.random() * 100);
break;
default:
response = "Unknown command: " + command;
}
TerminalService.emit('response', response);
}
<\/script>
2023-10-23 21:19:52 +00:00
`
2023-02-28 08:29:30 +00:00
}
};
},
mounted() {
TerminalService.on('command', this.commandHandler);
},
beforeUnmount() {
TerminalService.off('command', this.commandHandler);
},
methods: {
commandHandler(text) {
let response;
let argsIndex = text.indexOf(' ');
let command = argsIndex !== -1 ? text.substring(0, argsIndex) : text;
switch (command) {
case 'date':
response = 'Today is ' + new Date().toDateString();
break;
case 'greet':
response = 'Hola ' + text.substring(argsIndex + 1);
break;
case 'random':
response = Math.floor(Math.random() * 100);
break;
default:
response = 'Unknown command: ' + command;
}
TerminalService.emit('response', response);
}
}
};
</script>