progressbar. automatic focus on elements. test/widget.js. reallyScrollable.

This commit is contained in:
Christopher Jeffrey 2015-02-26 15:37:01 -08:00
parent 236f5fba00
commit 0e2b626556
3 changed files with 26 additions and 74 deletions

View File

@ -751,7 +751,7 @@ A progress bar allowing various styles. This can also be used as a form input.
- **orientation** - can be `horizontal` or `vertical`.
- **barFg, barBg** - (completed) bar foreground and background.
(can be contained in `style`: e.g. `style.bar.fg`).
- **ch** - the character to fill the bar with (default is space).
- **pch** - the character to fill the bar with (default is space).
- **filled** - the amount filled (0 - 100).
- **value** - same as `filled`.
- **keys** - enable key support.

View File

@ -4060,6 +4060,12 @@ ScrollableBox.prototype.__proto__ = Box.prototype;
ScrollableBox.prototype.type = 'scrollable-box';
// XXX Potentially use this in place of scrollable checks elsewhere.
ScrollableBox.prototype.__defineGetter__('reallyScrollable', function() {
if (this.shrink) return this.scrollable;
return this._scrollBottom() > this.height;
});
ScrollableBox.prototype._scrollBottom = function() {
if (!this.scrollable) return 0;
@ -4533,6 +4539,7 @@ List.prototype.appendItem = function(item) {
self.emit('select', item, self.selected);
return;
}
self.focus();
self.select(item);
self.screen.render();
});
@ -5376,6 +5383,7 @@ Button.prototype.__proto__ = Input.prototype;
Button.prototype.type = 'button';
Button.prototype.press = function() {
this.focus();
this.value = true;
var result = this.emit('press');
delete this.value;
@ -5403,7 +5411,16 @@ function ProgressBar(options) {
}
this.value = this.filled;
this.ch = options.ch || ' ';
this.pch = options.pch || ' ';
// XXX Workaround that predates the usage of `el.ch`.
if (options.ch) {
this.pch = options.ch;
this.ch = ' ';
}
if (options.bch) {
this.ch = options.bch;
}
if (!this.style.bar) {
this.style.bar = {};
@ -5478,7 +5495,7 @@ ProgressBar.prototype.render = function() {
dattr = this.sattr(this.style.bar, this.style.bar.fg, this.style.bar.bg);
this.screen.fillRegion(dattr, this.ch, xi, xl, yi, yl);
this.screen.fillRegion(dattr, this.pch, xi, xl, yi, yl);
if (this.content) {
var line = this.screen.lines[yi];

View File

@ -25,44 +25,12 @@ screen.append(blessed.line({
right: 0
}));
/*
screen.append(blessed.box({
fg: 4,
bg: -1,
border: {
type: 'ascii',
fg: -1,
bg: -1
},
content: 'Hello world!',
width: '50%',
height: '50%',
top: 'center',
left: 'center'
}));
screen.children[0].append(blessed.box({
fg: 4,
bg: 3,
border: {
type: 'bg',
fg: 0,
bg: 1,
ch: '/'
},
content: 'Foobar',
width: '50%',
height: '50%',
top: 'center',
left: 'center'
}));
*/
var list = blessed.list({
align: 'center',
mouse: true,
fg: 'blue',
bg: 'default',
label: ' My list ',
border: {
type: 'ascii',
fg: 'default',
@ -103,16 +71,6 @@ list.items.forEach(function(item) {
item.setHover(item.getText().trim());
});
list.prepend(blessed.text({
left: 2,
content: ' My list '
}));
if (screen.autoPadding) {
list.children[0].rleft = -list.ileft + 2;
list.children[0].rtop = -list.itop;
}
list.on('keypress', function(ch, key) {
if (key.name === 'up' || key.name === 'k') {
list.up();
@ -125,6 +83,11 @@ list.on('keypress', function(ch, key) {
}
});
list.on('select', function(item, select) {
list.setLabel(' ' + item.getText() + ' ');
screen.render();
});
var progress = blessed.progressbar({
fg: 'blue',
bg: 'default',
@ -194,21 +157,7 @@ screen.on('element focus', function(cur, old) {
screen.render();
});
/*
screen.on('element mouseover', function(el) {
el._bg = el.bg;
el.bg = 1;
screen.render();
});
screen.on('element mouseout', function(el) {
el.bg = el._bg;
screen.render();
});
*/
var input = blessed.textbox({
mouse: true,
label: ' My Input ',
content: '',
fg: 'blue',
@ -268,16 +217,6 @@ screen.on('keypress', function(ch, key) {
? screen.focusPrevious()
: screen.focusNext();
}
//if (key.name === 'i') {
// return input.readInput(function(err, value) {
// ;
// });
//}
//if (key.name === 'e') {
// return input.readEditor(function(err, value) {
// ;
// });
//}
if (key.name === 'escape' || key.name === 'q') {
return process.exit(0);
}
@ -289,10 +228,6 @@ screen.key('C-z', function() {
list.focus();
//screen.on('element click', function(el) {
// el.focus();
//});
screen.render();
setInterval(function() {