Skip to content

Commit e6d4dee

Browse files
committed
add support for the "resize" event
1 parent 2124be3 commit e6d4dee

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ function term (opts) {
3636
// cached "context"
3737
canvas.renderCtx = canvas.getContext('2d');
3838

39+
// handle the "resize" event
40+
stream.on('resize', function () {
41+
canvas.width = stream.columns / pixelWidth;
42+
canvas.height = stream.rows / pixelHeight;
43+
});
44+
3945
return canvas;
4046
}
4147

@@ -47,7 +53,6 @@ function term (opts) {
4753

4854
function render () {
4955
var cursor = ansi(this.stream);
50-
cursor.write('\n');
5156

5257
// erase everything on the screen
5358
cursor.eraseData(2);

t.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
var tc = require('./');
3+
4+
// create terminal <canvas>
5+
var canvas = tc();
6+
var ctx = canvas.getContext('2d');
7+
8+
var x = 0;
9+
var y = 0;
10+
function render () {
11+
12+
// black background
13+
ctx.fillStyle = 'black';
14+
ctx.fillRect(0, 0, canvas.width, canvas.height);
15+
16+
// print height and width
17+
ctx.font = '12px Arial';
18+
ctx.textBaseline = "top";
19+
ctx.fillStyle = 'red';
20+
ctx.fillText('w: ' + canvas.width + ', h: ' + canvas.height, 0, 0);
21+
22+
// render to TTY
23+
canvas.render();
24+
}
25+
26+
process.stdout.on('resize', render);
27+
28+
setInterval(render, 1000 / 60); // 60hz
29+
//render();

0 commit comments

Comments
 (0)