add warnings for no isatty(), and bad terminfo.

This commit is contained in:
Christopher Jeffrey 2015-07-21 19:10:46 -07:00
parent c488c08501
commit 1e57352eee
4 changed files with 45 additions and 0 deletions

View File

@ -337,6 +337,8 @@ The screen on which every other node renders.
combining characters properly. Blessed simply removes them from an element's combining characters properly. Blessed simply removes them from an element's
content if iTerm2 is detected). content if iTerm2 is detected).
- __sendFocus__ - send focus events after mouse is enabled. - __sendFocus__ - send focus events after mouse is enabled.
- __warnings__ - display warnings (such as the output not being a TTY, similar
to ncurses).
##### Properties: ##### Properties:

View File

@ -249,6 +249,12 @@ Program.prototype.setupTput = function() {
termcap: options.termcap termcap: options.termcap
}); });
if (tput.error) {
nextTick(function() {
self.emit('warning', tput.error.message);
});
}
this.put = function() { this.put = function() {
var args = slice.call(arguments) var args = slice.call(arguments)
, cap = args.shift(); , cap = args.shift();
@ -368,6 +374,12 @@ Program.prototype.listen = function() {
if (this.output._blessedListened) return; if (this.output._blessedListened) return;
this.output._blessedListened = true; this.output._blessedListened = true;
if (!this.output.isTTY) {
nextTick(function() {
self.emit('warning', 'Output is not a TTY');
});
}
// Output // Output
function resize() { function resize() {
self.cols = self.output.columns; self.cols = self.output.columns;

View File

@ -68,6 +68,7 @@ Tput.prototype.setup = function() {
this.injectTermcap(); this.injectTermcap();
} catch (e) { } catch (e) {
if (this.debug) throw e; if (this.debug) throw e;
this.error = new Error('Termcap parse error.');
this._useInternalCap(this.terminal); this._useInternalCap(this.terminal);
} }
} else { } else {
@ -75,6 +76,7 @@ Tput.prototype.setup = function() {
this.injectTerminfo(); this.injectTerminfo();
} catch (e) { } catch (e) {
if (this.debug) throw e; if (this.debug) throw e;
this.error = new Error('Terminfo parse error.');
this._useInternalInfo(this.terminal); this._useInternalInfo(this.terminal);
} }
} }
@ -82,6 +84,7 @@ Tput.prototype.setup = function() {
// If there was an error, fallback // If there was an error, fallback
// to an internally stored terminfo/cap. // to an internally stored terminfo/cap.
if (this.debug) throw e; if (this.debug) throw e;
this.error = new Error('Terminfo not found.');
this._useXtermInfo(); this._useXtermInfo();
} }
}; };

View File

@ -152,6 +152,10 @@ function Screen(options) {
self.emit('blur'); self.emit('blur');
}); });
this.program.on('warning', function(text) {
self.emit('warning', text);
});
this.on('newListener', function fn(type) { this.on('newListener', function fn(type) {
if (type === 'keypress' || type.indexOf('key ') === 0 || type === 'mouse') { if (type === 'keypress' || type.indexOf('key ') === 0 || type === 'mouse') {
if (type === 'keypress' || type.indexOf('key ') === 0) self._listenKeys(); if (type === 'keypress' || type.indexOf('key ') === 0) self._listenKeys();
@ -347,6 +351,30 @@ Screen.prototype.postEnter = function() {
this.debugLog.key(['q', 'escape'], self.debugLog.toggle); this.debugLog.key(['q', 'escape'], self.debugLog.toggle);
this.key('f12', self.debugLog.toggle); this.key('f12', self.debugLog.toggle);
} }
if (this.options.warnings) {
this.on('warning', function(text) {
var warning = new Box({
screen: self,
parent: self,
left: 'center',
top: 'center',
width: 30,
height: 'shrink',
align: 'center',
valign: 'middle',
border: 'line',
label: ' {red-fg}{bold}WARNING{/} ',
content: '{bold}' + text + '{/bold}',
tags: true
});
self.render();
setTimeout(function() {
warning.destroy();
self.render();
}, 1500).unref();
});
}
}; };
Screen.prototype.destroy = function() { Screen.prototype.destroy = function() {