misc fixes. remove dead code.
This commit is contained in:
parent
1a62484509
commit
6ec3534fcd
20
README.md
20
README.md
|
@ -8,6 +8,7 @@ terminals. See the `tput` example below.
|
|||
|
||||
Blessed also includes an extremely high-level widget library.
|
||||
|
||||
|
||||
## Example Usage
|
||||
|
||||
This will actually parse the xterm terminfo and compile every
|
||||
|
@ -68,6 +69,7 @@ program.bg('!black');
|
|||
program.feed();
|
||||
```
|
||||
|
||||
|
||||
## High-level Documentation
|
||||
|
||||
### Example
|
||||
|
@ -110,6 +112,7 @@ screen.on('keypress', function(ch, key) {
|
|||
screen.render();
|
||||
```
|
||||
|
||||
|
||||
### Widgets
|
||||
|
||||
Blessed comes with a number of high-level widgets so you can avoid all the
|
||||
|
@ -182,6 +185,7 @@ The screen on which every other node renders.
|
|||
- **bottom**, **rbottom** - bottom offset, always zero.
|
||||
- **grabKeys** - whether the focused element grabs all keypresses.
|
||||
- **lockKeys** - prevent keypresses from being received by any element.
|
||||
- **hover** - the currently hovered element. only set if mouse events are bound.
|
||||
|
||||
##### Events:
|
||||
|
||||
|
@ -228,7 +232,7 @@ The base element.
|
|||
- **label** - a simple text label for the element.
|
||||
- **align** - text alignment: `left`, `center`, or `right`.
|
||||
- **shrink** - shrink/flex/grow to content width during render.
|
||||
- **padding** - amount of padding on the inside of the element.
|
||||
- **padding** - amount of padding on the inside of the element. **(does not work...yet)**
|
||||
|
||||
##### Properties:
|
||||
|
||||
|
@ -283,7 +287,8 @@ The base element.
|
|||
|
||||
A box element which draws a simple box containing `content` or other elements.
|
||||
|
||||
Inherits all options, properties, events, and methods from Box.
|
||||
Inherits all options, properties, events, and methods from Element.
|
||||
|
||||
|
||||
#### Text (from Element)
|
||||
|
||||
|
@ -428,9 +433,9 @@ A box which allows text input.
|
|||
##### Methods:
|
||||
|
||||
- inherits all from Input.
|
||||
- **setInput(callback)** - grab key events and start reading text from the
|
||||
- **readInput(callback)** - grab key events and start reading text from the
|
||||
keyboard. takes a callback which receives the final value.
|
||||
- **setEditor(callback)** - open text editor in `$EDITOR`, read the output from
|
||||
- **readEditor(callback)** - open text editor in `$EDITOR`, read the output from
|
||||
the resulting file. takes a callback which receives the final value.
|
||||
|
||||
|
||||
|
@ -532,6 +537,7 @@ console.log(box.top);
|
|||
|
||||
This still needs to be tested a bit, but it should work.
|
||||
|
||||
|
||||
### Content
|
||||
|
||||
Every element can have text content via `setContent`. If `tags: true` was
|
||||
|
@ -549,7 +555,7 @@ box.setContent('hello {red-fg}{green-bg}{bold}world{/}');
|
|||
|
||||
Newlines and alignment are also possible in content.
|
||||
|
||||
```
|
||||
``` js
|
||||
box.setContent('hello\n'
|
||||
+ '{right}world{/right}\n'
|
||||
+ '{center}foo{/center}');
|
||||
|
@ -570,6 +576,7 @@ content and the colors will be parsed appropriately.
|
|||
This means that while `{red-fg}foo{/red-fg}` produces `^[[31mfoo^[[39m`, you
|
||||
could just feed `^[[31mfoo^[[39m` directly to the content.
|
||||
|
||||
|
||||
### Rendering
|
||||
|
||||
To actually render the screen buffer, you must call `render`.
|
||||
|
@ -583,6 +590,7 @@ Elements are rendered with the lower elements in the children array being
|
|||
painted first. In terms of the painter's algorithm, the lowest indicies in the
|
||||
array are the furthest away, just like in the DOM.
|
||||
|
||||
|
||||
### Optimization and CSR
|
||||
|
||||
You may notice a lot of terminal apps (e.g. mutt, irssi, vim, ncmpcpp) don't
|
||||
|
@ -618,11 +626,13 @@ Outputting:
|
|||
| line 4 |
|
||||
```
|
||||
|
||||
|
||||
### Testing
|
||||
|
||||
- For an interactive test, see `test/widget.js`.
|
||||
- For a less interactive position testing, see `test/widget-pos.js`.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
Copyright (c) 2013, Christopher Jeffrey. (MIT License)
|
||||
|
|
|
@ -49,6 +49,7 @@ exports.matchColor = function(col) {
|
|||
|
||||
exports._cache = {};
|
||||
|
||||
// Default VGA-like colors
|
||||
exports.def = [
|
||||
'#000000',
|
||||
'#ee0000',
|
||||
|
@ -68,6 +69,10 @@ exports.def = [
|
|||
'#ffffff'
|
||||
];
|
||||
|
||||
// XTerm Colors
|
||||
// These were actually tough to track down. The xterm source only uses color
|
||||
// keywords. The X11 source needed to be examined to find the actual values.
|
||||
// They then had to be mapped to rgb values and then converted to hex values.
|
||||
exports.xterm = [
|
||||
'#000000', // black
|
||||
'#cd0000', // red3
|
||||
|
@ -88,6 +93,7 @@ exports.xterm = [
|
|||
];
|
||||
|
||||
// Seed all 256 colors. Assume xterm defaults.
|
||||
// Ported from the xterm color generation script.
|
||||
exports.colors = (function() {
|
||||
var cols = exports.colors = []
|
||||
, _cols = exports.vcolors = []
|
||||
|
@ -195,6 +201,7 @@ exports.convert = function(color) {
|
|||
|
||||
// Map higher colors to the first 8 colors.
|
||||
// This allows translation of high colors to low colors on 8-color terminals.
|
||||
// Why the hell did I do this by hand?
|
||||
exports.ccolors = {
|
||||
blue: [
|
||||
4,
|
||||
|
|
|
@ -845,6 +845,7 @@ Program.prototype.tabSet = function() {
|
|||
};
|
||||
|
||||
// ESC 7 Save Cursor (DECSC).
|
||||
Program.prototype.sc =
|
||||
Program.prototype.saveCursor = function() {
|
||||
this.savedX = this.x || 1;
|
||||
this.savedY = this.y || 1;
|
||||
|
@ -853,6 +854,7 @@ Program.prototype.saveCursor = function() {
|
|||
};
|
||||
|
||||
// ESC 8 Restore Cursor (DECRC).
|
||||
Program.prototype.rc =
|
||||
Program.prototype.restoreCursor = function() {
|
||||
this.x = this.savedX || 1;
|
||||
this.y = this.savedY || 1;
|
||||
|
@ -2134,8 +2136,8 @@ Program.prototype.setScrollRegion = function(top, bottom) {
|
|||
|
||||
// CSI s
|
||||
// Save cursor (ANSI.SYS).
|
||||
Program.prototype.sc =
|
||||
Program.prototype.saveCursor = function() {
|
||||
Program.prototype.scA =
|
||||
Program.prototype.saveCursorA = function() {
|
||||
this.savedX = this.x;
|
||||
this.savedY = this.y;
|
||||
if (this.tput) return this.put.sc();
|
||||
|
@ -2144,8 +2146,8 @@ Program.prototype.saveCursor = function() {
|
|||
|
||||
// CSI u
|
||||
// Restore cursor (ANSI.SYS).
|
||||
Program.prototype.rc =
|
||||
Program.prototype.restoreCursor = function() {
|
||||
Program.prototype.rcA =
|
||||
Program.prototype.restoreCursorA = function() {
|
||||
this.x = this.savedX || 1;
|
||||
this.y = this.savedY || 1;
|
||||
if (this.tput) return this.put.rc();
|
||||
|
|
135
lib/widget.js
135
lib/widget.js
|
@ -205,8 +205,8 @@ Node.prototype.gon = function(type, callback) {
|
|||
, events = this._events || {}
|
||||
, listeners = (events[type] || []).slice();
|
||||
|
||||
return this.on(type, function fn(ch, key) {
|
||||
if (callback(ch, key) === true) {
|
||||
return this.on(type, function() {
|
||||
if (callback.apply(this, arguments) === true) {
|
||||
self._events[type] = listeners;
|
||||
}
|
||||
});
|
||||
|
@ -249,7 +249,7 @@ function Screen(options) {
|
|||
bottom: this.bottom = this.rbottom = 0
|
||||
};
|
||||
|
||||
//this.focused = null;
|
||||
// this.focused = null;
|
||||
this.hover = null;
|
||||
this.history = [];
|
||||
this.clickable = [];
|
||||
|
@ -264,14 +264,14 @@ function Screen(options) {
|
|||
this.program.on('resize', function() {
|
||||
self.alloc();
|
||||
self.render();
|
||||
//self.emit('resize');
|
||||
// self.emit('resize');
|
||||
(function emit(el) {
|
||||
el.emit('resize');
|
||||
if (el.children) {
|
||||
el.children.forEach(emit);
|
||||
}
|
||||
})(self);
|
||||
//self.emitDescendants('resize');
|
||||
// self.emitDescendants('resize');
|
||||
});
|
||||
|
||||
this.program.alternateBuffer();
|
||||
|
@ -302,9 +302,11 @@ function Screen(options) {
|
|||
|
||||
this.on('newListener', function fn(type) {
|
||||
if (type === 'keypress' || type === 'mouse') {
|
||||
self.removeListener('newListener', fn);
|
||||
if (type === 'keypress') self._listenKeys();
|
||||
if (type === 'mouse') self._listenMouse();
|
||||
// if (self._listenedKeys && self._listenedMouse) {
|
||||
// self.removeListener('newListener', fn);
|
||||
// }
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -328,9 +330,7 @@ Screen.prototype._listenMouse = function(el) {
|
|||
|
||||
this.program.enableMouse();
|
||||
|
||||
//this.on('element click', function(el) {
|
||||
// el.focus();
|
||||
//});
|
||||
// this.on('element click', el.focus.bind(el));
|
||||
|
||||
this.program.on('mouse', function(data) {
|
||||
if (self.lockKeys) return;
|
||||
|
@ -345,12 +345,10 @@ Screen.prototype._listenMouse = function(el) {
|
|||
, ret;
|
||||
|
||||
for (; i < self.clickable.length; i++) {
|
||||
//for (i = self.clickable.length - 1; i >= 0; i--) {
|
||||
el = self.clickable[i];
|
||||
if (!el.visible) continue;
|
||||
|
||||
// Get the true coordinates.
|
||||
//ret = el.render(true);
|
||||
ret = el._lastPos;
|
||||
if (!ret) continue;
|
||||
left = ret.xi;
|
||||
|
@ -358,12 +356,6 @@ Screen.prototype._listenMouse = function(el) {
|
|||
width = ret.xl - ret.xi;
|
||||
height = ret.yl - ret.yi;
|
||||
|
||||
// left = el.left + (el.border ? 1 : 0);
|
||||
// top = el.top + (el.border ? 1 : 0);
|
||||
// if (el.parent.childBase != null) top -= el.parent.childBase;
|
||||
// width = el.width;
|
||||
// height = el.height;
|
||||
|
||||
if (data.x > left && data.x <= left + width
|
||||
&& data.y > top && data.y <= top + height) {
|
||||
el.emit('mouse', data);
|
||||
|
@ -391,8 +383,12 @@ Screen.prototype._listenMouse = function(el) {
|
|||
}
|
||||
}
|
||||
|
||||
//if (data.action === 'mousemove' && self.hover && !set) {
|
||||
if ((data.action === 'mousemove' || data.action === 'mousedown' || data.action === 'mouseup') && self.hover && !set) {
|
||||
// Just mouseover?
|
||||
if ((data.action === 'mousemove'
|
||||
|| data.action === 'mousedown'
|
||||
|| data.action === 'mouseup')
|
||||
&& self.hover
|
||||
&& !set) {
|
||||
self.hover.emit('mouseout', data);
|
||||
self.emit('element mouseout', self.hover, data);
|
||||
self.hover = null;
|
||||
|
@ -402,49 +398,51 @@ Screen.prototype._listenMouse = function(el) {
|
|||
});
|
||||
};
|
||||
|
||||
// TODO: Bubble events.
|
||||
// TODO: Bubble and capture events throughout the tree.
|
||||
Screen.prototype._listenKeys = function(el) {
|
||||
var self = this;
|
||||
|
||||
if (el) {
|
||||
if (!~this.input.indexOf(el)) {
|
||||
// Listen for click, but do not enable
|
||||
// mouse if it's not enabled yet.
|
||||
if (el && !~this.input.indexOf(el)) {
|
||||
// Listen for click, but do not enable
|
||||
// mouse if it's not enabled yet.
|
||||
if (el.options.autoFocus !== false) {
|
||||
var lm = this._listenedMouse;
|
||||
this._listenedMouse = true;
|
||||
//this._listenMouse(el);
|
||||
if (el.options.autoFocus !== false) {
|
||||
el.on('click', el.focus.bind(el));
|
||||
}
|
||||
el.on('click', el.focus.bind(el));
|
||||
this._listenedMouse = lm;
|
||||
|
||||
this.input.push(el);
|
||||
}
|
||||
this.input.push(el);
|
||||
}
|
||||
|
||||
if (this._listenedKeys) return;
|
||||
this._listenedKeys = true;
|
||||
|
||||
// NOTE: The event emissions used to be reversed:
|
||||
// element + screen
|
||||
// They are now:
|
||||
// screen + element
|
||||
// After the first keypress emitted, the handler
|
||||
// checks to make sure grabKeys, lockKeys, and focused
|
||||
// weren't changed, and handles those situations appropriately.
|
||||
this.program.on('keypress', function(ch, key) {
|
||||
if (self.lockKeys) return;
|
||||
var focused = self.focused;
|
||||
if (!self.grabKeys) {
|
||||
|
||||
var focused = self.focused
|
||||
, grabKeys = self.grabKeys;
|
||||
|
||||
if (!grabKeys) {
|
||||
self.emit('keypress', ch, key);
|
||||
}
|
||||
|
||||
// If something changed from the screen key handler, stop.
|
||||
if (self.grabKeys !== grabKeys || self.lockKeys) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (~self.input.indexOf(focused)) {
|
||||
focused.emit('keypress', ch, key);
|
||||
}
|
||||
});
|
||||
|
||||
//this.program.on('keypress', function(ch, key) {
|
||||
// if (self.lockKeys) return;
|
||||
// if (~self.input.indexOf(self.focused)) {
|
||||
// self.focused.emit('keypress', ch, key);
|
||||
// }
|
||||
// if (!self.grabKeys) {
|
||||
// self.emit('keypress', ch, key);
|
||||
// }
|
||||
//});
|
||||
};
|
||||
|
||||
Screen.prototype.__defineGetter__('cols', function() {
|
||||
|
@ -918,11 +916,11 @@ function Element(options) {
|
|||
|
||||
this.on('mouseout', function() {
|
||||
// XXX Workaround
|
||||
if (0) if (self.parent.type === 'list'
|
||||
&& self === self.parent.items[self.parent.selected]
|
||||
&& self.bg === self.parent.selectedBg) {
|
||||
return;
|
||||
}
|
||||
// if (self.parent.type === 'list'
|
||||
// && self === self.parent.items[self.parent.selected]
|
||||
// && self.bg === self.parent.selectedBg) {
|
||||
// return;
|
||||
// }
|
||||
if (self._bg != null) self.bg = self._bg;
|
||||
self.screen.render();
|
||||
});
|
||||
|
@ -937,20 +935,24 @@ function Element(options) {
|
|||
}
|
||||
});
|
||||
|
||||
this.__h = {};
|
||||
|
||||
this.on('mouseover', function() {
|
||||
Object.keys(effects).forEach(function(key) {
|
||||
var val = effects[key];
|
||||
if (self['__h_' + key] == null) self['__h_' + key] = self[key];
|
||||
if (self.__h[key] == null) {
|
||||
self.__h[key] = self[key];
|
||||
}
|
||||
self[key] = val;
|
||||
});
|
||||
self.screen.render();
|
||||
});
|
||||
|
||||
this.on('mouseout', function() {
|
||||
if (self._bg != null) self.bg = self._bg;
|
||||
Object.keys(effects).forEach(function(key) {
|
||||
var val = effects[key];
|
||||
if (self['__h_' + key] != null) self[key] = self['__h_' + key];
|
||||
if (self.__h[key] != null) {
|
||||
self[key] = self.__h[key];
|
||||
}
|
||||
});
|
||||
self.screen.render();
|
||||
});
|
||||
|
@ -1937,7 +1939,7 @@ function List(options) {
|
|||
self.screen.render();
|
||||
return;
|
||||
}
|
||||
if (key.name === 'enter' || (options.vi && key.name === 'l')) {
|
||||
if (key.name === 'enter' || (options.vi && key.name === 'l' && !key.shift)) {
|
||||
self.emit('action', self.items[self.selected], self.selected);
|
||||
self.emit('select', self.items[self.selected], self.selected);
|
||||
return;
|
||||
|
@ -1981,6 +1983,7 @@ function List(options) {
|
|||
return;
|
||||
}
|
||||
if (options.vi && key.name === 'l' && key.shift) {
|
||||
// XXX This goes one too far on lists with an odd number of items.
|
||||
self.down(self.childBase
|
||||
+ Math.min(self.height - (self.border ? 2 : 0), this.items.length)
|
||||
- self.selected);
|
||||
|
@ -2293,6 +2296,8 @@ Textbox.prototype.__proto__ = Input.prototype;
|
|||
|
||||
Textbox.prototype.type = 'textbox';
|
||||
|
||||
Textbox.prototype.input =
|
||||
Textbox.prototype.readInput =
|
||||
Textbox.prototype.setInput = function(callback) {
|
||||
var self = this;
|
||||
|
||||
|
@ -2396,6 +2401,8 @@ Textbox.prototype.render = function(stop) {
|
|||
return this._render(stop);
|
||||
};
|
||||
|
||||
Textbox.prototype.editor =
|
||||
Textbox.prototype.readEditor =
|
||||
Textbox.prototype.setEditor = function(callback) {
|
||||
var self = this;
|
||||
|
||||
|
@ -2856,15 +2863,15 @@ function sattr(obj, fg, bg) {
|
|||
* Expose
|
||||
*/
|
||||
|
||||
exports.Screen = Screen;
|
||||
exports.Box = Box;
|
||||
exports.Text = Text;
|
||||
exports.Line = Line;
|
||||
exports.ScrollableBox = ScrollableBox;
|
||||
exports.List = List;
|
||||
exports.ScrollableText = ScrollableText;
|
||||
exports.Input = Input;
|
||||
exports.Textbox = Textbox;
|
||||
exports.Textarea = Textarea;
|
||||
exports.Button = Button;
|
||||
exports.ProgressBar = ProgressBar;
|
||||
exports.Screen = exports.screen = Screen;
|
||||
exports.Box = exports.box = Box;
|
||||
exports.Text = exports.text = Text;
|
||||
exports.Line = exports.line = Line;
|
||||
exports.ScrollableBox = exports.scrollablebox = ScrollableBox;
|
||||
exports.List = exports.list = List;
|
||||
exports.ScrollableText = exports.scrollabletext = ScrollableText;
|
||||
exports.Input = exports.input = Input;
|
||||
exports.Textbox = exports.textbox = Textbox;
|
||||
exports.Textarea = exports.textarea = Textarea;
|
||||
exports.Button = exports.button = Button;
|
||||
exports.ProgressBar = exports.progressbar = ProgressBar;
|
||||
|
|
|
@ -229,12 +229,12 @@ screen.on('keypress', function(ch, key) {
|
|||
: screen.focusNext();
|
||||
}
|
||||
if (key.name === 'i') {
|
||||
return input.setInput(function(err, value) {
|
||||
return input.readInput(function(err, value) {
|
||||
if (value) screen.children[0].setContent(value);
|
||||
});
|
||||
}
|
||||
if (key.name === 'e') {
|
||||
return input.setEditor(function(err, value) {
|
||||
return input.readEditor(function(err, value) {
|
||||
if (value) screen.children[0].setContent(value);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue