symfony-style-console
Version:
Use the style and utilities of the Symfony Console in Node.js
241 lines (240 loc) • 5.71 kB
TypeScript
import OutputInterface from '../Output/OutputInterface';
import { TableCellInput, TableRowInput } from './TableCellInterface';
import TableStyle from './TableStyle';
export interface TableStyleHash {
[s: string]: TableStyle;
}
/**
* Provides helpers to display a table.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* Original PHP Class
*
* @author Саша Стаменковић <umpirsky@gmail.com>
* @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
* @author Max Grigorian <maxakawizard@gmail.com>
*
* @author Florian Reuschel <florian@loilo.de>
*
* Port to TypeScript
*/
export default class Table {
/**
* Available styles for Table elements.
*/
private static styles;
/**
* Table headers.
*/
private headers;
/**
* Table rows.
*/
private rows;
/**
* Column widths cache.
*/
private effectiveColumnWidths;
/**
* Number of columns cache.
*/
private numberOfColumns;
/**
* Output
*/
private output;
/**
* TableStyle
*/
private style;
/**
* Column Styles
*/
private columnStyles;
/**
* User set column widths
*/
private columnWidths;
constructor(output: OutputInterface);
/**
* Sets a style definition.
*
* @param name The style name
* @param style A TableStyle instance
*/
static setStyleDefinition(name: string, style: TableStyle): void;
/**
* Gets a style definition by name.
*
* @param name The style name
* @return TableStyle
*/
static getStyleDefinition(name: string): TableStyle;
private static initStyles;
/**
* Sets table style.
*
* @param name The style name or a TableStyle instance
* @return this
*/
setStyle(name: TableStyle | string): this;
/**
* Gets the current table style.
*
* @return TableStyle
*/
getStyle(): TableStyle;
/**
* Sets table column style.
*
* @param columnIndex Column index
* @param name The style name or a TableStyle instance
*
* @return this
*/
setColumnStyle(columnIndex: number, name: TableStyle | string): this;
/**
* Gets the current style for a column.
*
* If style was not set, it returns the global table style.
*
* @param columnIndex Column index
*
* @return TableStyle
*/
getColumnStyle(columnIndex: number): TableStyle;
/**
* Sets the minimum width of a column.
*
* @param columnIndex Column index
* @param width Minimum column width in characters
*
* @return this
*/
setColumnWidth(columnIndex: number, width: number): this;
/**
* Sets the minimum width of all columns.
*
* @param widths
*
* @return this
*/
setColumnWidths(widths: number[]): this;
setHeaders(headers: TableCellInput[] | TableCellInput[][]): this;
setRows(rows: TableRowInput[]): this;
addRows(rows: TableRowInput[]): this;
addRow(row: TableRowInput): this;
setRow(column: number, row: TableRowInput): this;
/**
* Renders table to output.
*
* Example:
* +---------------+-----------------------+------------------+
* | ISBN | Title | Author |
* +---------------+-----------------------+------------------+
* | 99921-58-10-7 | Divine Comedy | Dante Alighieri |
* | 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens |
* | 960-425-059-0 | The Lord of the Rings | J. R. R. Tolkien |
* +---------------+-----------------------+------------------+
*/
render(): void;
/**
* Gets number of columns by row.
*
* @param row
*
* @return int
*/
getNumberOfColumns(row: TableCellInput[]): number;
/**
* Gets list of columns for the given row.
*
* @param array row
*
* @return array
*/
getRowColumns(row: TableCellInput[]): number[];
/**
* Gets column width.
*
* @return int
*/
getColumnSeparatorWidth(): number;
/**
* Gets cell width.
*
* @param row
* @param column
*
* @return int
*/
getCellWidth(row: TableCellInput[], column: number): number;
/**
* Renders horizontal header separator.
*
* Example: +-----+-----------+-------+
*/
private renderRowSeparator;
/**
* Renders vertical column separator.
*/
private renderColumnSeparator;
/**
* Renders table row.
*
* Example: | 9971-5-0210-0 | A Tale of Two Cities | Charles Dickens |
*
* @param row
* @param cellFormat
*/
private renderRow;
/**
* Renders table cell with padding.
*
* @param row
* @param column
* @param cellFormat
*/
private renderCell;
/**
* Calculate number of columns for this table.
*/
private calculateNumberOfColumns;
private buildTableRows;
/**
* fill rows that contains rowspan > 1.
*
* @param inputRows
* @param line
*
* @return array
*/
private fillNextRows;
/**
* fill cells for a row that contains colspan > 1.
*
* @param row
*
* @return array
*/
private fillCells;
/**
* @param rows
* @param line
*
* @return array
*/
private copyRow;
/**
* Calculates columns widths.
*
* @param array rows
*/
private calculateColumnsWidth;
/**
* Called after rendering to cleanup cache data.
*/
private cleanup;
private resolveStyle;
}