This repository was archived by the owner on Jul 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsole.vue
More file actions
113 lines (106 loc) · 2.4 KB
/
Console.vue
File metadata and controls
113 lines (106 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<template>
<div id="console">
<Prompt v-for="(entry, index) in history"
:key="entry.id"
:id="index"
:hostname="entry.hostname"
:command="entry.command"
:result="entry.result"
:delay="entry.delay"
:visible="entry.visible"
:interactive="entry.interactive"
v-on:command-complete="commandComplete" />
<div class="interactive prompt" v-show="is_interactive">
<span class="hostname">kaneda.net %</span>
<span class="cursor" v-show="show_interactive_cursor"></span>
<input id="user_input"
v-model="user_input" v-focus
ref="input" type="text"
autocomplete="off"
v-bind:class="{active: active_prompt}"
@focus="check_command"
@blur="check_command"
@keyup="check_command"
@keyup.enter="send_command"
/>
</div>
</div>
</template>
<script>
import Prompt from './Prompt'
import commands from '../lib/commands'
export default {
name: 'Console',
components: {
Prompt
},
data () {
return {
is_interactive: false,
active_prompt: false,
show_interactive_cursor: false,
user_input: ''
}
},
directives: {
focus: {
inserted: function (el) {
el.focus()
}
}
},
props: {
history: { type: Array, default: () => { return [] } }
},
methods: {
commandComplete: function (id) {
this.history[id].visible = true
this.is_interactive = true
},
check_command () {
this.show_interactive_cursor = !this.user_input.length
this.active_prompt = this.user_input.length > 0
},
send_command () {
const [command, ...args] = this.user_input.trim().split(' ')
this.history.push({
hostname: 'kaneda.net',
command: command + ' ' + args,
result: commands.evaluate(command, args),
interactive: true,
visible: true
})
this.$nextTick(() => {
this.user_input = ''
this.show_interactive_cursor = true
this.active_prompt = false
})
}
},
mounted: function () {
if (this.history.length) {
this.history[0].visible = true
}
}
}
</script>
<style scoped>
div.prompt {
display: flex;
}
span.hostname {
margin-right: 0.5rem;
}
input {
padding: 0;
margin: 0 0 0 -0.5rem;
border: none;
outline: none;
background: none;
min-width: 0;
flex: 1;
}
input.active {
margin-left: 0;
}
</style>