-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathApp.vue
380 lines (343 loc) · 9.75 KB
/
App.vue
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
<template>
<section>
<div class="mt-4">
<div class="container">
<h1>vue-command</h1>
<p class="lead">
A fully working, most feature-rich Vue.js terminal emulator. Now with Vue.js 3 support! <a
href="https://github.com/ndabAP/vue-command">Github</a>
</p>
<pre><code>$ npm install --save vue-command</code></pre>
<div class="mb-4">
<vue-command
v-model:cursor-position="cursorPosition"
v-model:dispatched-queries="dispatchedQueries"
v-model:is-fullscreen="isFullscreen"
v-model:history="history"
v-model:history-position="historyPosition"
v-model:query="query"
:commands="commands"
:font="font"
:help-text="helpText"
:help-timeout="helpTimeout"
:hide-bar="hideBar"
:hide-buttons="hideButtons"
:hide-prompt="hidePrompt"
:hide-title="hideTitle"
:invert="invert"
:prompt="prompt"
:options-resolver="optionsResolver"
:show-help="showHelp"
:title="title" />
</div>
<div class="table-responsive">
<table class="table table-striped table-borderless">
<thead>
<tr>
<th scope="col">
Property
</th>
<th scope="col">
Value
</th>
</tr>
</thead>
<tbody>
<tr>
<td><pre><code>cursor-position</code></pre></td>
<td>
<pre><code>{{ cursorPosition }}</code></pre>
</td>
</tr>
<tr>
<td><pre><code>dispatched-queries</code></pre></td>
<td>
<pre><code>{{ dispatchedQueries }}</code></pre>
</td>
</tr>
<tr>
<td><pre><code>help-text</code></pre></td>
<td>
<pre><code>{{ helpText }}</code></pre>
</td>
</tr>
<tr>
<td><pre><code>help-timeout</code></pre></td>
<td>
<pre><code>{{ helpTimeout }}</code></pre>
</td>
</tr>
<tr>
<td><pre><code>hide-bar</code></pre></td>
<td>
<input
v-model="hideBar"
class="form-check-input"
type="checkbox"
value="">
</td>
</tr>
<tr>
<td><pre><code>hide-buttons</code></pre></td>
<td>
<input
v-model="hideButtons"
class="form-check-input"
type="checkbox"
value="">
</td>
</tr>
<tr>
<td><pre><code>hide-prompt</code></pre></td>
<td>
<pre><code>{{ hidePrompt }}</code></pre>
</td>
</tr>
<tr>
<td><pre><code>hide-title</code></pre></td>
<td>
<input
v-model="hideTitle"
class="form-check-input"
type="checkbox"
value="">
</td>
</tr>
<tr>
<td><pre><code>help-timeout</code></pre></td>
<td>
<pre><code>{{ helpTimeout }}</code></pre>
</td>
</tr>
<tr>
<td><pre><code>history</code></pre></td>
<td>
<pre><code>{{ history }}</code></pre>
</td>
</tr>
<tr>
<td><pre><code>history-position</code></pre></td>
<td>
<pre><code>{{ historyPosition }}</code></pre>
</td>
</tr>
<tr>
<td><pre><code>invert</code></pre></td>
<td>
<input
v-model="invert"
class="form-check-input"
type="checkbox"
value="">
</td>
</tr>
<tr>
<td><pre><code>is-fullscreen</code></pre></td>
<td>
<pre><code>{{ isFullscreen }}</code></pre>
</td>
</tr>
<tr>
<td><pre><code>prompt</code></pre></td>
<td>
<pre><code>{{ prompt }}</code></pre>
</td>
</tr>
<tr>
<td><pre><code>query</code></pre></td>
<td>
<pre><code>{{ query }}</code></pre>
</td>
</tr>
<tr>
<td><pre><code>title</code></pre></td>
<td>
<pre><code>{{ title }}</code></pre>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</section>
</template>
<script lang="js">
import { ref } from 'vue'
import VueCommand from '@/components/VueCommand'
import {
createStderr,
createStdout,
createQuery,
listFormatter,
newDefaultHistory,
tableFormatter
} from '@/library'
import NanoEditor from '@/hosted/NanoEditor.vue'
import ChuckNorris from '@/hosted/ChuckNorris.vue'
const PROMPT = 'neil@moon~$'
export default {
components: {
VueCommand
},
setup () {
const cursorPosition = ref(0)
const dispatchedQueries = ref(new Set())
const font = ref('')
const helpText = ref('Type in help')
const helpTimeout = ref(3500)
const hideBar = ref(false)
const hideButtons = ref(false)
const hidePrompt = ref(false)
const hideTitle = ref(false)
const history = ref(newDefaultHistory())
const historyPosition = ref(0)
const invert = ref(false)
const isFullscreen = ref(false)
const prompt = ref(PROMPT)
const query = ref('')
const showHelp = ref(true)
const title = ref('bash - 720x350')
const optionsResolver = (program, parsedQuery, setQuery) => {
const lastArgument = parsedQuery[parsedQuery.length - 1]
switch (program) {
case 'cd':
switch (parsedQuery.length) {
case 0:
break
case 1:
setQuery('cd home')
break
default:
if ('home'.startsWith(lastArgument) && lastArgument !== 'home') {
setQuery('cd home')
}
break
}
break
}
}
const commands = {
cd: parsedQuery => {
if (parsedQuery.length < 2 || parsedQuery[parsedQuery.length - 1] === '.') {
return createQuery()
}
const lastArgument = parsedQuery[parsedQuery.length - 1]
if (lastArgument === 'home') {
prompt.value = `${PROMPT}/home`
}
if ((lastArgument === '../' || lastArgument === '..') &&
prompt.value === `${PROMPT}/home`) {
prompt.value = `${PROMPT}`
}
if (lastArgument !== 'home' && lastArgument !== '../' && lastArgument !== '..') {
return createStderr(`bash: cd: ${lastArgument}: No such file or directory`)
}
return createQuery()
},
clear: () => {
// "splice" is necessary since Vue.js losses its reactivity if array is
// set to empty
history.value.splice(0, history.value.length)
return createQuery()
},
'hello-world': () => {
return createStdout('Hello world')
},
history: () => {
const history = []
for (const [index, entry] of [...dispatchedQueries.value].entries()) {
history.push([index, entry])
}
return createStdout(tableFormatter(history))
},
nano: () => NanoEditor,
norris: () => ChuckNorris,
'set-font': parsedQuery => {
if (parsedQuery.length < 2) {
return createStderr('Missing font')
}
const match = parsedQuery.at(1)
if (match) {
font.value = match.replace(/['"]+/g, '')
return createQuery()
}
return createStderr('Missing font')
}
}
commands.help = () => {
const list = Object.keys(commands)
// TODO: Create terminal-like columns
return createStdout(listFormatter(...list))
}
return {
commands,
cursorPosition,
dispatchedQueries,
helpText,
helpTimeout,
hideBar,
hideButtons,
hidePrompt,
hideTitle,
history,
historyPosition,
invert,
isFullscreen,
prompt,
query,
showHelp,
title,
font,
optionsResolver
}
}
}
</script>
<style lang="scss">
@media (min-width: 1200px) {
.container {
max-width: 720px;
}
}
.vue-command,
.vue-command--invert {
width: 100%;
::-webkit-scrollbar {
width: 6px;
}
.vue-command__bar,
.vue-command__bar--invert {
border-top-right-radius: 6px;
border-top-left-radius: 6px;
}
.vue-command__history,
.vue-command__history--invert {
height: 350px;
border-bottom-right-radius: 6px;
border-bottom-left-radius: 6px;
}
}
.vue-command {
::-webkit-scrollbar-track {
background: #252525;
}
::-webkit-scrollbar-thumb {
background: #f1f1f1;
}
::-webkit-scrollbar-thumb:hover {
background: #333;
}
}
.vue-command--invert {
::-webkit-scrollbar-track {
background: #dadada;
}
::-webkit-scrollbar-thumb {
background: #0e0e0e;
}
::-webkit-scrollbar-thumb:hover {
background: #cccccc;
}
}
</style>