hex colors in program. another wrapContent fix.

This commit is contained in:
Christopher Jeffrey 2013-07-15 19:35:36 -05:00
parent 87dc701b46
commit 3332e9d34e
2 changed files with 13 additions and 8 deletions

View File

@ -9,7 +9,8 @@
*/
var EventEmitter = require('events').EventEmitter
, Tput = require('./tput');
, Tput = require('./tput')
, colors = require('./colors');
/**
* Program
@ -1554,7 +1555,9 @@ Program.prototype.text = function(text, attr) {
Program.prototype._attr = function(param, val) {
var self = this
, param = param || 'normal'
, parts = param.split(/\s*[,;]\s*/);
, parts = param.split(/\s*[,;]\s*/)
, color
, m;
if (parts.length > 1) {
parts = parts.map(function(part) {
@ -1571,8 +1574,6 @@ Program.prototype._attr = function(param, val) {
val = false;
}
// tput: TODO
switch (param) {
// attributes
case 'normal':
@ -1754,9 +1755,13 @@ Program.prototype._attr = function(param, val) {
default:
// 256-color fg and bg
var m = /^(\d+) (fg|bg)$/.exec(param);
if (param[0] === '#') {
param = param.replace(/#(?:[0-9a-f]{3}){1,2}/i, colors.matchColor);
}
m = /^(\d+) (fg|bg)$/.exec(param);
if (m) {
var color = +m[1] - 1;
color = +m[1] - 1;
if (val === false) {
return this._attr('default ' + m[2]);

View File

@ -4130,13 +4130,13 @@ function wrapContent(content, width, tags, state) {
while (line[i] && line[i++] !== 'm');
}
if (!line[i]) break;
//if (++total === width) {
if (++total > width) {
if (++total === width) {
// Try to find a space to break on:
if (line[i] !== ' ') {
var j = i;
while (j > i - 10 && j > 0 && line[j] !== ' ') j--;
if (line[j] === ' ') i = j + 1;
else i++;
} else {
i++;
}