commandbox.system.util

Class Print

lucee.Component
    extended by commandbox.system.util.Print
Direct Known Subclasses:
PrintBuffer

Copyright Since 2014 CommandBox by Ortus Solutions, Corp www.coldbox.org | www.ortussolutions.com I am a helper object for creating pretty ANSI-formatted text in the shell. I use onMissingMethod to allow for nice, readable methods that contain combinations of text and background colors as well as text formatting. Ex. print.Line() print.text( 'Hello World' ); print.boldText( 'Hello World' ); print.line( 'Hello World' ); print.redLine( 'Hello World' ); print.redOnWhiteLine( 'Hello World' ); print.redOnWhiteBold( 'Hello World' ); print.boldBlinkingUnderscoredBlueTextOnRedBackground( 'Test' ); If you want to modify formatting at runtime, pass a second parameter of additional text that will be appended to the method name upon processing. print.text( 'Hello World', 'blue' ); print.text( 'Hello World', statusColor ); print.text( 'Hello World', ( status == 'running' ? 'green' : 'red' ) ); Indent each carriage return with two spaces like so: print.indentedLine( 'Hello World' );

Class Attributes:
  • synchronized : false
  •  
  • accessors : false
  •  
  • persistent : false
  •  
  • author : Brad Wood, Luis Majano, Denny Valliant
  •  
    Property Summary
    type property default serializable required
    any JSONService


    • access = public
    • returntype = any
    • inject = JSONService
    true false
    any colors256Data


    • access = public
    • returntype = any
    • inject = colors256Data@constants
    true false
    any cr


    • access = public
    • returntype = any
    • inject = cr@constants
    true false
    any formatterUtil


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


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


    • access = public
    • returntype = any
    • inject = provider:TablePrinter
    true false
    Method Summary
    private any _onMissingMethod([any missingMethodName], [any missingMethodArguments])
    private any _tree(struct parent, string prefix, any formatUDF, any treeSB, [Array keyPath='[runtime expression]'])
    string columns(array items, [any formatUDF='[runtime expression]'])
    private string get256Color(any id, [any foreground='true'])
         Get an 256 color ANSI.
    private string getANSIAttribute(any attribute)
         Get an ANSI Attribute.
    private string indent([any text])
         Pad all lines with 2 spaces.
    any onMissingMethod([any missingMethodName], [any missingMethodArguments])
         This allows you concatenate pretty method names to describe the kind of text you want to generate.
    private string padRight(string text, numeric maxWidth, [string padChar=' '])
         Adds characters to the right of a string until the string reaches a certain length.
    any table(any data='[runtime expression]', [any includedHeaders=''], [any headerNames=''], [boolean debug='false'], [any width='-1'])
         Outputs a table to the screen.
    any tree(struct data, [any formatUDF='[runtime expression]'])
    any unansi(any ansiString)
         Removes ANSI attributes from string.
     
    Methods inherited from class lucee.Component
    None

    Property Detail

    JSONService

    property any JSONService

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

    colors256Data

    property any colors256Data

    Attributes:
    access - public
    required - false
    returntype - any
    inject - colors256Data@constants
    serializable - true

    cr

    property any cr

    Attributes:
    access - public
    required - false
    returntype - any
    inject - cr@constants
    serializable - true

    formatterUtil

    property any formatterUtil

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

    shell

    property any shell

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

    tablePrinter

    property any tablePrinter

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

    Method Detail

    _onMissingMethod

    private any _onMissingMethod([any missingMethodName], [any missingMethodArguments])

    Parameters:
    missingMethodName
    missingMethodArguments

    _tree

    private any _tree(struct parent, string prefix, any formatUDF, any treeSB, [Array keyPath='[runtime expression]'])

    Parameters:
    parent
    prefix
    formatUDF
    treeSB
    keyPath

    columns

    public string columns(array items, [any formatUDF='[runtime expression]'])

    Parameters:
    items
    formatUDF

    get256Color

    private string get256Color(any id, [any foreground='true'])

    Get an 256 color ANSI

    Parameters:
    id
    foreground

    getANSIAttribute

    private string getANSIAttribute(any attribute)

    Get an ANSI Attribute

    Parameters:
    attribute

    indent

    private string indent([any text])

    Pad all lines with 2 spaces

    Parameters:
    text

    onMissingMethod

    public any onMissingMethod([any missingMethodName], [any missingMethodArguments])

    This allows you concatenate pretty method names to describe the kind of text you want to generate If the method name contains "line", it will be appended with a carriage return Any other token in the name that exists in the list of ANSI attributes above will be picked up and applied to the text

    Parameters:
    missingMethodName
    missingMethodArguments

    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.

    table

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

    Outputs a table to the screen an array in the correct order matching the number of headers or a struct with keys matching the headers.

    Parameters:
    data - Any type of data for the table. Each item in the array may either be
    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

    tree

    public any tree(struct data, [any formatUDF='[runtime expression]'])

    Parameters:
    data - top level struct
    formatUDF

    unansi

    public any unansi(any ansiString)

    Removes ANSI attributes from string

    Parameters:
    ansiString