-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support fixed column widths (#71)
* feat: support fixed column widths * chore: add example for fixed table width * fix: ignore padding when column width is fixed
- Loading branch information
1 parent
c0aee83
commit dbe7be8
Showing
5 changed files
with
160 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {printTable} from '../src/index.js' | ||
|
||
const data = [ | ||
{ | ||
actual: 'This is a long string of the actual test results. '.repeat(50), | ||
expected: 'This is a long string of the expected test results. '.repeat(10), | ||
result: 'Passed', | ||
test: 'Topic', | ||
}, | ||
] | ||
|
||
printTable({ | ||
columns: [ | ||
{key: 'test', width: '10%'}, | ||
{key: 'result', width: '10%'}, | ||
{key: 'expected', width: '40%'}, | ||
{key: 'actual', width: '40%'}, | ||
], | ||
data, | ||
headerOptions: { | ||
formatter: 'capitalCase', | ||
}, | ||
overflow: 'wrap', | ||
title: 'Fixed-Width Columns', | ||
titleOptions: {bold: true}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import ansis from 'ansis' | ||
import terminalLink from 'terminal-link' | ||
|
||
import {TableOptions, printTable} from '../src/index.js' | ||
|
||
const data = [ | ||
{ | ||
age: 20, | ||
employed: ansis.bold('true'), | ||
id: terminalLink('36329', 'https://example.com/36329'), | ||
name: 'Alice', | ||
}, | ||
{ | ||
age: 21, | ||
employed: ansis.bold('true'), | ||
id: terminalLink('49032', 'https://example.com/49032'), | ||
name: ansis.dim('Bob'), | ||
}, | ||
{ | ||
age: 22, | ||
employed: ansis.bold('false'), | ||
id: terminalLink('51786', 'https://example.com/51786'), | ||
name: 'Charlie', | ||
}, | ||
] | ||
|
||
const basic: TableOptions<(typeof data)[number]> = { | ||
borderStyle: 'all', | ||
columns: ['id', {key: 'name', name: 'First Name'}, 'age', 'employed'], | ||
data, | ||
headerOptions: { | ||
bold: true, | ||
color: '#905de8', | ||
formatter: 'sentenceCase', | ||
}, | ||
sort: { | ||
id: 'desc', | ||
}, | ||
verticalAlignment: 'center', | ||
width: '100%', | ||
} | ||
|
||
printTable(basic) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters