-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblessedtest.js
69 lines (60 loc) · 1.46 KB
/
blessedtest.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
var blessed = require('blessed');
// Create a screen object.
var screen = blessed.screen();
// Create a box perfectly centered horizontally and vertically.
var outer = blessed.box({
fg: 'blue',
bg: 'default',
border: {
type: 'line',
fg: '#ffffff'
},
tags: true,
content: '{center}{red-fg}Hello{/red-fg}{/center}\n'
+ '{right}world!{/right}',
width: '50%',
height: '50%',
top: 'center',
left: 'center'
});
// Append our box to the screen.
screen.append(outer);
// Create a child box perfectly centered horizontally and vertically.
var inner = blessed.box({
parent: outer,
top: 'center',
left: 'center',
width: '50%',
height: '50%',
border: {
type: 'line',
fg: '#ffffff'
},
fg: 'white',
bg: 'magenta',
content: 'Click {bold}me{/bold}!',
tags: true,
hoverEffects: {
bg: 'green'
}
});
// If our box is clicked, change the content.
inner.on('click', function(data) {
inner.setContent('{center}You clicked {red-fg}me{/red-fg}.{/center}');
screen.render();
});
// If box is focused, handle `enter` and give us some more content.
inner.key('enter', function() {
inner.setContent('{right}You pressed {black-fg}enter{/black-fg}.{/right}\n');
inner.setLine(1, 'bar');
inner.insertLine(1, 'foo');
screen.render();
});
// Quit on Escape, q, or Control-C.
screen.key(['escape', 'q', 'C-c'], function(ch, key) {
return process.exit(0);
});
// Focus our element.
inner.focus();
// Render the screen.
screen.render();