display

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package display formats sessions for list-mode output using lipgloss and ANSI 16-color palette.

Index

Constants

View Source
const (
	MaxTitleLimit = 40 // baseline cap for adaptive title width

)

Column widths (display columns, not bytes).

Variables

View Source
var (
	ColorTime    = lipgloss.Color("2") // green
	ColorTitle   = lipgloss.Color("3") // yellow
	ColorID      = lipgloss.Color("7") // white
	ColorMsg     = lipgloss.Color("5") // magenta
	ColorSrc     = lipgloss.Color("5") // magenta (same as msg)
	ColorDir     = lipgloss.Color("6") // cyan
	ColorMuted   = lipgloss.Color("8") // dark grey (separators, borders, dim text)
	ColorHeader  = lipgloss.Color("7") // white (header row)
	ColorSpinner = lipgloss.Color("9") // bright red (renders as orange in most terminals, matches Claude brand)
)

Shared ANSI 16-color palette used by both list mode and the interactive picker. Using ANSI 16 respects the user's terminal color theme.

Functions

func AdaptiveDirWidth

func AdaptiveDirWidth(sessions []source.Session, termWidth int) int

AdaptiveDirWidth returns the column width needed to display the widest CWDDisplay. When termWidth > 0, the result is capped at termWidth. When termWidth == 0, result is the natural maximum (no cap).

func AdaptiveIDWidth

func AdaptiveIDWidth(sessions []source.Session) int

AdaptiveIDWidth returns the column width needed to display the widest session ID.

func AdaptiveMsgWidth

func AdaptiveMsgWidth(sessions []source.Session) int

AdaptiveMsgWidth returns the column width needed to display the widest message count. The minimum is len("MSG") so the header always fits.

func AdaptiveTitleWidth

func AdaptiveTitleWidth(titles []string) int

AdaptiveTitleWidth returns min(MaxTitleLimit, maxActualDisplayWidth) across titles.

func FormatDirCell added in v0.2.8

func FormatDirCell(dir string, colWidth int, dim bool) string

FormatDirCell renders a directory path with the basename in bold. The total rendered width is padded to colWidth display columns (0 = unconstrained). prefix and basename are rendered separately so only basename is bold. dim=true renders the cell faint (same path as previous row).

func FormatListRow

func FormatListRow(s source.Session, w ListWidths, dimDir bool) string

FormatListRow formats a session for plain list output. dimDir=true renders the directory cell faint (same path as previous row).

func Header(w ListWidths) string

Header returns a formatted header row for list mode.

func Sanitize

func Sanitize(s string) string

Sanitize replaces tab and newline characters with spaces.

func TermWidth

func TermWidth(w io.Writer) int

TermWidth returns the terminal width of w, or 0 if w is not a TTY. Callers treat 0 as "unconstrained" (pipe / redirect).

func TruncateWidth

func TruncateWidth(s string, maxCols int, tail string) string

TruncateWidth truncates s to at most maxCols display columns, CJK-aware. tail (e.g. "…") is appended when truncation occurs and counts toward maxCols. Uses lipgloss.Width (which wraps go-runewidth) to measure each candidate.

Types

type ListWidths

type ListWidths struct {
	Title  int
	ID     int
	Msg    int
	Dir    int // 0 means unconstrained (pipe mode — Dir rendered without Width padding)
	Source int // 0 when not combined
}

ListWidths holds pre-computed column widths for list-mode rendering.

func ComputeListWidths

func ComputeListWidths(sessions []source.Session, includeSource bool, termWidth int) ListWidths

ComputeListWidths computes adaptive column widths for all sessions. termWidth==0 means stdout is not a TTY; no bonus space is allocated.

Jump to

Keyboard shortcuts

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