output

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package output renders command results: JSON (optionally filtered by jq or a Go template), and tables.

The exporter follows github.com/cli/cli pkg/cmdutil/json_flags.go (Copyright (c) 2019 GitHub Inc., MIT); see NOTICE.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Copy

func Copy(ios *iostreams.IOStreams, r io.Reader) error

Copy writes r to ios.Out unchanged, adding a final newline on a terminal when the content lacks one so the shell prompt starts on its own line.

func SanitizeCell

func SanitizeCell(s string) string

SanitizeCell is SanitizeText for a single-line table cell: tabs and line breaks become spaces.

func SanitizeText

func SanitizeText(s string) string

SanitizeText makes server-supplied text safe to print on a terminal: it drops C0 and C1 control characters (ESC, CSI, OSC and the rest, also as raw 8-bit bytes) and DEL, keeping newlines and tabs. \r\n becomes \n. Like go-gh's asciisanitizer it guards against escape-sequence injection, but it removes the characters instead of printing caret notation.

func WriteJSON

func WriteJSON(ios *iostreams.IOStreams, r io.Reader, f Format) error

WriteJSON writes the JSON document in r to ios.Out: filtered by JQ, formatted by Template, pretty and colored on a color terminal, or verbatim.

Types

type Cell added in v0.2.0

type Cell struct {
	Text  string
	Style func(string) string
}

Cell is a table field with an optional style, applied after the field is sanitized and fitted to its column (so escapes never count toward widths).

type Exportable

type Exportable interface {
	ExportData(fields []string) map[string]any
}

Exportable is implemented by results that can be projected onto a list of JSON field names.

type Exporter

type Exporter struct {
	Fields []string
	Format
}

Exporter writes results as JSON restricted to the requested fields.

func (*Exporter) Write

func (e *Exporter) Write(ios *iostreams.IOStreams, data any) error

Write projects data (an Exportable, or a slice or map of them) onto the exporter's fields and writes it.

type Format

type Format struct {
	// JQ filters the JSON through a jq expression.
	JQ string
	// Template formats the JSON with a Go template (go-gh template functions).
	Template string
}

Format selects how JSON is written.

type Table

type Table struct {
	tableprinter.TablePrinter
}

Table prints aligned columns on a terminal and tab-separated values when piped. Headers are shown only on a terminal, so piped output is pure data.

func NewTable

func NewTable(ios *iostreams.IOStreams, headers ...string) *Table

NewTable returns a Table writing to ios.Out with the given column headers.

func (*Table) Row

func (t *Table) Row(fields ...string)

Row adds one row. Fields are sanitized with SanitizeCell, so server data cannot inject terminal escapes or break the tab-separated layout.

func (*Table) StyledRow added in v0.2.0

func (t *Table) StyledRow(cells ...Cell)

StyledRow adds one row of cells, each sanitized like Row.

Jump to

Keyboard shortcuts

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