renderer

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2025 License: MIT Imports: 8 Imported by: 132

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Blueprint

type Blueprint struct {
	// contains filtered or unexported fields
}

Blueprint implements a basic default table renderer with customizable borders and alignments.

func NewBlueprint

func NewBlueprint(configs ...tw.RendererConfig) *Blueprint

func (*Blueprint) Close

func (f *Blueprint) Close(w io.Writer) error

func (*Blueprint) Config

func (f *Blueprint) Config() tw.RendererConfig

Config returns the renderer's current configuration.

func (*Blueprint) Debug

func (f *Blueprint) Debug() []string

Debug returns the accumulated debug trace messages.

func (*Blueprint) Footer

func (f *Blueprint) Footer(w io.Writer, footers [][]string, ctx tw.Formatting)

Footer renders the table footer section with configured formatting.

func (*Blueprint) Header

func (f *Blueprint) Header(w io.Writer, headers [][]string, ctx tw.Formatting)

Header renders the table header section with configured formatting.

func (*Blueprint) Line

func (f *Blueprint) Line(w io.Writer, ctx tw.Formatting)

Line renders a full horizontal row line with junctions and segments.

func (*Blueprint) Row

func (f *Blueprint) Row(w io.Writer, row []string, ctx tw.Formatting)

Row renders a table data row with configured formatting.

func (*Blueprint) Start

func (f *Blueprint) Start(w io.Writer) error

type Colorized

type Colorized struct {
	// contains filtered or unexported fields
}

Colorized renders colored ASCII tables with customizable borders, colors, and alignments.

func NewColorized

func NewColorized(configs ...ColorizedConfig) *Colorized

NewColorized creates a Colorized renderer with the specified configuration, falling back to defaults if none provided. Only the first config is used if multiple are passed.

func (*Colorized) Close

func (f *Colorized) Close(w io.Writer) error

func (*Colorized) Config

func (f *Colorized) Config() tw.RendererConfig

Config returns the renderer's configuration as a RendererConfig.

func (*Colorized) Debug

func (f *Colorized) Debug() []string

Debug returns the accumulated debug trace messages.

func (*Colorized) Footer

func (f *Colorized) Footer(w io.Writer, footers [][]string, ctx tw.Formatting)

Footer renders the table footer with configured colors and formatting.

func (*Colorized) Header

func (f *Colorized) Header(w io.Writer, headers [][]string, ctx tw.Formatting)

Header renders the table header with configured colors and formatting.

func (*Colorized) Line

func (f *Colorized) Line(w io.Writer, ctx tw.Formatting)

Line renders a horizontal row line with colored junctions and segments, skipping zero-width columns.

func (*Colorized) Reset

func (f *Colorized) Reset()

Reset clears the renderer's internal state, including debug traces.

func (*Colorized) Row

func (f *Colorized) Row(w io.Writer, row []string, ctx tw.Formatting)

Row renders a table data row with configured colors and formatting.

func (*Colorized) Start

func (f *Colorized) Start(w io.Writer) error

type ColorizedConfig

type ColorizedConfig struct {
	Borders   tw.Border   // Border visibility settings
	Settings  tw.Settings // Rendering behavior settings (e.g., separators, whitespace)
	Header    Tint        // Colors for header cells
	Column    Tint        // Colors for row cells
	Footer    Tint        // Colors for footer cells
	Border    Tint        // Colors for borders and lines
	Separator Tint        // Colors for column separators
	Symbols   tw.Symbols  // Symbols for table drawing (e.g., corners, lines)
	Debug     bool        // Enables debug logging
}

ColorizedConfig holds configuration for the Colorized table renderer.

type Colors

type Colors []color.Attribute

Colors is a slice of color attributes for use with fatih/color, such as color.FgWhite or color.Bold.

type HTML

type HTML struct {
	// contains filtered or unexported fields
}

HTML renders tables in HTML format with customizable classes and content handling.

func NewHTML

func NewHTML(w io.Writer, debug bool, configs ...HTMLConfig) *HTML

NewHTML initializes an HTML renderer with the given writer, debug setting, and optional configuration. It panics if the writer is nil and applies defaults for unset config fields.

func (*HTML) Close

func (h *HTML) Close(w io.Writer) error

Close ensures all open HTML tags (<table>, <tbody>, <tfoot>) are properly closed.

func (*HTML) Config

func (h *HTML) Config() tw.RendererConfig

Config returns a RendererConfig representation of the current configuration.

func (*HTML) Debug

func (h *HTML) Debug() []string

Debug returns the accumulated debug trace messages.

func (*HTML) Footer

func (h *HTML) Footer(w io.Writer, footers [][]string, ctx tw.Formatting)

Footer renders the <tfoot> section with footer rows, supporting horizontal merges.

func (*HTML) Header

func (h *HTML) Header(w io.Writer, headers [][]string, ctx tw.Formatting)

Header renders the <thead> section with header rows, supporting horizontal merges.

func (*HTML) Line

func (h *HTML) Line(w io.Writer, ctx tw.Formatting)

Line is a no-op for HTML rendering, as structural lines are handled by tags.

func (*HTML) Reset

func (h *HTML) Reset()

Reset clears the renderer's internal state, including debug traces and merge tracking.

func (*HTML) Row

func (h *HTML) Row(w io.Writer, row []string, ctx tw.Formatting)

Row renders a <tr> element within <tbody>, supporting horizontal and vertical merges.

func (*HTML) Start

func (h *HTML) Start(w io.Writer) error

Start begins the HTML table rendering by opening the <table> tag.

type HTMLConfig

type HTMLConfig struct {
	EscapeContent  bool   // Whether to escape cell content
	AddLinesTag    bool   // Whether to wrap multiline content in <lines> tags
	TableClass     string // CSS class for <table>
	HeaderClass    string // CSS class for <thead>
	BodyClass      string // CSS class for <tbody>
	FooterClass    string // CSS class for <tfoot>
	RowClass       string // CSS class for <tr> in body
	HeaderRowClass string // CSS class for <tr> in header
	FooterRowClass string // CSS class for <tr> in footer
}

HTMLConfig defines settings for the HTML table renderer.

type Junction

type Junction struct {
	// contains filtered or unexported fields
}

Junction handles rendering of table junction points (corners, intersections) with color support.

func NewJunction

func NewJunction(ctx JunctionContext) *Junction

NewJunction initializes a Junction with the given symbols, context, and tints. If debug is nil, a no-op debug function is used.

func (*Junction) GetSegment

func (jr *Junction) GetSegment() string

GetSegment determines whether to render a colored horizontal line or an empty space based on merge states.

func (*Junction) RenderJunction

func (jr *Junction) RenderJunction(leftColIdx, rightColIdx int) string

RenderJunction selects and colors the junction symbol between two adjacent columns based on merge states and table position.

func (*Junction) RenderLeft

func (jr *Junction) RenderLeft() string

RenderLeft selects and colors the leftmost junction symbol for the current row line based on position and merges.

func (*Junction) RenderRight

func (jr *Junction) RenderRight(lastColIdx int) string

RenderRight selects and colors the rightmost junction symbol for the row line based on position, merges, and last column index.

type JunctionContext

type JunctionContext struct {
	Symbols       tw.Symbols
	Ctx           tw.Formatting
	ColIdx        int
	Debugging     bool
	Debug         func(format string, a ...interface{})
	BorderTint    Tint
	SeparatorTint Tint
}

type Markdown

type Markdown struct {
	// contains filtered or unexported fields
}

Markdown renders tables in Markdown format with customizable settings.

func NewMarkdown

func NewMarkdown(configs ...tw.RendererConfig) *Markdown

NewMarkdown initializes a Markdown renderer with defaults tailored for Markdown (e.g., pipes, header separator). Only the first config is used if multiple are provided.

func (*Markdown) Close

func (m *Markdown) Close(w io.Writer) error

func (*Markdown) Config

func (m *Markdown) Config() tw.RendererConfig

Config returns the renderer's current configuration.

func (*Markdown) Debug

func (m *Markdown) Debug() []string

Debug returns the accumulated debug trace messages.

func (*Markdown) Footer

func (m *Markdown) Footer(w io.Writer, footers [][]string, ctx tw.Formatting)

Footer renders the Markdown table footer.

func (*Markdown) Header

func (m *Markdown) Header(w io.Writer, headers [][]string, ctx tw.Formatting)

Header renders the Markdown table header and its separator line.

func (*Markdown) Line

func (m *Markdown) Line(w io.Writer, ctx tw.Formatting)

Line is a no-op for Markdown, as only the header separator is rendered (handled by Header).

func (*Markdown) Reset

func (m *Markdown) Reset()

Reset clears the renderer's internal state, including debug traces.

func (*Markdown) Row

func (m *Markdown) Row(w io.Writer, row []string, ctx tw.Formatting)

Row renders a Markdown table data row.

func (*Markdown) Start

func (m *Markdown) Start(w io.Writer) error

type Tint

type Tint struct {
	FG      Colors // Foreground color attributes
	BG      Colors // Background color attributes
	Columns []Tint // Per-column color settings
}

Tint defines foreground and background color settings for table elements, with optional per-column overrides.

func (Tint) Apply

func (t Tint) Apply(text string) string

Apply applies the Tint's foreground and background colors to the given text, returning the text unchanged if no colors are set.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL