multiple fixes/improvements.

This commit is contained in:
Christopher Jeffrey 2014-01-12 05:08:16 -06:00
parent 4cebb15918
commit 6a959074a4
1 changed files with 84 additions and 10 deletions

View File

@ -565,7 +565,7 @@ Screen.prototype._listenKeys = function(el) {
return; return;
} }
if (~self.keyable.indexOf(focused)) { if (focused && focused.keyable) {
focused.emit('keypress', ch, key); focused.emit('keypress', ch, key);
focused.emit('key ' + key.full, ch, key); focused.emit('key ' + key.full, ch, key);
} }
@ -2912,7 +2912,7 @@ Element.prototype._getShrink = function(xi, xl, yi, yl, get) {
return { xi: xi, xl: xl, yi: yi, yl: yl }; return { xi: xi, xl: xl, yi: yi, yl: yl };
}; };
Element.prototype._getCoords = function(get) { Element.prototype._getCoords = function(get, noscroll) {
if (this.hidden) return; if (this.hidden) return;
// if (this.parent._rendering) get = true; // if (this.parent._rendering) get = true;
@ -2956,7 +2956,7 @@ Element.prototype._getCoords = function(get) {
// inside of the visible scroll area. // inside of the visible scroll area.
// NOTE: Lists have a property where only // NOTE: Lists have a property where only
// the list items are obfuscated. // the list items are obfuscated.
if (el) { if (el && !noscroll) {
ppos = this.parent.lpos; ppos = this.parent.lpos;
// The shrink option can cause a stack overflow // The shrink option can cause a stack overflow
@ -3039,6 +3039,11 @@ Element.prototype._getCoords = function(get) {
} }
} }
//if (this.parent.lpos) {
// this.parent.lpos._scrollBottom = Math.max(
// this.parent.lpos._scrollBottom, yl);
//}
return { return {
xi: xi, xi: xi,
xl: xl, xl: xl,
@ -3730,6 +3735,12 @@ ScrollableBox.prototype._scrollBottom = function() {
} }
var bottom = this.children.reduce(function(current, el) { var bottom = this.children.reduce(function(current, el) {
if (!el.detached) {
var l = el._getCoords(false, true);
if (l) {
return Math.max(current, el.rtop + (l.yl - l.yi));
}
}
return Math.max(current, el.rtop + el.height); return Math.max(current, el.rtop + el.height);
}, 0); }, 0);
@ -4847,7 +4858,7 @@ Textbox.prototype.setValue = function(value) {
} }
}; };
Textarea.prototype.submit = function() { Textbox.prototype.submit = function() {
if (!this.__listener) return; if (!this.__listener) return;
return this.__listener('\r', { name: 'enter' }); return this.__listener('\r', { name: 'enter' });
}; };
@ -4994,6 +5005,14 @@ ProgressBar.prototype.render = function() {
this.screen.fillRegion(dattr, this.ch, xi, xl, yi, yl); this.screen.fillRegion(dattr, this.ch, xi, xl, yi, yl);
if (this.content) {
var line = this.screen.lines[yi];
for (var i = 0; i < this.content.length; i++) {
line[xi + i][1] = this.content[i];
}
line.dirty = true;
}
return ret; return ret;
}; };
@ -5415,7 +5434,7 @@ Prompt.prototype.type = function(text, value, callback) {
this.show(); this.show();
this.setContent(' ' + text); this.setContent(' ' + text);
if (value) this._.input.value = value; this._.input.value = value;
this.screen.saveFocus(); this.screen.saveFocus();
@ -5561,6 +5580,16 @@ Message.prototype.display = function(text, time, callback) {
if (time == null) time = 3; if (time == null) time = 3;
//time = time || 3; //time = time || 3;
var parent = this.parent;
this.detach();
parent.append(this);
if (this.scrollable) {
this.screen.saveFocus();
this.focus();
this.setScroll(0);
}
this.show(); this.show();
this.setContent(text); this.setContent(text);
this.screen.render(); this.screen.render();
@ -5569,6 +5598,9 @@ Message.prototype.display = function(text, time, callback) {
var end = function() { var end = function() {
if (end.done) return; if (end.done) return;
end.done = true; end.done = true;
if (self.scrollable) {
self.screen.restoreFocus();
}
self.hide(); self.hide();
self.screen.render(); self.screen.render();
if (callback) callback(); if (callback) callback();
@ -5577,6 +5609,18 @@ Message.prototype.display = function(text, time, callback) {
setTimeout(function() { setTimeout(function() {
self.screen.on('keypress', function fn(ch, key) { self.screen.on('keypress', function fn(ch, key) {
if (key.name === 'mouse') return; if (key.name === 'mouse') return;
if (self.scrollable) {
if ((key.name === 'up' || (self.options.vi && key.name === 'k'))
|| (key.name === 'down' || (self.options.vi && key.name === 'j'))
|| (self.options.vi && key.name === 'u' && key.ctrl)
|| (self.options.vi && key.name === 'd' && key.ctrl)
|| (self.options.vi && key.name === 'b' && key.ctrl)
|| (self.options.vi && key.name === 'f' && key.ctrl)
|| (self.options.vi && key.name === 'g' && !key.shift)
|| (self.options.vi && key.name === 'g' && key.shift)) {
return;
}
}
self.screen.removeListener('keypress', fn); self.screen.removeListener('keypress', fn);
end(); end();
}); });
@ -5869,6 +5913,7 @@ Listbar.prototype.appendItem = function(item, callback) {
if (typeof item === 'object') { if (typeof item === 'object') {
cmd = item; cmd = item;
if (cmd.prefix == null) cmd.prefix = (this.items.length + 1) + '';
} }
if (typeof item === 'string') { if (typeof item === 'string') {
@ -5891,11 +5936,9 @@ Listbar.prototype.appendItem = function(item, callback) {
cmd.prefix = cmd.keys[0]; cmd.prefix = cmd.keys[0];
} }
title = (cmd.prefix != null ? '{light-black-fg}' var t = generateTags(this.style.prefix || { fg: 'lightblack' });
+ cmd.prefix
+ '{/light-black-fg}' title = (cmd.prefix != null ? t.open + cmd.prefix + t.close + ':' : '') + cmd.text;
+ ':' : '')
+ cmd.text;
len = ((cmd.prefix != null ? cmd.prefix + ':' : '') + cmd.text).length; len = ((cmd.prefix != null ? cmd.prefix + ':' : '') + cmd.text).length;
@ -5944,6 +5987,11 @@ Listbar.prototype.appendItem = function(item, callback) {
if (cmd.callback) { if (cmd.callback) {
//el.on('press', cmd.callback); //el.on('press', cmd.callback);
//this.on('select', function(el) {
// if (el._.cmd.callback) {
// el._.cmd.callback();
// }
//});
if (cmd.keys) { if (cmd.keys) {
this.screen.key(cmd.keys, function(ch, key) { this.screen.key(cmd.keys, function(ch, key) {
self.emit('action', el, self.selected); self.emit('action', el, self.selected);
@ -6144,6 +6192,32 @@ Passbox.prototype.type = 'passbox';
* Helpers * Helpers
*/ */
function generateTags(style, text) {
var open = ''
, close = '';
Object.keys(style).forEach(function(key) {
var val = style[key];
if (typeof val === 'string') {
val = val.replace(/^light(?!-)/, 'light-');
open = '{' + val + '-' + key + '}' + open;
close += '{/' + val + '-' + key + '}';
} else {
open = '{' + key + '}' + open;
close += '{/' + key + '}';
}
});
if (text != null) {
return open + text + close;
}
return {
open: open,
close: close
};
}
function merge(a, b) { function merge(a, b) {
Object.keys(b).forEach(function(key) { Object.keys(b).forEach(function(key) {
a[key] = b[key]; a[key] = b[key];