2013-07-18 22:56:05 +00:00
|
|
|
var blessed = require('../')
|
2013-07-28 19:29:07 +00:00
|
|
|
, assert = require('assert')
|
|
|
|
, screen;
|
|
|
|
|
|
|
|
screen = blessed.screen({
|
|
|
|
dump: __dirname + '/logs/pos.log'
|
|
|
|
});
|
2013-06-11 14:20:09 +00:00
|
|
|
|
2013-06-11 16:48:37 +00:00
|
|
|
// My terminal size at the time of writing these tests:
|
2013-07-18 22:56:05 +00:00
|
|
|
screen.program.cols = 154;
|
|
|
|
screen.program.rows = 19;
|
2015-01-15 21:29:46 +00:00
|
|
|
screen.alloc();
|
2013-06-11 16:48:37 +00:00
|
|
|
|
2013-07-18 22:56:05 +00:00
|
|
|
var main = blessed.box({
|
2013-06-11 15:07:04 +00:00
|
|
|
//width: '75%',
|
|
|
|
//height: '75%',
|
|
|
|
width: 115,
|
|
|
|
height: 14,
|
2015-04-04 06:43:24 +00:00
|
|
|
style: {
|
|
|
|
bg: 'yellow'
|
|
|
|
},
|
2013-06-11 14:20:09 +00:00
|
|
|
top: 2,
|
|
|
|
left: 2,
|
|
|
|
content: 'Welcome to my program'
|
|
|
|
});
|
|
|
|
|
|
|
|
screen.append(main);
|
|
|
|
|
2013-07-18 22:56:05 +00:00
|
|
|
var inner = blessed.box({
|
2013-06-11 14:20:09 +00:00
|
|
|
width: '50%',
|
|
|
|
height: '50%',
|
2013-06-11 15:07:04 +00:00
|
|
|
//width: 57,
|
|
|
|
//height: 7,
|
2015-04-04 06:43:24 +00:00
|
|
|
style: {
|
|
|
|
bg: 'blue'
|
|
|
|
},
|
2013-06-11 14:20:09 +00:00
|
|
|
top: 2,
|
|
|
|
left: 2,
|
|
|
|
content: 'Hello'
|
|
|
|
});
|
|
|
|
|
|
|
|
main.append(inner);
|
|
|
|
|
|
|
|
inner.setContent(inner.content + '\n' + JSON.stringify({
|
2015-03-29 11:17:59 +00:00
|
|
|
aleft: inner.aleft,
|
|
|
|
aright: inner.aright,
|
|
|
|
atop: inner.atop,
|
|
|
|
abottom: inner.abottom,
|
2013-06-11 14:20:09 +00:00
|
|
|
width: inner.width,
|
|
|
|
height: inner.height,
|
|
|
|
rleft: inner.rleft,
|
|
|
|
rright: inner.rright,
|
|
|
|
rtop: inner.rtop,
|
|
|
|
rbottom: inner.rbottom
|
|
|
|
}));
|
|
|
|
|
2013-06-11 15:07:04 +00:00
|
|
|
assert.equal(inner.width, 57);
|
|
|
|
assert.equal(inner.height, 7);
|
|
|
|
|
2015-03-29 11:17:59 +00:00
|
|
|
assert.equal(inner.aleft, 4);
|
|
|
|
assert.equal(inner.aright, 93);
|
|
|
|
assert.equal(inner.atop, 4);
|
|
|
|
assert.equal(inner.abottom, 8);
|
2013-06-11 15:07:04 +00:00
|
|
|
|
|
|
|
assert.equal(inner.rleft, 2);
|
|
|
|
assert.equal(inner.rright, 56);
|
|
|
|
assert.equal(inner.rtop, 2);
|
|
|
|
assert.equal(inner.rbottom, 5);
|
|
|
|
|
|
|
|
// Change left to half of the parent width.
|
|
|
|
inner.rleft = '50%';
|
2015-03-29 11:17:59 +00:00
|
|
|
assert.equal(inner.aleft, 59);
|
2013-06-11 15:07:04 +00:00
|
|
|
|
|
|
|
// Change left to half of the screen width.
|
2015-03-29 11:17:59 +00:00
|
|
|
inner.aleft = '50%';
|
|
|
|
assert.equal(inner.aleft, screen.width / 2 | 0);
|
2013-06-11 15:07:04 +00:00
|
|
|
|
|
|
|
// Test implied height/width.
|
|
|
|
reset(inner, {
|
|
|
|
top: 5,
|
|
|
|
bottom: 5,
|
|
|
|
left: 5,
|
|
|
|
right: 5
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(inner.width, 105);
|
|
|
|
assert.equal(inner.height, 4);
|
|
|
|
|
2015-03-29 11:17:59 +00:00
|
|
|
// Demonstrate the difference between `left: 5`, and `.aleft = 5` (relative vs. absolute):
|
|
|
|
inner.atop = inner.abottom = inner.aleft = inner.aright = 5;
|
2013-06-11 15:07:04 +00:00
|
|
|
|
|
|
|
assert.equal(inner.width, 144);
|
|
|
|
assert.equal(inner.height, 9);
|
|
|
|
|
2013-06-11 16:48:37 +00:00
|
|
|
// Test center keyword
|
|
|
|
reset(inner, {
|
|
|
|
width: '50%',
|
|
|
|
height: '50%',
|
|
|
|
left: 'center',
|
|
|
|
top: 'center'
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(inner.rleft, 29);
|
|
|
|
assert.equal(inner.rtop, 4);
|
|
|
|
|
2013-06-11 15:07:04 +00:00
|
|
|
// TODO: Start storing position.left, etc. as absolute?
|
|
|
|
|
2013-06-11 14:20:09 +00:00
|
|
|
screen.on('keypress', function(ch, key) {
|
|
|
|
if (key.name === 'escape' || key.name === 'q') {
|
2015-08-08 04:00:31 +00:00
|
|
|
return screen.destroy();
|
2013-06-11 14:20:09 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
screen.render();
|
2013-06-11 15:07:04 +00:00
|
|
|
|
|
|
|
function reset(el, pos) {
|
2013-06-11 16:48:37 +00:00
|
|
|
pos = pos || {};
|
2013-06-11 15:07:04 +00:00
|
|
|
el.position.width = el.options.width = pos.width;
|
|
|
|
el.position.height = el.options.height = pos.height;
|
|
|
|
el.position.left = el.options.left = pos.left;
|
|
|
|
el.position.right = el.options.right = pos.right;
|
|
|
|
el.position.top = el.options.top = pos.top;
|
|
|
|
el.position.bottom = el.options.bottom = pos.bottom;
|
|
|
|
}
|