forked from andrewjstone/node-multimeter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
75 lines (64 loc) · 1.88 KB
/
index.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var charmer = require('charm');
var Bar = require('./lib/bar');
var exports = module.exports = function (c) {
if (c instanceof charmer.Charm) {
var charm = c;
}
else {
var charm = charmer.apply(null, arguments);
charm.on('^C', function () {
charm.destroy();
});
}
var multi = function (x, y, params) {
if (typeof x === 'object') {
params = x;
x = params.x;
y = params.y;
}
if (!params) params = {};
if (x === undefined) x = '+0';
if (y === undefined) y = '+0';
var bar = new Bar(charm, x, y, params);
multi.bars.push(bar);
bar.offset = multi.offset;
multi.on('offset', function (o) {
bar.offset = o;
});
return bar;
};
multi.bars = [];
multi.rel = function (x, y, params) {
return multi(x, '-' + y, params);
};
multi.drop = function (params, cb) {
if (!cb) { cb = params; params = {} }
charm.position(function (x, y) {
var bar = new Bar(charm, x, y, params);
multi.bars.push(bar);
multi.on('offset', function (o) {
bar.offset = o;
});
cb(bar);
});
};
multi.charm = charm;
multi.destroy = charm.destroy.bind(charm);
multi.on = charm.on.bind(charm);
multi.emit = charm.emit.bind(charm);
multi.removeListener = charm.removeListener.bind(charm);
multi.write = charm.write.bind(charm);
(function () {
var offset = 0;
Object.defineProperty(multi, 'offset', {
set : function (o) {
offset = o;
multi.emit('offset', o);
},
get : function () {
return offset;
}
});
})();
return multi;
};