Comparing version 4.0.0 to 4.1.0
{ | ||
"name": "tty-table", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "Node cli table", | ||
@@ -5,0 +5,0 @@ "main": "src/main.js", |
@@ -77,3 +77,6 @@ # tty-table 端子台 | ||
| footerColor | <code>string</code> | default: terminal default color | | ||
| formatter | <code>function(cellValue, columnIndex, rowIndex, rowData, inputData)</code> | Runs a callback on each cell value in the parent column. <br/>Use `this.style` within function body to style text, i.e. `this.style("mytext", "bold", "green", "underline")`. <br/>Please note that fat arrow functions `() => {}` don't support scope overrides, and this feature won't work within them. For a full list of options, see: [chalk](https://github.com/chalk/chalk). | | ||
| formatter | <code>function(cellValue, columnIndex, rowIndex, rowData, inputData</code> | Runs a callback on each cell value in the parent column. <br/>Please note that fat arrow functions `() => {}` don't support scope overrides, and this feature won't work correctly within them. | | ||
| @formatter configure | <code>function(object)</code> | Configure cell properties. For example: <br/>`this.configure({ truncate: false, align: "left" })` | | ||
| @formatter resetStyle | <code>function(cellValue)</code> | Removes ANSI escape sequences. For example: <br/>`this.resetStyle("[32m myText[39m") // "myText"`<br/>[More here.](https://github.com/tecfu/tty-table/blob/master/examples/truncated-lines.js#L100-L110)) | | ||
| @formatter style | <code>function(cellValue, effect)</code> | Style cell value. For example: <br/>`this.style("mytext", "bold", "green", "underline")`<br/>For a full list of options, see: [chalk](https://github.com/chalk/chalk). | | ||
| headerAlign | <code>string</code> | default: "center" | | ||
@@ -90,3 +93,2 @@ | headerColor | <code>string</code> | default: terminal's default color | | ||
**Example** | ||
@@ -93,0 +95,0 @@ |
@@ -41,2 +41,3 @@ // @TODO split defaults into table and cell settings | ||
headerColor: "yellow", | ||
headerTruncate: false, | ||
isNull: false, // undocumented cell setting | ||
@@ -43,0 +44,0 @@ marginLeft: 2, |
@@ -147,3 +147,5 @@ const stripAnsi = require("strip-ansi") | ||
if (typeof config.truncate === "string") { | ||
const truncKey = (rowType === 'header') ? "headerTruncate" : "truncate" | ||
if (typeof config[truncKey] === "string") { | ||
string = exports.truncate(string, cellOptions, innerWidth) | ||
@@ -194,3 +196,3 @@ } else { | ||
module.exports.truncate = (string, cellOptions, maxWidth) => { | ||
module.exports.truncate = (string, cellOptions, maxWidth, rowType) => { | ||
const stringWidth = wcwidth(string) | ||
@@ -200,7 +202,8 @@ | ||
// @TODO give user option to decide if they want to break words on wrapping | ||
let truncKey = (rowType === 'header') ? "headerTruncate" : "truncate" | ||
string = smartwrap(string, { | ||
width: maxWidth - cellOptions.truncate.length, | ||
width: maxWidth - cellOptions[truncKey].length, | ||
breakword: true | ||
}).split("\n")[0] | ||
string = string + cellOptions.truncate | ||
string = string + cellOptions[truncKey] | ||
} | ||
@@ -207,0 +210,0 @@ |
@@ -212,8 +212,8 @@ const Style = require("./style.js") | ||
let cellValue = null | ||
const formatterMeta = { | ||
reset: false | ||
} | ||
const cellOptions = Object.assign( | ||
{}, | ||
{ | ||
reset: false, | ||
rowType: rowType | ||
}, | ||
config, | ||
@@ -243,3 +243,5 @@ (rowType === "body") ? config.columnSettings[columnIndex] : {}, // ignore columnSettings for footer | ||
cellValue = elem.bind({ | ||
meta: formatterMeta, // `resetStyle` updates to prevent downstream styling | ||
configure: function (object) { | ||
return Object.assign(cellOptions, object) | ||
}, | ||
style: Style.style, | ||
@@ -265,3 +267,5 @@ resetStyle: Style.resetStyle | ||
.bind({ | ||
meta: formatterMeta, // `resetStyle` updates to prevent downstream styling | ||
configure: function (object) { | ||
return Object.assign(cellOptions, object) | ||
}, | ||
style: Style.style, | ||
@@ -284,3 +288,3 @@ resetStyle: Style.resetStyle | ||
// and omit those default styles if the user applied `this.resetStyle` | ||
if (!formatterMeta.reset) { | ||
if (!cellOptions.reset) { | ||
cellValue = Style.colorizeCell(cellValue, cellOptions, rowType) | ||
@@ -290,3 +294,3 @@ } | ||
// textwrap cellValue | ||
const { cell, innerWidth } = Format.wrapCellText(config, cellValue, columnIndex, cellOptions, rowType) | ||
const { cell, innerWidth } = Format.wrapCellText(cellOptions, cellValue, columnIndex, cellOptions, rowType) | ||
@@ -293,0 +297,0 @@ if (rowType === "header") { |
@@ -28,3 +28,3 @@ const chalk = require("chalk") | ||
module.exports.resetStyle = function (str) { | ||
this.meta.reset = true | ||
this.configure({ reset: true }) | ||
return stripAnsi(str) | ||
@@ -31,0 +31,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49078
1060
295