-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathconsole.js
More file actions
30 lines (28 loc) · 823 Bytes
/
console.js
File metadata and controls
30 lines (28 loc) · 823 Bytes
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
'use strict';
define(function (require) {
let cons = document.getElementById('console')
cons.value = ''
let lastStr
let consoleOut = (str) => {
console.log(str)
if (str === lastStr) { return }
lastStr = str
cons.value += '\n'+str
cons.scrollTop = cons.scrollHeight
}
consoleOut('\n Welcome to Limut\n')
let commands = {}
cons.addEventListener('keydown', (event) => {
if (event.key === 'Enter' && !event.shiftKey) {
let line = event.target.value.split('\n').pop().trim()
let args = line.split(' ')
let cmd = (args[0] || '').toLowerCase()
if (commands[cmd]) {
console.log('Console Command: ' + line)
commands[cmd](args.slice(1), line)
}
}
})
consoleOut.addCommand = (name, func) => { commands[name] = func }
return consoleOut
})