### Install cli-table3 Source: https://github.com/cli-table/cli-table3/blob/master/README.md Install the cli-table3 package using npm. ```bash npm install cli-table3 ``` -------------------------------- ### Complex Layout with Multi-line RowSpan Content Source: https://github.com/cli-table/cli-table3/blob/master/advanced-usage.md An advanced example demonstrating multi-line content within `rowSpan` cells in a complex table layout. ```javascript let table = new Table({ style: { head: [], border: [] } }); table.push( [ { content: 'hello', colSpan: 2 }, { rowSpan: 2, colSpan: 2, content: 'sup\nman\nhey' }, { rowSpan: 3, content: 'hi\nyo' }, ], [{ content: 'howdy', colSpan: 2 }], ['o', 'k', '', ''] ); ``` -------------------------------- ### Add Hyperlinks to CLI Table Cells Source: https://github.com/cli-table/cli-table3/blob/master/basic-usage.md Supports hyperlinking cell content using the `href` option. Links are not displayed in documentation examples. ```javascript const table = new Table({ colWidths: [11, 5, 5], style: { border: [], head: [] }, wordWrap: true, wrapOnWordBoundary: false, }); const href = 'http://example.com'; table.push( [{ content: 'Text Link', href }, { content: 'Hello Link', href }, { href }], [{ href, colSpan: 3 }] ); ``` -------------------------------- ### Span Columns Above Normal Cells Source: https://github.com/cli-table/cli-table3/blob/master/advanced-usage.md Use `colSpan` to make a cell span across multiple columns. This example shows `colSpan` applied to cells that appear above normal cells. ```javascript let table = new Table({ style: { head: [], border: [] } }); table.push( [{ colSpan: 2, content: 'greetings' }], [{ colSpan: 2, content: 'greetings' }], ['hello', 'howdy'] ); ``` -------------------------------- ### Getting Table Width Source: https://context7.com/cli-table/cli-table3/llms.txt Access the read-only `table.width` property to get the rendered width of the table in terminal characters. This is useful for centering output or fitting content within a terminal viewport. ```javascript const Table = require('cli-table3'); const table = new Table({ head: ['Col A', 'Col B'], colWidths: [12, 12], style: { head: [], border: [] }, }); table.push(['val1', 'val2']); console.log(`Table is ${table.width} characters wide`); ``` -------------------------------- ### Span Rows on the Left Side Source: https://github.com/cli-table/cli-table3/blob/master/advanced-usage.md Utilize `rowSpan` to make a cell extend across multiple rows. This example places `rowSpan` cells on the left side of the table. ```javascript let table = new Table({ style: { head: [], border: [] } }); table.push( [{ rowSpan: 2, content: 'greetings' }, { rowSpan: 2, content: 'greetings', vAlign: 'center' }, 'hello'], ['howdy'] ); ``` -------------------------------- ### Create a Basic Table Source: https://github.com/cli-table/cli-table3/blob/master/basic-usage.md Initializes a table with headers and pushes data. By default, headers are red and borders are grey. ```javascript // By default, headers will be red, and borders will be grey let table = new Table({ head: ['a', 'b'] }); table.push(['c', 'd']); ``` -------------------------------- ### Create Horizontal Table with Headers and Fixed Widths Source: https://context7.com/cli-table/cli-table3/llms.txt Instantiate a Table with options for headers, column widths, and styles. Rows are added using the push method. The toString() method renders the table. ```javascript const Table = require('cli-table3'); // Horizontal table with headers and fixed column widths const table = new Table({ head: ['Name', 'Version', 'Description'], colWidths: [20, 10, 40], style: { head: ['cyan'], // header text color border: ['grey'], // border color }, }); table.push( ['cli-table3', '0.7.0', 'Pretty unicode tables for the command line'], ['ansis', '3.10.0', 'ANSI color and style library'] ); console.log(table.toString()); ``` -------------------------------- ### Update Documentation Source: https://github.com/cli-table/cli-table3/blob/master/README.md Generate or update the project's documentation by running the `yarn docs` command. ```bash $ yarn docs ``` -------------------------------- ### Create Cross Table (Row and Column Headers) Source: https://context7.com/cli-table/cli-table3/llms.txt Construct a hybrid table with both column headers (in options.head) and row headers (as keys in row objects). The first column header must be an empty string. ```javascript const Table = require('cli-table3'); const table = new Table({ head: ['', 'Q1', 'Q2', 'Q3'], style: { 'padding-left': 0, 'padding-right': 0, head: [], border: [] }, }); table.push( { 'Revenue': ['$1M', '$1.2M', '$1.4M'] }, { 'Expenses': ['$0.8M', '$0.9M', '$1M'] } ); console.log(table.toString()); ``` -------------------------------- ### Run Test Coverage Report Source: https://github.com/cli-table/cli-table3/blob/master/README.md Execute all tests and generate coverage reports using the `yarn test:coverage` command. ```bash $ yarn test:coverage ``` -------------------------------- ### Enable debugging with `debug` option and `Table.reset()` Source: https://context7.com/cli-table/cli-table3/llms.txt Use the `debug` option to capture diagnostic messages about cell layout. Messages are stored in `table.messages` and should be printed after `toString()`. Call `Table.reset()` between tables when rendering multiple tables with debug mode enabled to clear previous messages. ```javascript const Table = require('cli-table3'); const table = new Table({ debug: 1 }); // 1 = WARN level table.push( [{ rowSpan: 2, content: 'A' }, 'B'], ['C'] ); console.log(table.toString()); // Print debug messages collected during render table.messages.forEach((msg) => console.log('[DEBUG]', msg)); // When rendering multiple tables in debug mode, reset between them Table.reset(); const table2 = new Table({ debug: true }); table2.push(['x', 'y']); console.log(table2.toString()); table2.messages.forEach((msg) => console.log('[DEBUG]', msg)); Table.reset(); ``` -------------------------------- ### Enable Word Wrapping Source: https://github.com/cli-table/cli-table3/blob/master/basic-usage.md Sets `wordWrap` to true to wrap text on word boundaries within fixed-width columns. Text exceeding column width will be truncated. ```javascript let table = new Table({ style: { border: [], header: [] }, colWidths: [7, 9], // Requires fixed column widths wordWrap: true, }); table.push([ 'Hello how are you?', 'I am fine thanks! Looooooong', ['Words that exceed', 'the colWidth will', 'be truncated.'].join('\n'), ['Text is only', 'wrapped for', 'fixed width', 'columns.'].join('\n'), ]); ``` -------------------------------- ### Create Vertical Table (Key-Value Pairs) Source: https://context7.com/cli-table/cli-table3/llms.txt Generate a two-column key-value table by pushing rows as objects with a single key-value pair. Styles for padding and borders can be customized. ```javascript const Table = require('cli-table3'); const table = new Table({ style: { 'padding-left': 0, 'padding-right': 0, head: [], border: [] }, }); table.push( { 'Node version': 'v18.12.0' }, { 'Platform': 'linux' }, { 'Arch': 'x64' } ); console.log(table.toString()); ``` -------------------------------- ### Colorize Table Background with Hex Source: https://github.com/cli-table/cli-table3/blob/master/README.md Specify a background color for the entire table using a hex color code with the `bgHex` method. Ensure the 'ansis' library is imported for color manipulation. ```javascript var { green } = require('ansis'); var Table = require('cli-table3'); var table = new Table({ head: ['Name', 'Age'], style: { border: ['hex(#FFD700)'], head: ['hex(#FFA500)', 'italic'], } }); table.push( ['Walter White', '50'], ['Jesse Pinkman', '24'], ); var output = green.bgHex('#3d239d')(table.toString()); // <- add a background to the table console.log(output); ``` -------------------------------- ### Create Vertical Table Source: https://github.com/cli-table/cli-table3/blob/master/README.md Instantiate and populate a vertical table where keys represent headers and values represent cell content. ```javascript var Table = require('cli-table3'); var table = new Table(); table.push( { 'Some key': 'Some value' } , { 'Another key': 'Another value' } ); console.log(table.toString()); ``` -------------------------------- ### Create Cross Table Source: https://github.com/cli-table/cli-table3/blob/master/README.md Instantiate a cross table with a specified header row (including an initial empty string) and data rows where keys are left headers and values are arrays of row values. ```javascript var Table = require('cli-table3'); var table = new Table({ head: ["", "Top Header 1", "Top Header 2"] }); table.push( { 'Left Header 1': ['Value Row 1 Col 1', 'Value Row 1 Col 2'] } , { 'Left Header 2': ['Value Row 2 Col 1', 'Value Row 2 Col 2'] } ); console.log(table.toString()); ``` -------------------------------- ### Rendering Table to String Source: https://context7.com/cli-table/cli-table3/llms.txt Use the `table.toString()` method to render the complete table, including headers, as a unicode string with ANSI color codes. This string can be piped to `console.log` or any output stream. ```javascript const Table = require('cli-table3'); const table = new Table({ head: ['Package', 'Status'], style: { head: [], border: [] }, }); table.push(['lodash', 'up to date'], ['express', 'outdated']); const output = table.toString(); console.log(output); ``` -------------------------------- ### Staggered RowSpan Layout Source: https://github.com/cli-table/cli-table3/blob/master/advanced-usage.md Creates a staggered table layout using `rowSpan` where cells do not align perfectly in a grid, demonstrating flexible cell placement. ```javascript let table = new Table({ style: { head: [], border: [] } }); table.push( [{ content: 'a', rowSpan: 2 }, 'b'], [{ content: 'c', rowSpan: 2 }], ['d'] ); ``` -------------------------------- ### Run Tests on File Changes Source: https://github.com/cli-table/cli-table3/blob/master/README.md Continuously run tests and automatically re-run them whenever a file is modified using the `yarn test:watch` command. ```bash $ yarn test:watch ``` -------------------------------- ### Create Horizontal Table Source: https://github.com/cli-table/cli-table3/blob/master/README.md Instantiate and populate a horizontal table with headers and data rows. The table is an array, allowing standard array manipulation methods. ```javascript var Table = require('cli-table3'); // instantiate var table = new Table({ head: ['TH 1 label', 'TH 2 label'] , colWidths: [100, 200] }); // table is an Array, so you can `push`, `unshift`, `splice` and friends table.push( ['First value', 'Second value'] , ['First value', 'Second value'] ); console.log(table.toString()); ``` -------------------------------- ### Create Vertical Tables Source: https://github.com/cli-table/cli-table3/blob/master/basic-usage.md Generates vertical tables by pushing objects that specify key-value pairs. Styles can be adjusted for minimal padding. ```javascript let table = new Table({ style: { 'padding-left': 0, 'padding-right': 0, head: [], border: [] }, }); table.push( { 'v0.1': 'Testing something cool' }, { 'v0.1': 'Testing something cool' } ); ``` -------------------------------- ### Create Horizontal Table without Colors Source: https://context7.com/cli-table/cli-table3/llms.txt Create a horizontal table with specified headers and column widths, disabling default colors for headers and borders. Rows are added using the push method. ```javascript const Table = require('cli-table3'); const table = new Table({ head: ['Rel', 'Change', 'By', 'When'], style: { head: [], border: [] }, // disable colors colWidths: [6, 21, 25, 17], }); table.push( ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '7 minutes ago'], ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '8 minutes ago'] ); console.log(table.toString()); ``` -------------------------------- ### Mix RowSpan and ColSpan for Complex Layouts Source: https://github.com/cli-table/cli-table3/blob/master/advanced-usage.md Combine `rowSpan` and `colSpan` to create intricate table structures with cells spanning both rows and columns. ```javascript let table = new Table({ style: { head: [], border: [] } }); table.push( [ { content: 'hello', colSpan: 2 }, { rowSpan: 2, colSpan: 2, content: 'sup' }, { rowSpan: 3, content: 'hi' }, ], [{ content: 'howdy', colSpan: 2 }], ['o', 'k', '', ''] ); ``` -------------------------------- ### Create Cross Tables Source: https://github.com/cli-table/cli-table3/blob/master/basic-usage.md Constructs cross tables, which are similar to vertical tables but include an empty string for the first header. Styles are cleared to prevent color output. ```javascript let table = new Table({ head: ['', 'Header 1', 'Header 2'], style: { 'padding-left': 0, 'padding-right': 0, head: [], border: [] }, }); // clear styles to prevent color output table.push( { 'Header 3': ['v0.1', 'Testing something cool'] }, { 'Header 4': ['v0.1', 'Testing something cool'] } ); ``` -------------------------------- ### Styling Table Headers and Borders with Colors Source: https://context7.com/cli-table/cli-table3/llms.txt Apply ANSI colors, styles, or hex truecolor codes to headers and borders using the `style.head` and `style.border` options. Colors are applied using the `ansis` library. ```javascript const Table = require('cli-table3'); // Named colors and styles const table1 = new Table({ head: ['Name', 'Score'], style: { head: ['green', 'bold'], // bold green header text border: ['grey'], // grey border }, }); table1.push(['Alice', '95'], ['Bob', '87']); console.log(table1.toString()); ``` ```javascript // Truecolor hex values const table2 = new Table({ head: ['Name', 'Score'], style: { head: ['hex(#FFA500)', 'italic'], // italic orange header border: ['hex(#FFD700)'], // gold border }, }); table2.push(['Alice', '95']); console.log(table2.toString()); ``` ```javascript // Colorize individual cells using ansis directly const ansis = require('ansis'); const table3 = new Table({ head: ['Status', 'Service'], style: { head: ['cyan'], border: ['grey'] }, }); table3.push( [ansis.green('● OK'), 'API Gateway'], [ansis.red('● FAILED'), 'Auth Service'], [ansis.yellow('● WARN'), 'Cache Layer'] ); console.log(table3.toString()); ``` -------------------------------- ### Configure Word Wrapping in CLI Table Source: https://github.com/cli-table/cli-table3/blob/master/basic-usage.md Set `wrapOnWordBoundary` to `false` to disable word boundary wrapping. Ensure `colWidths` are greater than 2. ```javascript const table = new Table({ style: { border: [], header: [] }, colWidths: [3, 3], // colWidths must all be greater than 2!!!! wordWrap: true, wrapOnWordBoundary: false, }); table.push(['Wrap', 'Text']); ``` -------------------------------- ### Specify First Row Column Width Source: https://github.com/cli-table/cli-table3/blob/master/advanced-usage.md You can specify a column width for only the first row; other rows will automatically adjust to fit content. This allows for initial layout control while maintaining content adaptability. ```javascript let table = new Table({ colWidths: [4], style: { head: [], border: [] }, }); table.push( [{ colSpan: 2, content: 'hello there' }], ['hi', { hAlign: 'center', content: 'hi' }] ); ``` -------------------------------- ### Enable Table Debugging Source: https://github.com/cli-table/cli-table3/blob/master/README.md Enable debugging for table rendering by setting the `debug` option to 1. Debug messages will be stored in the `messages` property of the table instance. Use `Table.reset()` to clear messages between table renderings. ```javascript var table = new Table({ debug: 1 }); table.push([{}, {},}); // etc. console.log(table.toString()); table.messages.forEach((message) => console.log(message)); ``` -------------------------------- ### Add Hyperlinks with href Source: https://context7.com/cli-table/cli-table3/llms.txt Add clickable terminal hyperlinks by setting the `href` property in a cell object. Terminals supporting OSC 8 will render the cell content as a link. ```javascript const Table = require('cli-table3'); const table = new Table({ colWidths: [20, 30], style: { border: [], head: [] }, wordWrap: true, wrapOnWordBoundary: false, }); const url = 'https://github.com/cli-table/cli-table3'; table.push( [ { content: 'GitHub Repository', href: url }, { content: 'cli-table/cli-table3', href: url }, ], [ { href: url, colSpan: 2 }, // displays the URL itself as linked text ] ); console.log(table.toString()); ``` -------------------------------- ### Colorize Table Cells with Ansis Source: https://github.com/cli-table/cli-table3/blob/master/README.md Utilize the 'ansis' library to apply individual colors or styles to specific table cells. Named colors, hex codes, and bright variants are supported. ```javascript var ansi = require('ansis'); var Table = require('cli-table3'); var table = new Table({ head: ['Name', 'Age'], style: { border: ['hex(#FFD700)'], head: ['hex(#FFA500)', 'italic'], } }); table.push( // apply a color to cells [ansi.green('Walter White'), ansi.red('50')], [ansi.hex('#FF69B4')('Jesse Pinkman'), ansi.blueBright('24')], ); console.log(table.toString()); ``` -------------------------------- ### Enable Text Wrapping with wordWrap Source: https://context7.com/cli-table/cli-table3/llms.txt Automatic text wrapping within fixed-width columns is enabled with `wordWrap: true`. Use `wrapOnWordBoundary: false` for character-boundary wrapping. ```javascript const Table = require('cli-table3'); const table = new Table({ style: { border: [], head: [] }, colWidths: [15, 15], wordWrap: true, wrapOnWordBoundary: true, // default: true }); table.push([ 'This is a long sentence that will be wrapped at word boundaries.', 'Short text', ]); console.log(table.toString()); // ┌───────────────┬───────────────┐ // │ This is a │ Short text │ // │ long sentence │ │ // │ that will be │ │ // │ wrapped at │ │ // │ word │ │ // │ boundaries. │ │ // └───────────────┴───────────────┘ // Character-boundary wrapping const table2 = new Table({ style: { border: [], head: [] }, colWidths: [5, 5], wordWrap: true, wrapOnWordBoundary: false, }); table2.push(['Wrap', 'Text']); console.log(table2.toString()); // ┌─────┬─────┐ // │ Wra │ Tex │ // │ p │ t │ // └─────┴─────┘ ``` -------------------------------- ### Using Colors in Content Strings Source: https://github.com/cli-table/cli-table3/blob/master/advanced-usage.md Colors can be used directly within content strings. The library correctly calculates column widths even when colors are present, ensuring proper table rendering. ```javascript let table = new Table({ colWidths: [5], style: { head: [], border: [] }, }); table.push([colors.red('hello')]); ``` -------------------------------- ### Multi-line Content in RowSpan Cells Source: https://github.com/cli-table/cli-table3/blob/master/advanced-usage.md Shows how multi-line content within `rowSpan` cells automatically flows across the spanned rows. ```javascript let table = new Table({ style: { head: [], border: [] } }); table.push( ['hello', { rowSpan: 2, content: 'greetings\nfriends' }, { rowSpan: 2, content: 'greetings\nfriends' }], ['howdy'] ); ``` -------------------------------- ### Colorize Entire Table Body Source: https://github.com/cli-table/cli-table3/blob/master/README.md Apply a single color to the entire table output by wrapping the `toString()` result with an ansis color function. ```javascript var { green } = require('ansis'); // use a named import when using a few colors var Table = require('cli-table3'); var table = new Table({ head: ['Name', 'Age'], style: { border: ['hex(#FFD700)'], head: ['hex(#FFA500)', 'italic'], } }); table.push( ['Walter White', '50'], ['Jesse Pinkman', '24'], ); var output = green(table.toString()); // colorize the whole table console.log(output); ``` -------------------------------- ### Automatic Empty Cell Creation Source: https://github.com/cli-table/cli-table3/blob/master/advanced-usage.md The layout manager automatically inserts empty cells to complete the table structure when using `rowSpan` and `colSpan`, even with sparse data. ```javascript let table = new Table({ style: { head: [], border: [] } }); //notice we only create 3 cells here, but the table ends up having 6. table.push( [{ content: 'a', rowSpan: 3, colSpan: 2 }, 'b'], [], [{ content: 'c', rowSpan: 2, colSpan: 2 }], [] ); ``` -------------------------------- ### Stylize Table with Custom Borders Source: https://github.com/cli-table/cli-table3/blob/master/basic-usage.md Applies custom border characters to stylize the table's appearance. Colors are also disabled for consistency. ```javascript let table = new Table({ chars: { top: '═', 'top-mid': '╤', 'top-left': '╔', 'top-right': '╗', bottom: '═', 'bottom-mid': '╧', 'bottom-left': '╚', 'bottom-right': '╝', left: '║', 'left-mid': '╟', right: '║', 'right-mid': '╢', }, style: { head: [], border: [], }, }); table.push( ['foo', 'bar', 'baz'], ['frob', 'bar', 'quuz'] ); ``` -------------------------------- ### Fix Row Height with rowHeights Option Source: https://github.com/cli-table/cli-table3/blob/master/advanced-usage.md Use the `rowHeights` option to set a fixed height for rows. Content exceeding the specified height will be truncated, showing an ellipsis. ```javascript let table = new Table({ rowHeights: [2], style: { head: [], border: [] }, }); table.push(['hello\nhi\nsup']); ``` -------------------------------- ### Setting Row Heights Source: https://context7.com/cli-table/cli-table3/llms.txt Control the height of specific rows in lines using the `rowHeights` option. Content exceeding the fixed height will be truncated with a ellipsis (`…`) on the last visible line. ```javascript const Table = require('cli-table3'); const table = new Table({ rowHeights: [3, 1], // row 0: 3 lines tall, row 1: 1 line tall style: { head: [], border: [] }, }); table.push( ['Line 1\nLine 2\nLine 3\nLine 4 (truncated)'], ['Only one line visible here - extra content truncated'] ); console.log(table.toString()); ``` -------------------------------- ### Span Cells with colSpan and rowSpan Source: https://context7.com/cli-table/cli-table3/llms.txt Use `colSpan` and `rowSpan` properties within cell objects to make cells span multiple columns or rows. Vertical alignment is controlled with `vAlign`. ```javascript const Table = require('cli-table3'); const table = new Table({ style: { head: [], border: [] } }); table.push( // First row: one cell spanning 3 columns [{ colSpan: 3, content: 'System Status', hAlign: 'center' }], // Second row: left cell spans 2 rows, others are normal [{ rowSpan: 2, content: 'Services', vAlign: 'center' }, 'API', 'OK' ], [ 'Database', 'OK' ], // Mixed colSpan + rowSpan [{ colSpan: 2, content: 'All systems operational' }, 'Healthy'] ); console.log(table.toString()); ``` -------------------------------- ### Automatic Column Width Adjustment Source: https://github.com/cli-table/cli-table3/blob/master/advanced-usage.md When `colWidths` is not specified, the layout manager automatically widens rows to fit the content. This is useful for tables where content length is unpredictable. ```javascript let table = new Table({ style: { head: [], border: [] } }); table.push( [{ colSpan: 2, content: 'hello there' }], ['hi', 'hi'] ); ``` -------------------------------- ### Align Cells with hAlign and vAlign Source: https://context7.com/cli-table/cli-table3/llms.txt Control horizontal and vertical alignment per cell or globally using `colAligns` and `rowAligns` table options. Cell-specific `hAlign` overrides global settings. ```javascript const Table = require('cli-table3'); const table = new Table({ head: ['Left', 'Center', 'Right'], colWidths: [10, 10, 10], colAligns: ['left', 'center', 'right'], // default alignment per column style: { head: [], border: [] }, }); table.push( ['foo', 'bar', 'baz'], [ { content: 'override', hAlign: 'right' }, // per-cell override 'mid', { content: 'L', hAlign: 'left' }, ] ); console.log(table.toString()); ``` -------------------------------- ### Colorize Table Border Source: https://github.com/cli-table/cli-table3/blob/master/README.md Apply colors to the table border using truecolor hex codes. This can be combined with header styling. ```javascript style: { border: ['hex(#FFD700)'], head: ['hex(#FFA500)', 'italic'], } ``` -------------------------------- ### Span Columns Below Normal Cells Source: https://github.com/cli-table/cli-table3/blob/master/advanced-usage.md Demonstrates `colSpan` where the spanned cells appear below normal cells in the table structure. ```javascript let table = new Table({ style: { head: [], border: [] } }); table.push( ['hello', 'howdy'], [{ colSpan: 2, content: 'greetings' }], [{ colSpan: 2, content: 'greetings' }] ); ``` -------------------------------- ### Null Column Width for Auto-Widening Source: https://github.com/cli-table/cli-table3/blob/master/advanced-usage.md A column with a null column width will be automatically widened to fit content. This provides flexibility when certain columns should expand based on their content. ```javascript let table = new Table({ colWidths: [null, 4], style: { head: [], border: [] }, }); table.push( [{ colSpan: 2, content: 'hello there' }], [{ hAlign: 'right', content: 'hi' }, 'hi'] ); ``` -------------------------------- ### Custom Border Characters Source: https://context7.com/cli-table/cli-table3/llms.txt Override default border characters using the `chars` option to change the table's visual style. Unspecified keys retain their defaults. ```javascript const Table = require('cli-table3'); // Double-line box-drawing style const table = new Table({ chars: { 'top': '═', 'top-mid': '╤', 'top-left': '╔', 'top-right': '╗', 'bottom': '═', 'bottom-mid': '╧', 'bottom-left': '╚', 'bottom-right':'╝', 'left': '║', 'left-mid': '╟', 'right': '║', 'right-mid': '╢', 'mid': '─', 'mid-mid': '┼', 'middle': '│', }, style: { head: [], border: [] }, }); table.push(['foo', 'bar', 'baz'], ['frob', 'bar', 'quuz']); console.log(table.toString()); ``` ```javascript // Borderless / compact style (no horizontal separators between rows) const compact = new Table({ chars: { 'mid': '', 'left-mid': '', 'mid-mid': '', 'right-mid': '' }, style: { head: [], border: [] }, }); compact.push(['foo', 'bar'], ['frobnicate', 'baz']); console.log(compact.toString()); ``` -------------------------------- ### Disable Colors in Table Source: https://github.com/cli-table/cli-table3/blob/master/basic-usage.md Disables colors for headers and borders, making it suitable for unit tests and plain text output. Column widths can also be set. ```javascript // For most of these examples, and most of the unit tests we disable colors. // It makes unit tests easier to write/understand, and allows these pages to // display the examples as text instead of screen shots. let table = new Table({ head: ['Rel', 'Change', 'By', 'When'], style: { head: [], //disable colors in header cells border: [], //disable colors for the border }, colWidths: [6, 21, 25, 17], //set the widths of each column (optional) }); table.push( ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '7 minutes ago'], ['v0.1', 'Testing something cool', 'rauchg@gmail.com', '8 minutes ago'] ); ``` -------------------------------- ### Use ANSI Colors and Multi-line Text Source: https://github.com/cli-table/cli-table3/blob/master/basic-usage.md Styles cell content using ANSI colors and allows text to span multiple lines within cells. Border and header colors are disabled. ```javascript let table = new Table({ style: { border: [], header: [] } }); table.push([colors.red('Hello\nhow\nare\nyou?'), colors.blue('I\nam\nfine\nthanks!')]); ``` -------------------------------- ### Custom Table Characters Source: https://github.com/cli-table/cli-table3/blob/master/README.md Define custom characters for table borders to alter the table's appearance. Empty strings can be used to omit certain separators. ```javascript var table = new Table({ chars: { 'top': '═' , 'top-mid': '╤' , 'top-left': '╔' , 'top-right': '╗' , 'bottom': '═' , 'bottom-mid': '╧' , 'bottom-left': '╚' , 'bottom-right': '╝' , 'left': '║' , 'left-mid': '╟' , 'mid': '─' , 'mid-mid': '┼' , 'right': '║' , 'right-mid': '╢' , 'middle': '│' } }); table.push( ['foo', 'bar', 'baz'] , ['frob', 'bar', 'quuz'] ); console.log(table.toString()); ``` ```javascript var table = new Table({ chars: {'mid': '', 'left-mid': '', 'mid-mid': '', 'right-mid': ''} }); table.push( ['foo', 'bar', 'baz'] , ['frobnicate', 'bar', 'quuz'] ); console.log(table.toString()); ``` ```javascript var table = new Table({ chars: { 'top': '' , 'top-mid': '' , 'top-left': '' , 'top-right': '' , 'bottom': '' , 'bottom-mid': '' , 'bottom-left': '' , 'bottom-right': '' , 'left': '' , 'left-mid': '' , 'mid': '' , 'mid-mid': '' , 'right': '' , 'right-mid': '' , 'middle': ' ' }, style: { 'padding-left': 0, 'padding-right': 0 } }); table.push( ['foo', 'bar', 'baz'] , ['frobnicate', 'bar', 'quuz'] ); console.log(table.toString()); ``` -------------------------------- ### Colorize Table Header Text Source: https://github.com/cli-table/cli-table3/blob/master/README.md Style table header text using base 16 named colors or truecolor hex codes. Styles like 'bold' and 'italic' can be combined. ```javascript var table = new Table({ head: ['Name', 'Age'], style: { head: ['green', 'bold'], } }); table.push(['Walter White', '50']); console.log(table.toString()); ``` ```javascript style: { head: ['hex(#FFA500)', 'italic'], } ``` -------------------------------- ### Use `compact: true` to omit horizontal separators Source: https://context7.com/cli-table/cli-table3/llms.txt Set `compact: true` in the style options to remove horizontal separator lines between data rows for a more condensed table. This is useful for saving vertical space. ```javascript const Table = require('cli-table3'); const table = new Table({ head: ['Name', 'Value'], style: { head: [], border: [], compact: true }, }); table.push(['alpha', '1'], ['beta', '2'], ['gamma', '3']); console.log(table.toString()); ``` -------------------------------- ### Span Rows on the Right Side Source: https://github.com/cli-table/cli-table3/blob/master/advanced-usage.md Illustrates `rowSpan` applied to cells on the right side of the table, allowing them to span multiple rows. ```javascript let table = new Table({ style: { head: [], border: [] } }); table.push( ['hello', { rowSpan: 2, content: 'greetings' }, { rowSpan: 2, content: 'greetings', vAlign: 'bottom' }], ['howdy'] ); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.