Style

There are six style objects that can be used to target individual areas of the _printer. These style objects are pretty similar to styling table cells using the table.cell() method.

Table

Use the tableStyle object to style the internal table. Since there is no dedicated method for setting tableStyle, direct assignment is fine.

// Create a custom tableStyle object.
var tbs = tools.tableStyle.new(
             bgColor = tools._color("white_medium"),
             frameColor = tools._color("red_dark"),
             frameWidth = 2,
             borderColor = tools._color("red_bright"),
             borderWidth = 2)

if barstate.islast
    // Create a printer with the custom tableStyle.
    printer = tools._printer.new(tableStyle=tbs)

    // Print something.
    printer.print(tools._rndmStringMatrix(rows=2, columns=2))

Use the headerStyle object to style the header cell. To add a headerStyle, use the header() method.

// Create a custom headerStyle object.
var hs = tools.headerStyle.new(
           width = 0, 
           height = 5, 
           textHalign = text.align_left, 
           textValign = text.align_center, 
           textColor = tools._color("purple_bright"), 
           textSize = size.large, 
           bgColor = tools._color("blue_dark"), 
           textFontFamily = font.family_default, 
           format = "HEADER: {0}")

if barstate.islast
    // Create a printer object.
    printer = tools._printer.new()

    // Connect the style to the printer, using header().
    printer.header(val="Header with custom styling", headerStyle=hs)

    // Print something.
    printer.print("Testing custom headerStyle")

Use the footerStyle object to style the footer cell. To add a footerStyle, use the footer() method.

// Create a custom footerStyle object.
var fs = tools.footerStyle.new(
           width = 0, 
           height = 5, 
           textHalign = text.align_left, 
           textValign = text.align_center, 
           textColor = tools._color("purple_bright"), 
           textSize = size.large, 
           bgColor = tools._color("blue_dark"), 
           textFontFamily = font.family_default, 
           format = "FOOTER: {0}")

if barstate.islast
    // Create a printer object.
    printer = tools._printer.new()

    // Connect the style to the printer, using footer().
    printer.footer(val="Footer with custom styling", footerStyle=fs)

    // Print something.
    printer.print("Testing custom footerStyle")

Title cells

Use the titleStyle object to style all title cells or individual ones. There are couple of ways to add custom titleStyle. We can use the dedicated title() method to target all titles, or pass it to the print() method to target individual sets. Lets look at how to apply titleStyle.

// Create a custom titleStyle object.
var ts = tools.titleStyle.new(
           top = true,
           width = 0, 
           height = 0, 
           textHalign = text.align_center, 
           textValign = text.align_top, 
           textColor = tools._color("green_light"), 
           textSize = size.normal, 
           bgColor = tools._color("blue_dark"), 
           textFontFamily = font.family_default, 
           format = "TITLE: {0}")

if barstate.islast
    // Create a printer object.
    printer = tools._printer.new()

    // Connect the style to the printer, using title().
    printer.title(titleStyle=ts)

    // First print will use the custom titleStyle, as passed thru the printer.
    printer.print("First print", title="First title")

    // Second print will use a new custom titleStyle passed directly to it.
    printer.print("Second print", title="Second title", titleStyle=tools.titleStyle.new(top=false))

Cells

Use the cellStyle object to style all the regular data cells. There are couple of ways to add custom cellStyle. We can use the dedicated cell() method to target all data cells, or pass it to the print() method to target individual sets. Lets look at how to apply cellStyle.

// Create a custom cellStyle object.
var cs = tools.cellStyle.new(
           horizontal = false,
           width = 0, 
           height = 0, 
           textHalign = text.align_center, 
           textValign = text.align_top, 
           textColor = tools._color("green_light"), 
           textSize = size.normal, 
           bgColor = tools._color("blue_dark"), 
           textFontFamily = font.family_default,
           format = "CELL: {0}")

// Create a second cellStyle.
var cs2 = tools.cellStyle.copy(cs)

// Change few things.
cs2.horizontal := true
cs2.bgColor := tools._color("purple_dark", 80)
cs2.format := "Cell 2: {0}"

if barstate.islast
    // Create a printer object.
    printer = tools._printer.new()

    // Connect the style to the printer, using cell().
    printer.cell(cellStyle=cs)

    // Print something.
    
    // First print will use a custom cellStyle, as passed thru the printer.
    printer.print(tools._rndmString())
    
    // Second print will use a new custom cellStyle passed directly to it.
    printer.print(tools._rndmFloatArray(), cellStyle=cs2)
    
    // Third print will again fall back to the first set cellStyle.
    printer.print(tools._rndmBoolArray())

Gutter Cells

Use the gutterStyle object to style all the gutter cells. To add a gutterStyle, use the gutter() method.

// Create a custom titleStyle object.
var gs = tools.gutterStyle.new(
           gutter = true,
           width = 2, 
           height = 2)

// Add some frame and border to help see the gutter space better.
var tbs = tools.tableStyle.new(
             frameColor = color.silver, 
             borderColor = color.silver, 
             borderWidth = 1)

if barstate.islast
    // Create a printer object.
    printer = tools._printer.new(tableStyle=tbs)

    // Connect the style to the printer, using cell().
    printer.gutter(gutterStyle=gs)

    // Print something.
    printer.print(tools._rndmStringArray())
    
    // Add few more data sets to see the gutterStyle in action. 
    printer.print(tools._rndmFloatArray())
    printer.print(tools._rndmIntMatrix())

Themes

You can style the printer with a convenient theme() method, which uses preset colors to create a color theme. Below are all the current available themes with their color guides.

Background colorFrame colorCell text colorHeader/Footer/Title text colorTitle background colorHeader/Footer background color
blue
gray
green
orange
pink
purple
red
white
yellow

There are couple of ways to set theme. We can use the dedicated theme() method to target everything. We can also pass theme individually to each print() method. Lets see how we can do both.

if barstate.islast
    // Create a printer object.
    printer = tools._printer.new()
    printer.header("Header")
    printer.footer("Footer")
    
    // Set the theme.
    printer.theme("green")

    // Print something.
    printer.print(tools._rndmFloatArray(size=5), title="Green")

    // Print another couple set of data, but give them their own themes.
    printer.print(tools._rndmBoolMatrix(rows=3, columns=3), title="Orange", theme="orange")
    printer.print(tools._rndmStringMatrix(rows=3, columns=3), title="Pink", theme="pink")

    // Print another set of data, this one will fall back to the first theme.
    printer.print(tools._rndmBoolArray(size=3), title="Green")