-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclanvas.js
44 lines (37 loc) · 956 Bytes
/
clanvas.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
var createCharm = require('charm')
module.exports = Clanvas
function Clanvas (stdout, width, height, bg) {
this.ratio = 2
this.charm = createCharm()
this.charm.pipe(stdout)
this.charm.reset()
this.charm.cursor(false)
this.width = Math.floor(width / this.ratio)
this.height = height - 2
this.backgroundColor = bg
}
Clanvas.prototype.fill = function (color) {
for (var i = 0; i <= this.height; i++) {
this.fillLine(i, color)
}
}
Clanvas.prototype.clear = function () {
this.fill(this.backgroundColor)
}
Clanvas.prototype.paintCell = function (x, y, fg, bg, char) {
this.charm
.background(bg)
.foreground(fg)
.position(x * this.ratio, y + 2)
.write(char + ' ')
}
Clanvas.prototype.fillLine = function (y, color) {
var line = new Array(1 + this.width).join(' ')
this.charm
.background(color)
.position(1, y + 2)
.write(line)
}
Clanvas.prototype.dispose = function () {
this.charm.reset()
}