result

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package result formats query values for display and export.

Formatting lives apart from the UI so the grid, CSV export and JSON export all agree on what a value looks like — and so the rules can be tested without a terminal.

Index

Constants

View Source
const CellLimit = 200

CellLimit caps how many runes a grid cell shows. Long values stay in the buffer intact; only the rendering is shortened.

View Source
const NullText = "NULL"

NullText is how a SQL NULL is shown. It has to be visually distinct from an empty string: treating the two alike misleads people into thinking a row failed an IS NULL test for no reason.

View Source
const TimeLayout = "2006-01-02 15:04:05"

TimeLayout is the timestamp rendering, chosen to match MySQL's own.

Variables

This section is empty.

Functions

func EscapeTags

func EscapeTags(s string) string

EscapeTags neutralises tview's colour-tag syntax.

tview reads "[" as the start of a tag, so a cell containing "[red]" would recolour the grid instead of showing its own text. tview's documented escape is to write "[" as "[[".

func Format

func Format(v any) string

Format renders a scanned value as display text.

func Truncate

func Truncate(s string, limit int) string

Truncate shortens s to limit runes, marking the cut with an ellipsis. A limit of zero or less leaves s unchanged.

Types

type Buffer

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

Buffer holds the rows of one result set.

It is written by the streaming goroutine and read by the UI goroutine, so every accessor takes the lock. Reads outside the current bounds return zero values rather than panicking: tview asks for cells while rendering, and a result that was just cleared would otherwise crash the application.

func NewBuffer

func NewBuffer(max int) *Buffer

NewBuffer returns an empty buffer. A max of zero means unbounded.

func (*Buffer) Append

func (b *Buffer) Append(rows [][]any) int

Append adds rows up to the cap and returns how many were accepted.

func (*Buffer) AtCapacity

func (b *Buffer) AtCapacity() bool

AtCapacity reports whether the buffer has stopped accepting rows.

func (*Buffer) Cell

func (b *Buffer) Cell(row, col int) string

Cell returns display text for a cell, ready to hand to tview.

func (*Buffer) ColumnCount

func (b *Buffer) ColumnCount() int

ColumnCount is the number of columns in the result.

func (*Buffer) ColumnName

func (b *Buffer) ColumnName(col int) string

ColumnName returns the name of a column, or "" if it is out of range.

func (*Buffer) Columns

func (b *Buffer) Columns() []string

Columns returns a copy of the column names.

func (*Buffer) Raw

func (b *Buffer) Raw(row, col int) any

Raw returns the unformatted value, which export needs and display does not.

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset clears the header and the rows.

func (*Buffer) Row

func (b *Buffer) Row(row int) []any

Row returns a copy of one row's raw values, or nil if out of range.

func (*Buffer) RowCount

func (b *Buffer) RowCount() int

RowCount is the number of rows received so far. While a stream is running it grows, which is what lets the grid scroll through partial results.

func (*Buffer) SetColumns

func (b *Buffer) SetColumns(columns []string, types []*sql.ColumnType)

SetColumns replaces the result header and drops any existing rows.

Jump to

Keyboard shortcuts

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