mirror of
https://github.com/embarklabs/neo-blessed.git
synced 2025-01-10 19:16:20 +00:00
add a scrollable option.
This commit is contained in:
parent
5e2f1061d1
commit
1c9d25780a
@ -267,7 +267,7 @@ Node.prototype.set = function(name, value) {
|
||||
function Screen(options) {
|
||||
var self = this;
|
||||
|
||||
if (!(this instanceof Screen)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new Screen(options);
|
||||
}
|
||||
|
||||
@ -1569,12 +1569,28 @@ Screen.prototype.sigtstp = function(callback) {
|
||||
function Element(options) {
|
||||
var self = this;
|
||||
|
||||
if (!(this instanceof Element)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new Element(options);
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
|
||||
// Workaround to get a `scrollable` option.
|
||||
if (options.scrollable
|
||||
&& !this._ignore
|
||||
&& this.type !== 'scrollable-box'
|
||||
&& this.type !== 'scrollable-text') {
|
||||
Object.getOwnPropertyNames(ScrollableBox.prototype).forEach(function(key) {
|
||||
if (key === 'type') return;
|
||||
Object.defineProperty(this, key,
|
||||
Object.getOwnPropertyDescriptor(ScrollableBox.prototype, key));
|
||||
}, this);
|
||||
this._ignore = true;
|
||||
ScrollableBox.call(this, options);
|
||||
delete this._ignore;
|
||||
return this;
|
||||
}
|
||||
|
||||
Node.call(this, options);
|
||||
|
||||
this.name = options.name;
|
||||
@ -1804,7 +1820,7 @@ Element.prototype._focus = function() {
|
||||
// Find a scrollable ancestor if we have one.
|
||||
var el = this;
|
||||
while (el = el.parent) {
|
||||
if (el.childBase != null) break;
|
||||
if (el.scrollable) break;
|
||||
}
|
||||
|
||||
// If we're in a scrollable element,
|
||||
@ -1906,7 +1922,7 @@ Element.prototype._parseAttr = function(lines) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.childBase == null) {
|
||||
if (!this.scrollable) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2528,7 +2544,7 @@ Element.prototype._getShrinkBox = function(xi, xl, yi, yl) {
|
||||
if (this.position.height == null
|
||||
&& (this.position.top == null
|
||||
|| this.position.bottom == null)
|
||||
&& this.childBase == null) {
|
||||
&& !this.scrollable) {
|
||||
if (this.position.top == null && this.position.bottom != null) {
|
||||
yi = yl - (myl - myi);
|
||||
yi -= this.padding.top + this.padding.bottom;
|
||||
@ -2559,7 +2575,7 @@ Element.prototype._getShrinkContent = function(xi, xl, yi, yl) {
|
||||
if (this.position.height == null
|
||||
&& (this.position.top == null
|
||||
|| this.position.bottom == null)
|
||||
&& this.childBase == null) {
|
||||
&& !this.scrollable) {
|
||||
if (this.position.top == null && this.position.bottom != null) {
|
||||
yi = yl - h - this.iheight;
|
||||
} else {
|
||||
@ -2625,7 +2641,7 @@ Element.prototype._getCoords = function(get) {
|
||||
// Find a scrollable ancestor if we have one.
|
||||
var el = this;
|
||||
while (el = el.parent) {
|
||||
if (el.childBase != null) break;
|
||||
if (el.scrollable) break;
|
||||
}
|
||||
|
||||
// Check to make sure we're visible and
|
||||
@ -2723,7 +2739,7 @@ Element.prototype.render = function() {
|
||||
|
||||
// If we're in a scrollable text box, check to
|
||||
// see which attributes this line starts with.
|
||||
if (this.childBase != null) {
|
||||
if (this.scrollable) {
|
||||
attr = this._clines.attr[Math.min(this.childBase, this._clines.length - 1)];
|
||||
}
|
||||
|
||||
@ -3099,7 +3115,7 @@ Element.prototype.popLine = function(n) {
|
||||
*/
|
||||
|
||||
function Box(options) {
|
||||
if (!(this instanceof Box)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new Box(options);
|
||||
}
|
||||
options = options || {};
|
||||
@ -3115,7 +3131,7 @@ Box.prototype.type = 'box';
|
||||
*/
|
||||
|
||||
function Text(options) {
|
||||
if (!(this instanceof Text)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new Text(options);
|
||||
}
|
||||
options = options || {};
|
||||
@ -3134,7 +3150,7 @@ Text.prototype.type = 'text';
|
||||
function Line(options) {
|
||||
var self = this;
|
||||
|
||||
if (!(this instanceof Line)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new Line(options);
|
||||
}
|
||||
|
||||
@ -3186,7 +3202,7 @@ Line.prototype.type = 'line';
|
||||
function ScrollableBox(options) {
|
||||
var self = this;
|
||||
|
||||
if (!(this instanceof ScrollableBox)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new ScrollableBox(options);
|
||||
}
|
||||
|
||||
@ -3459,7 +3475,7 @@ ScrollableBox.prototype.resetScroll = function() {
|
||||
function List(options) {
|
||||
var self = this;
|
||||
|
||||
if (!(this instanceof List)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new List(options);
|
||||
}
|
||||
|
||||
@ -3760,7 +3776,7 @@ List.prototype.down = function(offset) {
|
||||
*/
|
||||
|
||||
function ScrollableText(options) {
|
||||
if (!(this instanceof ScrollableText)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new ScrollableText(options);
|
||||
}
|
||||
options = options || {};
|
||||
@ -3779,14 +3795,14 @@ ScrollableText.prototype.type = 'scrollable-text';
|
||||
function Form(options) {
|
||||
var self = this;
|
||||
|
||||
if (!(this instanceof Form)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new Form(options);
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
|
||||
options.ignoreKeys = true;
|
||||
ScrollableBox.call(this, options);
|
||||
Box.call(this, options);
|
||||
|
||||
if (options.keys) {
|
||||
this.screen._listenKeys(this);
|
||||
@ -3993,7 +4009,7 @@ Form.prototype.reset = function() {
|
||||
*/
|
||||
|
||||
function Input(options) {
|
||||
if (!(this instanceof Input)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new Input(options);
|
||||
}
|
||||
options = options || {};
|
||||
@ -4011,7 +4027,7 @@ Input.prototype.type = 'input';
|
||||
function Textbox(options) {
|
||||
var self = this;
|
||||
|
||||
if (!(this instanceof Textbox)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new Textbox(options);
|
||||
}
|
||||
|
||||
@ -4175,7 +4191,7 @@ Textbox.prototype.setEditor = function(callback) {
|
||||
*/
|
||||
|
||||
function Textarea(options) {
|
||||
if (!(this instanceof Textarea)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new Textarea(options);
|
||||
}
|
||||
|
||||
@ -4372,7 +4388,7 @@ Textarea.prototype.setEditor = function(callback) {
|
||||
function Button(options) {
|
||||
var self = this;
|
||||
|
||||
if (!(this instanceof Button)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new Button(options);
|
||||
}
|
||||
|
||||
@ -4411,7 +4427,7 @@ Button.prototype.press = function() {
|
||||
*/
|
||||
|
||||
function ProgressBar(options) {
|
||||
if (!(this instanceof ProgressBar)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new ProgressBar(options);
|
||||
}
|
||||
|
||||
@ -4533,7 +4549,7 @@ ProgressBar.prototype.reset = function() {
|
||||
function FileManager(options) {
|
||||
var self = this;
|
||||
|
||||
if (!(this instanceof FileManager)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new FileManager(options);
|
||||
}
|
||||
|
||||
@ -4712,7 +4728,7 @@ FileManager.prototype.reset = function(cwd, callback) {
|
||||
function Checkbox(options) {
|
||||
var self = this;
|
||||
|
||||
if (!(this instanceof Checkbox)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new Checkbox(options);
|
||||
}
|
||||
|
||||
@ -4788,7 +4804,7 @@ Checkbox.prototype.toggle = function() {
|
||||
*/
|
||||
|
||||
function RadioSet(options) {
|
||||
if (!(this instanceof RadioSet)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new RadioSet(options);
|
||||
}
|
||||
options = options || {};
|
||||
@ -4809,7 +4825,7 @@ RadioSet.prototype.type = 'radio-set';
|
||||
function RadioButton(options) {
|
||||
var self = this;
|
||||
|
||||
if (!(this instanceof RadioButton)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new RadioButton(options);
|
||||
}
|
||||
|
||||
@ -4846,7 +4862,7 @@ RadioButton.prototype.toggle = RadioButton.prototype.check;
|
||||
function Prompt(options) {
|
||||
var self = this;
|
||||
|
||||
if (!(this instanceof Prompt)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new Prompt(options);
|
||||
}
|
||||
|
||||
@ -4939,7 +4955,7 @@ Prompt.prototype.type = function(text, value, callback) {
|
||||
function Question(options) {
|
||||
var self = this;
|
||||
|
||||
if (!(this instanceof Question)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new Question(options);
|
||||
}
|
||||
|
||||
@ -5030,7 +5046,7 @@ Question.prototype.ask = function(text, callback) {
|
||||
function Message(options) {
|
||||
var self = this;
|
||||
|
||||
if (!(this instanceof Message)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new Message(options);
|
||||
}
|
||||
|
||||
@ -5073,7 +5089,7 @@ Message.prototype.error = function(text, callback) {
|
||||
function Info(options) {
|
||||
var self = this;
|
||||
|
||||
if (!(this instanceof Info)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new Info(options);
|
||||
}
|
||||
|
||||
@ -5123,7 +5139,7 @@ Info.prototype.display = function(text, callback) {
|
||||
function Loading(options) {
|
||||
var self = this;
|
||||
|
||||
if (!(this instanceof Loading)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new Loading(options);
|
||||
}
|
||||
|
||||
@ -5189,7 +5205,7 @@ Loading.prototype.stop = function() {
|
||||
function PickList(options) {
|
||||
var self = this;
|
||||
|
||||
if (!(this instanceof PickList)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new PickList(options);
|
||||
}
|
||||
|
||||
@ -5223,7 +5239,7 @@ PickList.prototype.pick = function(callback) {
|
||||
function Listbar(options) {
|
||||
var self = this;
|
||||
|
||||
if (!(this instanceof Listbar)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new Listbar(options);
|
||||
}
|
||||
|
||||
@ -5401,7 +5417,7 @@ Listbar.prototype.sel = function(i) {
|
||||
function DirManager(options) {
|
||||
var self = this;
|
||||
|
||||
if (!(this instanceof DirManager)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new DirManager(options);
|
||||
}
|
||||
|
||||
@ -5426,7 +5442,7 @@ DirManager.prototype.type = 'dir-manager';
|
||||
function Passbox(options) {
|
||||
var self = this;
|
||||
|
||||
if (!(this instanceof Passbox)) {
|
||||
if (!(this instanceof Node)) {
|
||||
return new Passbox(options);
|
||||
}
|
||||
|
||||
|
@ -9,9 +9,10 @@ var form = blessed.form({
|
||||
left: 0,
|
||||
top: 0,
|
||||
width: '100%',
|
||||
height: 12,
|
||||
//height: 12,
|
||||
bg: 'green',
|
||||
content: 'foobar',
|
||||
scrollable: true,
|
||||
border_: {
|
||||
type: 'ch',
|
||||
ch: ' ',
|
||||
@ -184,11 +185,12 @@ var box4 = blessed.box({
|
||||
});
|
||||
|
||||
var output = blessed.scrollabletext({
|
||||
parent: screen,
|
||||
parent: form,
|
||||
mouse: true,
|
||||
keys: true,
|
||||
left: 0,
|
||||
top: 12,
|
||||
top: 20,
|
||||
height: 5,
|
||||
width: '100%',
|
||||
bg: 'red',
|
||||
content: 'foobar'
|
||||
|
Loading…
x
Reference in New Issue
Block a user