mirror of
https://github.com/embarklabs/neo-blessed.git
synced 2025-02-03 14:45:33 +00:00
add warnings for no isatty(), and bad terminfo.
This commit is contained in:
parent
c488c08501
commit
1e57352eee
@ -337,6 +337,8 @@ The screen on which every other node renders.
|
||||
combining characters properly. Blessed simply removes them from an element's
|
||||
content if iTerm2 is detected).
|
||||
- __sendFocus__ - send focus events after mouse is enabled.
|
||||
- __warnings__ - display warnings (such as the output not being a TTY, similar
|
||||
to ncurses).
|
||||
|
||||
##### Properties:
|
||||
|
||||
|
@ -249,6 +249,12 @@ Program.prototype.setupTput = function() {
|
||||
termcap: options.termcap
|
||||
});
|
||||
|
||||
if (tput.error) {
|
||||
nextTick(function() {
|
||||
self.emit('warning', tput.error.message);
|
||||
});
|
||||
}
|
||||
|
||||
this.put = function() {
|
||||
var args = slice.call(arguments)
|
||||
, cap = args.shift();
|
||||
@ -368,6 +374,12 @@ Program.prototype.listen = function() {
|
||||
if (this.output._blessedListened) return;
|
||||
this.output._blessedListened = true;
|
||||
|
||||
if (!this.output.isTTY) {
|
||||
nextTick(function() {
|
||||
self.emit('warning', 'Output is not a TTY');
|
||||
});
|
||||
}
|
||||
|
||||
// Output
|
||||
function resize() {
|
||||
self.cols = self.output.columns;
|
||||
|
@ -68,6 +68,7 @@ Tput.prototype.setup = function() {
|
||||
this.injectTermcap();
|
||||
} catch (e) {
|
||||
if (this.debug) throw e;
|
||||
this.error = new Error('Termcap parse error.');
|
||||
this._useInternalCap(this.terminal);
|
||||
}
|
||||
} else {
|
||||
@ -75,6 +76,7 @@ Tput.prototype.setup = function() {
|
||||
this.injectTerminfo();
|
||||
} catch (e) {
|
||||
if (this.debug) throw e;
|
||||
this.error = new Error('Terminfo parse error.');
|
||||
this._useInternalInfo(this.terminal);
|
||||
}
|
||||
}
|
||||
@ -82,6 +84,7 @@ Tput.prototype.setup = function() {
|
||||
// If there was an error, fallback
|
||||
// to an internally stored terminfo/cap.
|
||||
if (this.debug) throw e;
|
||||
this.error = new Error('Terminfo not found.');
|
||||
this._useXtermInfo();
|
||||
}
|
||||
};
|
||||
|
@ -152,6 +152,10 @@ function Screen(options) {
|
||||
self.emit('blur');
|
||||
});
|
||||
|
||||
this.program.on('warning', function(text) {
|
||||
self.emit('warning', text);
|
||||
});
|
||||
|
||||
this.on('newListener', function fn(type) {
|
||||
if (type === 'keypress' || type.indexOf('key ') === 0 || type === 'mouse') {
|
||||
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.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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user