neo-blessed/test/widget-csr.js

90 lines
1.7 KiB
JavaScript
Raw Normal View History

2013-07-18 22:56:05 +00:00
var blessed = require('../')
2013-07-15 06:44:11 +00:00
, screen;
screen = blessed.screen({
2013-07-28 19:29:07 +00:00
dump: __dirname + '/logs/csr.log',
2013-07-15 06:44:11 +00:00
smartCSR: true
});
var lorem = require('fs').readFileSync(__dirname + '/git.diff', 'utf8');
2015-05-02 02:11:34 +00:00
var cleanSides = screen.cleanSides;
function expectClean(value) {
2015-05-02 02:11:34 +00:00
screen.cleanSides = function(el) {
var ret = cleanSides.apply(this, arguments);
if (ret !== value) {
throw new Error('Failed. Expected '
+ value + ' from cleanSides. Got '
+ ret + '.');
}
return ret;
};
}
2013-07-15 06:44:11 +00:00
/*
blessed.box({
parent: screen,
left: 0,
top: 'center',
width: '50%',
height: 2,
2015-04-04 06:43:24 +00:00
style: {
bg: 'green'
},
content: 'This will disallow CSR.'
});
expectClean(false);
2013-07-15 06:44:11 +00:00
*/
2015-05-02 02:11:34 +00:00
var btext = blessed.box({
parent: screen,
left: 'center',
top: 'center',
width: '80%',
height: '80%',
2015-04-04 06:43:24 +00:00
style: {
bg: 'green'
},
2015-04-04 06:43:24 +00:00
border: 'line',
content: 'CSR should still work.'
});
2015-05-02 02:11:34 +00:00
btext._oscroll = btext.scroll;
btext.scroll = function(offset, always) {
expectClean(true);
return btext._oscroll(offset, always);
};
var text = blessed.scrollabletext({
parent: screen,
content: lorem,
2015-04-04 06:43:24 +00:00
border: 'line',
left: 'center',
top: 'center',
2015-05-02 02:11:34 +00:00
draggable: true,
width: '50%',
height: '50%',
mouse: true,
keys: true,
vi: true
});
2015-05-02 02:11:34 +00:00
text._oscroll = text.scroll;
text.scroll = function(offset, always) {
var el = this;
var value = true;
if (el.left < 0) value = true;
if (el.top < 0) value = false;
if (el.left + el.width > screen.width) value = true;
if (el.top + el.height > screen.height) value = false;
expectClean(value);
return text._oscroll(offset, always);
};
text.focus();
screen.key('q', function() {
return process.exit(0);
});
screen.render();