commandbox.system.util

Class TablePrinter

lucee.Component
    extended by commandbox.system.util.TablePrinter

Copyright Since 2014 CommandBox by Ortus Solutions, Corp www.coldbox.org | www.ortussolutions.com I print tables

Class Attributes:
  • synchronized : false
  •  
  • accessors : false
  •  
  • persistent : false
  •  
  • author : Brad Wood, Luis Majano, Scott Steinbeck
  •  
    Property Summary
    type property default serializable required
    any convert


    • access = public
    • returntype = any
    • inject = DataConverter
    true false
    any job


    • access = public
    • returntype = any
    • inject = InteractiveJob
    true false
    any print


    • access = public
    • returntype = any
    • inject = PrintBuffer
    true false
    any shell


    • access = public
    • returntype = any
    • inject = shell
    true false
    Method Summary
    private array autoFormatData(array headers, array data)
         Formats the data into an array of arrays.
    private struct calculateColumnData(numeric index, string header, array data, [array headerNames='[runtime expression]'])
         Calculates the max width of a column across the header and all rows of data.
    any cellHasFormattingEmbedded([any data])
    private array getStructValues(struct item, array headers)
         Gets the required keys from the struct of data and returns them as an array of arrays.
    private string padRight(string text, numeric maxWidth, [string padChar=' '])
         Adds characters to the right of a string until the string reaches a certain length.
    string print(any data='[runtime expression]', [any includedHeaders=''], [any headerNames=''], [boolean debug='false'], [any width='-1'])
         Outputs a table to the screen.
    private void printData(array data, array headerData)
         Prints all the data for the table.
    private void printHeader(array headerData)
         Prints the header row for the table.
    private void printRow(array row, array headerData)
         Prints a single row of data for the table.
    private void printRowSeparator(array headerData)
         Prints the separator between rows.
    private void printTableEnd(array headerData)
         Prints the final line of the table.
    array processHeaders(array headers, array data, [any headerNames='[runtime expression]'], [any width='-1'])
         Outputs a table to the screen.
    any stringify([any data])
     
    Methods inherited from class lucee.Component
    None

    Property Detail

    convert

    property any convert

    Attributes:
    access - public
    required - false
    returntype - any
    inject - DataConverter
    serializable - true

    job

    property any job

    Attributes:
    access - public
    required - false
    returntype - any
    inject - InteractiveJob
    serializable - true

    print

    property any print

    Attributes:
    access - public
    required - false
    returntype - any
    inject - PrintBuffer
    serializable - true

    shell

    property any shell

    Attributes:
    access - public
    required - false
    returntype - any
    inject - shell
    serializable - true

    Method Detail

    autoFormatData

    private array autoFormatData(array headers, array data)

    Formats the data into an array of arrays. If the data is an array of structs, the headers will be used to convert it to an array of arrays.

    Parameters:
    headers - The column headers for the table. Used as the lookup keys if data is an array of structs.
    data - The data for the table.

    calculateColumnData

    private struct calculateColumnData(numeric index, string header, array data, [array headerNames='[runtime expression]'])

    Calculates the max width of a column across the header and all rows of data. This value is used to layout the table correctly.

    Parameters:
    index - The index of the column we are calculating.
    header - The column header.
    data - The data for the table.
    headerNames - Header name overrides

    cellHasFormattingEmbedded

    public any cellHasFormattingEmbedded([any data])

    Parameters:
    data

    getStructValues

    private array getStructValues(struct item, array headers)

    Gets the required keys from the struct of data and returns them as an array of arrays.

    Parameters:
    item - The struct of data representing a single row.
    headers - The column headers for the table used to get the needed data from the item in the correct order.

    padRight

    private string padRight(string text, numeric maxWidth, [string padChar=' '])

    Adds characters to the right of a string until the string reaches a certain length. If the text is already greater than or equal to the maxWidth, the text is returned unchanged.

    Parameters:
    text - The text to pad.
    maxWidth - The number of characters to pad up to.
    padChar - The character to use to pad the text.

    print

    public string print(any data='[runtime expression]', [any includedHeaders=''], [any headerNames=''], [boolean debug='false'], [any width='-1'])

    Outputs a table to the screen

    Parameters:
    data - Any type of data for the table. Each item in the array may either be an array in the correct order matching the number of headers or a struct with keys matching the headers.
    includedHeaders - A list of headers to include. Used for query inputs
    headerNames - An list/array of column headers to use instead of the default
    debug - Only print out the names of the columns and the first row values
    width - Override the terminal width

    printData

    private void printData(array data, array headerData)

    Prints all the data for the table.

    Parameters:
    data - The data for the table.
    headerData - The array of column headers for the table with their corresponding max widths.

    printHeader

    private void printHeader(array headerData)

    Prints the header row for the table.

    Parameters:
    headerData - The array of column headers for the table with their corresponding max widths.

    printRow

    private void printRow(array row, array headerData)

    Prints a single row of data for the table.

    Parameters:
    row - A single row of data for the table.
    headerData - The array of column headers for the table with their corresponding max widths.

    printRowSeparator

    private void printRowSeparator(array headerData)

    Prints the separator between rows.

    Parameters:
    headerData - The array of column headers for the table with their corresponding max widths.

    printTableEnd

    private void printTableEnd(array headerData)

    Prints the final line of the table.

    Parameters:
    headerData - The array of column headers for the table with their corresponding max widths.

    processHeaders

    public array processHeaders(array headers, array data, [any headerNames='[runtime expression]'], [any width='-1'])

    Outputs a table to the screen

    Parameters:
    headers - An array of column headers,
    data - An array of data for the table.
    headerNames - Header name overrides
    width

    stringify

    public any stringify([any data])

    Parameters:
    data