lazily convert colors. other misc color fixes.
This commit is contained in:
parent
5753d7b6ab
commit
d0f99be764
|
@ -3,8 +3,19 @@
|
|||
*/
|
||||
|
||||
// Try to match a hex code to a terminal color as best as possible.
|
||||
// This entire function assumes the terminal user is using the
|
||||
// default xterm colors.
|
||||
exports.matchColor = function(col) {
|
||||
if (col[0] !== '#') return col;
|
||||
if (col[0] !== '#') {
|
||||
return col;
|
||||
}
|
||||
|
||||
if (col.length === 4) {
|
||||
col = col[0]
|
||||
+ col[1] + col[1]
|
||||
+ col[2] + col[2]
|
||||
+ col[3] + col[3];
|
||||
}
|
||||
|
||||
if (exports._cache[col] != null) {
|
||||
return exports._cache[col];
|
||||
|
@ -49,26 +60,6 @@ exports.matchColor = function(col) {
|
|||
|
||||
exports._cache = {};
|
||||
|
||||
// Default VGA-like colors
|
||||
exports.def = [
|
||||
'#000000',
|
||||
'#ee0000',
|
||||
'#00ee00',
|
||||
'#eeee00',
|
||||
'#0000ee',
|
||||
'#ee00ee',
|
||||
'#00eeee',
|
||||
'#eeeeee',
|
||||
'#111111',
|
||||
'#ff0000',
|
||||
'#00ff00',
|
||||
'#ffff00',
|
||||
'#0000ff',
|
||||
'#ff00ff',
|
||||
'#00ffff',
|
||||
'#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.
|
||||
|
@ -164,6 +155,7 @@ exports.ccolors = (function() {
|
|||
|
||||
var colorNames = exports.colorNames = {
|
||||
default: -1,
|
||||
normal: -1,
|
||||
bg: -1,
|
||||
fg: -1,
|
||||
black: 0,
|
||||
|
|
10
lib/tput.js
10
lib/tput.js
|
@ -1373,7 +1373,7 @@ Tput.prototype.parseACS = function() {
|
|||
}
|
||||
|
||||
// See: ~/ncurses/ncurses/tinfo/lib_acs.c: L208
|
||||
Object.keys(acsc).forEach(function(ch) {
|
||||
Object.keys(Tput.acsc).forEach(function(ch) {
|
||||
var acs_chars = self.strings.acs_chars || ''
|
||||
, i = acs_chars.indexOf(ch)
|
||||
, next = acs_chars[i + 1];
|
||||
|
@ -1382,8 +1382,8 @@ Tput.prototype.parseACS = function() {
|
|||
return;
|
||||
}
|
||||
|
||||
self.acsc[ch] = acsc[next];
|
||||
self.acscr[acsc[next]] = ch;
|
||||
self.acsc[ch] = Tput.acsc[next];
|
||||
self.acscr[Tput.acsc[next]] = ch;
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -2115,7 +2115,7 @@ Tput.strings = [
|
|||
|
||||
// DEC Special Character and Line Drawing Set.
|
||||
// Taken from tty.js.
|
||||
var acsc = { // (0
|
||||
Tput.acsc = { // (0
|
||||
'`': '\u25c6', // '◆'
|
||||
'a': '\u2592', // '▒'
|
||||
'b': '\u0009', // '\t'
|
||||
|
@ -2150,7 +2150,7 @@ var acsc = { // (0
|
|||
};
|
||||
|
||||
// ['b', 'c', 'd', 'e', 'h', 'i'].forEach(function(ch) {
|
||||
// delete acsc[ch];
|
||||
// delete Tput.acsc[ch];
|
||||
// });
|
||||
|
||||
/**
|
||||
|
|
|
@ -797,7 +797,7 @@ Screen.prototype._reduceColor = function(col) {
|
|||
if (this.tput) {
|
||||
if (col >= 16 && this.tput.colors <= 16) {
|
||||
col = colors.ccolors[col];
|
||||
if (col == null) col = 0x1ff;
|
||||
if (col == null) col = 0;
|
||||
} else if (col >= 8 && this.tput.colors <= 8) {
|
||||
col -= 8;
|
||||
} else if (col >= 2 && this.tput.colors <= 2) {
|
||||
|
@ -1042,11 +1042,11 @@ Screen.prototype.setEffects = function(el, fel, over, out, effects, temp) {
|
|||
Object.keys(effects).forEach(function(key) {
|
||||
var val = effects[key];
|
||||
if (typeof val === 'string') {
|
||||
effects[key] = colors.convert(val);
|
||||
effects[key] = val;
|
||||
} else if (val && typeof val === 'object' && !Array.isArray(val)) {
|
||||
Object.keys(effects[key]).forEach(function(k) {
|
||||
var v = effects[key][k];
|
||||
effects[key][k] = colors.convert(v);
|
||||
effects[key][k] = v;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -1115,8 +1115,8 @@ function Element(options) {
|
|||
// this.position.padding = options.padding || 0;
|
||||
// this.position.margin = options.margin || 0;
|
||||
|
||||
this.fg = colors.convert(options.fg);
|
||||
this.bg = colors.convert(options.bg);
|
||||
this.fg = options.fg;
|
||||
this.bg = options.bg;
|
||||
this.bold = options.bold;
|
||||
this.underline = options.underline;
|
||||
this.blink = options.blink;
|
||||
|
@ -1132,8 +1132,8 @@ function Element(options) {
|
|||
this.border = options.border;
|
||||
if (this.border) {
|
||||
this.border.type = this.border.type || 'bg';
|
||||
this.border.fg = colors.convert(this.border.fg);
|
||||
this.border.bg = colors.convert(this.border.bg);
|
||||
this.border.fg = this.border.fg;
|
||||
this.border.bg = this.border.bg;
|
||||
this.border.ch = this.border.ch || ' ';
|
||||
}
|
||||
|
||||
|
@ -2053,8 +2053,8 @@ function Line(options) {
|
|||
|
||||
options.border = {
|
||||
type: 'bg',
|
||||
bg: colors.convert(options.bg),
|
||||
fg: colors.convert(options.fg),
|
||||
bg: options.bg,
|
||||
fg: options.fg,
|
||||
ch: !options.type || options.type === 'ascii'
|
||||
? orientation === 'horizontal' ? '─' : '│'
|
||||
: options.ch || ' '
|
||||
|
@ -2090,8 +2090,8 @@ function ScrollableBox(options) {
|
|||
|
||||
this.scrollbar = options.scrollbar;
|
||||
if (this.scrollbar) {
|
||||
this.scrollbar.fg = colors.convert(this.scrollbar.fg);
|
||||
this.scrollbar.bg = colors.convert(this.scrollbar.bg);
|
||||
this.scrollbar.fg = this.scrollbar.fg;
|
||||
this.scrollbar.bg = this.scrollbar.bg;
|
||||
this.scrollbar.ch = this.scrollbar.ch || ' ';
|
||||
}
|
||||
}
|
||||
|
@ -2155,8 +2155,8 @@ function List(options) {
|
|||
this.ritems = [];
|
||||
this.selected = 0;
|
||||
|
||||
this.selectedBg = colors.convert(options.selectedBg);
|
||||
this.selectedFg = colors.convert(options.selectedFg);
|
||||
this.selectedBg = options.selectedBg;
|
||||
this.selectedFg = options.selectedFg;
|
||||
this.selectedBold = options.selectedBold;
|
||||
this.selectedUnderline = options.selectedUnderline;
|
||||
this.selectedBlink = options.selectedBlink;
|
||||
|
@ -2946,8 +2946,8 @@ function ProgressBar(options) {
|
|||
this.filled = +this.filled.slice(0, -1);
|
||||
}
|
||||
this.ch = options.ch || ' ';
|
||||
this.barFg = colors.convert(options.barFg);
|
||||
this.barBg = colors.convert(options.barBg);
|
||||
this.barFg = options.barFg;
|
||||
this.barBg = options.barBg;
|
||||
this.orientation = options.orientation || 'horizontal';
|
||||
}
|
||||
|
||||
|
@ -4045,14 +4045,16 @@ function sattr(obj, fg, bg) {
|
|||
| ((obj.blink ? 4 : 0) << 18)
|
||||
| ((obj.underline ? 2 : 0) << 18))
|
||||
| ((obj.bold ? 1 : 0) << 18)
|
||||
| (fg << 9))
|
||||
| bg;
|
||||
| (colors.convert(fg) << 9))
|
||||
| colors.convert(bg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose
|
||||
*/
|
||||
|
||||
exports.colors = colors;
|
||||
|
||||
exports.Screen = exports.screen = Screen;
|
||||
exports.Box = exports.box = Box;
|
||||
exports.Text = exports.text = Text;
|
||||
|
|
|
@ -10,6 +10,8 @@ screen.append(new blessed.Text({
|
|||
width: '100%',
|
||||
//bg: 'blue',
|
||||
content: '{green-fg}Welcome{/green-fg} to my {red-fg,ul}program{/red-fg,ul}',
|
||||
bg: '#0000ff',
|
||||
// bg: blessed.colors.matchColor('#0000ff'),
|
||||
tags: true,
|
||||
align: 'center'
|
||||
}));
|
||||
|
|
Loading…
Reference in New Issue