This commit is contained in:
Mario GLiewe 2015-01-31 21:21:14 +01:00
commit 96a19b8523
7 changed files with 72 additions and 20 deletions

View File

@ -21,6 +21,8 @@ var blessed = require('blessed');
// Create a screen object. // Create a screen object.
var screen = blessed.screen(); var screen = blessed.screen();
screen.title = 'my window title';
// Create a box perfectly centered horizontally and vertically. // Create a box perfectly centered horizontally and vertically.
var box = blessed.box({ var box = blessed.box({
top: 'center', top: 'center',
@ -194,6 +196,7 @@ The screen on which every other node renders.
- **grabKeys** - whether the focused element grabs all keypresses. - **grabKeys** - whether the focused element grabs all keypresses.
- **lockKeys** - prevent keypresses from being received by any element. - **lockKeys** - prevent keypresses from being received by any element.
- **hover** - the currently hovered element. only set if mouse events are bound. - **hover** - the currently hovered element. only set if mouse events are bound.
- **title** - set or get window title.
##### Events: ##### Events:

View File

@ -15,6 +15,7 @@ if (~argv.indexOf('-h') || ~argv.indexOf('--help')) {
console.log('-s - Show seconds.'); console.log('-s - Show seconds.');
console.log('-n - No leading zero on hours.'); console.log('-n - No leading zero on hours.');
console.log('-d - Show date box.'); console.log('-d - Show date box.');
console.log('--skinny - Skinny text.');
return process.exit(0); return process.exit(0);
} }
@ -64,7 +65,8 @@ var date = blessed.box({
date.hide(); date.hide();
var wid = ~argv.indexOf('--skinny') ? 1 : 2; var wid = ~argv.indexOf('--skinny') ? 1 : 2;
var bch = ' '; // var bch = ' ';
var bch = '│';
var inverse = true; var inverse = true;
// var bch = '*'; // var bch = '*';
@ -1030,7 +1032,7 @@ function updateTime() {
if (~argv.indexOf('-d')) { if (~argv.indexOf('-d')) {
date.show(); date.show();
date.setContent(d.toISOString()); date.setContent(d.toISOString().replace(/\.\d+/, ''));
} }
screen.render(); screen.render();

View File

@ -126,6 +126,8 @@ function emitKey(stream, s) {
} else if (s === '\n') { } else if (s === '\n') {
// enter, should have been called linefeed // enter, should have been called linefeed
key.name = 'enter'; key.name = 'enter';
// linefeed
// key.name = 'linefeed';
} else if (s === '\t') { } else if (s === '\t') {
// tab // tab
@ -298,5 +300,13 @@ function emitKey(stream, s) {
if (key || ch) { if (key || ch) {
stream.emit('keypress', ch, key); stream.emit('keypress', ch, key);
// if (key && key.name === 'return') {
// var nkey = {};
// Object.keys(key).forEach(function(k) {
// nkey[k] = key[k];
// });
// nkey.name = 'enter';
// stream.emit('keypress', ch, nkey);
// }
} }
} }

View File

@ -1477,6 +1477,15 @@ Program.prototype.repeat = function(ch, i) {
return Array(i + 1).join(ch); return Array(i + 1).join(ch);
}; };
Program.prototype.__defineGetter__('title', function() {
return this._title;
});
Program.prototype.__defineSetter__('title', function(title) {
this.setTitle(title);
return this._title;
});
/** /**
* Normal * Normal
*/ */
@ -1798,6 +1807,8 @@ Program.prototype.setG = function(val) {
// OSC Ps ; Pt BEL // OSC Ps ; Pt BEL
// Set Text Parameters. // Set Text Parameters.
Program.prototype.setTitle = function(title) { Program.prototype.setTitle = function(title) {
this._title = title;
if (this.term('screen')) { if (this.term('screen')) {
// Tmux pane // Tmux pane
// if (process.env.TMUX) { // if (process.env.TMUX) {
@ -1805,6 +1816,7 @@ Program.prototype.setTitle = function(title) {
// } // }
return this._write('\x1bk' + title + '\x1b\\'); return this._write('\x1bk' + title + '\x1b\\');
} }
return this._write('\x1b]0;' + title + '\x07'); return this._write('\x1b]0;' + title + '\x07');
}; };
@ -2806,7 +2818,7 @@ Program.prototype.normalBuffer = function() {
}; };
Program.prototype.enableMouse = function() { Program.prototype.enableMouse = function() {
if (this.term('rxvt-unicode')) { if (this.term('rxvt-unicode') || process.env.VTE_VERSION) {
return this.setMouse({ return this.setMouse({
urxvtMouse: true, urxvtMouse: true,
allMotion: true allMotion: true

View File

@ -360,16 +360,25 @@ function Screen(options) {
this._maxListeners = Infinity; this._maxListeners = Infinity;
if (this.options.handleUncaughtExceptions !== false) { Screen.total++;
process.on('uncaughtException', function(err) {
reset();
if (err) console.error(err.stack ? err.stack + '' : err + '');
return process.exit(1);
});
}
process.on('SIGTERM', function() { process.on('uncaughtException', function(err) {
return process.exit(0); if (process.listeners('uncaughtException').length > Screen.total) {
return;
}
reset();
err = err || new Error('Uncaught Exception.');
console.error(err.stack ? err.stack + '' : err + '');
return process.exit(1);
});
['SIGTERM', 'SIGINT', 'SIGQUIT'].forEach(function(signal) {
process.on(signal, function() {
if (process.listeners(signal).length > Screen.total) {
return;
}
return process.exit(0);
});
}); });
process.on('exit', function() { process.on('exit', function() {
@ -398,10 +407,20 @@ function Screen(options) {
Screen.global = null; Screen.global = null;
Screen.total = 0;
Screen.prototype.__proto__ = Node.prototype; Screen.prototype.__proto__ = Node.prototype;
Screen.prototype.type = 'screen'; Screen.prototype.type = 'screen';
Screen.prototype.__defineGetter__('title', function() {
return this.program.title;
});
Screen.prototype.__defineSetter__('title', function(title) {
return this.program.title = title;
});
Screen.prototype.enter = function() { Screen.prototype.enter = function() {
if (this.program.isAlt) return; if (this.program.isAlt) return;
this.program.alternateBuffer(); this.program.alternateBuffer();
@ -1093,8 +1112,7 @@ Screen.prototype.draw = function(start, end) {
// are it does not support UTF8. This is probably // are it does not support UTF8. This is probably
// the "safest" way to do this. Should fix things // the "safest" way to do this. Should fix things
// like sun-color. // like sun-color.
// if ((!this.unicode || this.tput.numbers.U8 !== 1) && ch > '~') { if ((!this.tput.unicode || this.tput.numbers.U8 !== 1) && ch > '~') {
if ((!this.unicode || this.tput.numbers.U8 !== 1) && this.tput.utoa[ch]) {
ch = this.tput.utoa[ch] || '?'; ch = this.tput.utoa[ch] || '?';
} }
} }
@ -4754,8 +4772,8 @@ Form.prototype.reset = function() {
case 'dir-manager': case 'dir-manager':
el.refresh(el.options.cwd); el.refresh(el.options.cwd);
return; return;
case 'passbox': case 'terminal':
el.clearInput(); el.write('');
return; return;
} }
el.children.forEach(fn); el.children.forEach(fn);
@ -6044,6 +6062,14 @@ function Listbar(options) {
Box.call(this, options); Box.call(this, options);
if (!this.style.selected) {
this.style.selected = {};
}
if (!this.style.item) {
this.style.item = {};
}
if (options.commands || options.items) { if (options.commands || options.items) {
this.setItems(options.commands || options.items); this.setItems(options.commands || options.items);
} }
@ -6073,7 +6099,6 @@ function Listbar(options) {
self.emit('action', self.items[self.selected], self.selected); self.emit('action', self.items[self.selected], self.selected);
self.emit('select', self.items[self.selected], self.selected); self.emit('select', self.items[self.selected], self.selected);
var item = self.items[self.selected]; var item = self.items[self.selected];
//item.press();
if (item._.cmd.callback) { if (item._.cmd.callback) {
item._.cmd.callback(); item._.cmd.callback();
} }
@ -6227,7 +6252,6 @@ Listbar.prototype.appendItem = function(item, callback) {
}); });
var el = new Box(options); var el = new Box(options);
//var el = new Button(options);
this._[cmd.text] = el; this._[cmd.text] = el;
cmd.element = el; cmd.element = el;

View File

@ -2,7 +2,7 @@
"name": "blessed", "name": "blessed",
"description": "A curses-like library for node.js.", "description": "A curses-like library for node.js.",
"author": "Christopher Jeffrey", "author": "Christopher Jeffrey",
"version": "0.0.38", "version": "0.0.39",
"main": "./lib/blessed.js", "main": "./lib/blessed.js",
"bin": "./bin/tput.js", "bin": "./bin/tput.js",
"preferGlobal": false, "preferGlobal": false,

View File

@ -2,7 +2,8 @@ var blessed = require('../')
, screen; , screen;
screen = blessed.screen({ screen = blessed.screen({
dump: __dirname + '/logs/widget.log' dump: __dirname + '/logs/widget.log',
title: 'widget test'
}); });
screen.append(blessed.text({ screen.append(blessed.text({