-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
59 lines (47 loc) · 1.22 KB
/
app.js
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
var h = require('hyperscript')
exports.needs = {
command: 'map'
}
exports.gives = 'app'
function first (conts, cb) {
;(function next(i) {
if(i >= conts.length)
cb(new Error('no matches'))
else if(!conts[i])
next(i + 1)
else
conts[i](function (err, result) {
if(err || result) cb(err, result)
else next(i+1)
})
})(0)
}
exports.create = function (api) {
return function () {
document.head.appendChild(h('style',
require('fs').readFileSync(__dirname+'/style.css', 'utf8')))
var commands =
h('input.wide', {
onkeydown: function (ev) {
if(ev.keyCode === 13) { //enter
first(api.command(ev.target.value), function (err, el) {
results.textContent = ''
if(err) results.appendChild(h('pre', err.stack))
else {
results.appendChild(el)
el.focus()
}
})
}
}
})
var results = h('div.results.wide.high', {
onkeydown: function (ev) {
if(ev.keyCode == 27) //esc?
commands.focus()
}
})
document.body.appendChild(h('div.screen', commands, results))
return true
}
}