Documentation
¶
Index ¶
- Constants
- Variables
- func DetectDarkBackground() bool
- func FormatTableResult(result *db.QueryResult, colOffset int, rowOffset int, termWidth int, ...) string
- func FormatVerticalResult(result *db.QueryResult) string
- func HighlightCode(code string, lexerName string) string
- func HighlightJS(jsStr string) string
- func HighlightSQL(sqlStr string) string
- func RenderMarkdown(md string, width int) string
- func RenderMarkdownWithTheme(md string, width int, isDark bool) string
- func SetThemeDark(isDark bool)
- type Model
- type PendingExport
- type State
- type TableState
- type ToolCallItem
Constants ¶
const ( MaxColumnWidth = 24 // Max character width per cell to keep grid compact PageRowSize = 12 // Rows per page )
Variables ¶
var ( TableHeaderStyle = lipgloss.NewStyle(). Bold(true). Foreground(lipgloss.AdaptiveColor{Light: "#4F46E5", Dark: "#818CF8"}). Padding(0, 1) TableCellStyle = lipgloss.NewStyle(). Foreground(lipgloss.AdaptiveColor{Light: "#1E293B", Dark: "#F1F5F9"}). Padding(0, 1) TableNilStyle = lipgloss.NewStyle(). Foreground(lipgloss.AdaptiveColor{Light: "#94A3B8", Dark: "#64748B"}). Italic(true). Padding(0, 1) TableBorderStyle = lipgloss.NewStyle(). Foreground(lipgloss.AdaptiveColor{Light: "#CBD5E1", Dark: "#334155"}) ActiveTableBorderStyle = lipgloss.NewStyle(). Foreground(lipgloss.AdaptiveColor{Light: "#6366F1", Dark: "#818CF8"}) FieldKeyStyle = lipgloss.NewStyle(). Bold(true). Foreground(lipgloss.AdaptiveColor{Light: "#4F46E5", Dark: "#818CF8"}) FieldValueStyle = lipgloss.NewStyle(). Foreground(lipgloss.AdaptiveColor{Light: "#1E293B", Dark: "#F1F5F9"}) RecordDividerStyle = lipgloss.NewStyle(). Bold(true). Foreground(PrimaryColor) ScrollBadgeStyle = lipgloss.NewStyle(). Bold(true). Foreground(lipgloss.AdaptiveColor{Light: "#BE185D", Dark: "#F472B6"}) )
var ( // High-Contrast Adaptive Styles for SQL & JS Syntax Highlighting (Light & Dark mode compatible) KeywordStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.AdaptiveColor{Light: "#6D28D9", Dark: "#C084FC"}) // Rich Purple StringStyle = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#047857", Dark: "#34D399"}) // Emerald Green NumberStyle = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#B45309", Dark: "#FBBF24"}) // Amber Gold NameStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.AdaptiveColor{Light: "#0369A1", Dark: "#38BDF8"}) // Sky Blue CommentStyle = lipgloss.NewStyle().Italic(true).Foreground(lipgloss.AdaptiveColor{Light: "#64748B", Dark: "#94A3B8"}) // Slate Grey DefaultTxtStyle = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.AdaptiveColor{Light: "#0F172A", Dark: "#F8FAFC"}) // Deep Slate / Crisp White )
var ( // Palette Colors (Adaptive Catppuccin / Tokyo Night Theme) PrimaryColor = lipgloss.AdaptiveColor{Light: "#6D28D9", Dark: "#A78BFA"} SecondaryColor = lipgloss.AdaptiveColor{Light: "#059669", Dark: "#34D399"} AccentColor = lipgloss.AdaptiveColor{Light: "#BE185D", Dark: "#F472B6"} WarningColor = lipgloss.AdaptiveColor{Light: "#D97706", Dark: "#FBBF24"} ErrorColor = lipgloss.AdaptiveColor{Light: "#E11D48", Dark: "#F87171"} InfoColor = lipgloss.AdaptiveColor{Light: "#0284C7", Dark: "#38BDF8"} MutedColor = lipgloss.AdaptiveColor{Light: "#64748B", Dark: "#94A3B8"} TextNormal = lipgloss.AdaptiveColor{Light: "#0F172A", Dark: "#F8FAFC"} HeaderBg = lipgloss.AdaptiveColor{Light: "#E2E8F0", Dark: "#1E293B"} // Header Container & Badges HeaderBarStyle = lipgloss.NewStyle(). Background(HeaderBg). Padding(0, 1) HeaderTitleBadge = lipgloss.NewStyle(). Bold(true). Foreground(lipgloss.Color("#FFFFFF")). Background(PrimaryColor). Padding(0, 1) HeaderProfileBadge = lipgloss.NewStyle(). Bold(true). Foreground(lipgloss.Color("#FFFFFF")). Background(InfoColor). Padding(0, 1) BadgeReadOnly = lipgloss.NewStyle(). Bold(true). Foreground(lipgloss.Color("#FFFFFF")). Background(SecondaryColor). Padding(0, 1) BadgeReadWrite = lipgloss.NewStyle(). Bold(true). Foreground(lipgloss.Color("#FFFFFF")). Background(WarningColor). Padding(0, 1) BadgeAutoExec = lipgloss.NewStyle(). Bold(true). Foreground(lipgloss.Color("#FFFFFF")). Background(AccentColor). Padding(0, 1) BadgeManualApprove = lipgloss.NewStyle(). Bold(true). Foreground(lipgloss.AdaptiveColor{Light: "#0F172A", Dark: "#E2E8F0"}). Background(lipgloss.AdaptiveColor{Light: "#CBD5E1", Dark: "#475569"}). Padding(0, 1) // Keybinding Badges KeyBadgeStyle = lipgloss.NewStyle(). Bold(true). Foreground(lipgloss.AdaptiveColor{Light: "#0F172A", Dark: "#F8FAFC"}). Background(lipgloss.AdaptiveColor{Light: "#CBD5E1", Dark: "#334155"}). Padding(0, 1) KeyLabelStyle = lipgloss.NewStyle(). Foreground(MutedColor) // SQL Preview Box SQLBoxStyle = lipgloss.NewStyle(). Border(lipgloss.RoundedBorder()). BorderForeground(PrimaryColor). Padding(0, 1). MarginTop(1). MarginBottom(1) SQLTitleStyle = lipgloss.NewStyle(). Bold(true). Foreground(AccentColor) SQLCodeStyle = lipgloss.NewStyle(). Bold(true). Foreground(InfoColor) // User & AI Message Tags UserTagStyle = lipgloss.NewStyle(). Bold(true). Foreground(lipgloss.Color("#FFFFFF")). Background(SecondaryColor). Padding(0, 1) AITagStyle = lipgloss.NewStyle(). Bold(true). Foreground(lipgloss.Color("#FFFFFF")). Background(PrimaryColor). Padding(0, 1) ExecutingTagStyle = lipgloss.NewStyle(). Bold(true). Foreground(lipgloss.Color("#FFFFFF")). Background(WarningColor). Padding(0, 1) SuccessBadgeStyle = lipgloss.NewStyle(). Bold(true). Foreground(SecondaryColor) WarningBadgeStyle = lipgloss.NewStyle(). Bold(true). Foreground(WarningColor) MetricsStyle = lipgloss.NewStyle(). Foreground(MutedColor). Italic(true) AIResponseStyle = lipgloss.NewStyle(). Foreground(TextNormal). PaddingLeft(1) ErrorMsgStyle = lipgloss.NewStyle(). Bold(true). Foreground(ErrorColor). PaddingLeft(1) PromptPrefixStyle = lipgloss.NewStyle(). Bold(true). Foreground(PrimaryColor) // Collapsible Tool Call Badges ToolCollapsedBadge = lipgloss.NewStyle(). Bold(true). Foreground(lipgloss.AdaptiveColor{Light: "#475569", Dark: "#94A3B8"}). Background(lipgloss.AdaptiveColor{Light: "#E2E8F0", Dark: "#1E293B"}). Padding(0, 1) ToolExpandedBadge = lipgloss.NewStyle(). Bold(true). Foreground(lipgloss.Color("#FFFFFF")). Background(WarningColor). Padding(0, 1) ToolDetailStyle = lipgloss.NewStyle(). Border(lipgloss.NormalBorder(), false, false, false, true). BorderForeground(MutedColor). PaddingLeft(1). Foreground(MutedColor) )
var CurrentThemeIsDark = DetectDarkBackground()
CurrentThemeIsDark tracks the detected or configured theme preference
var XSQLDarkMarkdownStyle = ansi.StyleConfig{ Document: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ Color: stringPtr("#F8FAFC"), }, Margin: uintPtr(0), }, BlockQuote: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ Color: stringPtr("#94A3B8"), }, Indent: uintPtr(1), IndentToken: stringPtr("│ "), }, List: ansi.StyleList{ LevelIndent: 2, }, Heading: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ BlockSuffix: "\n", Bold: boolPtr(true), }, }, H1: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ Prefix: " ", Suffix: " ", Color: stringPtr("#FFFFFF"), BackgroundColor: stringPtr("#6D28D9"), Bold: boolPtr(true), }, }, H2: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ Prefix: "## ", Color: stringPtr("#818CF8"), Bold: boolPtr(true), }, }, H3: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ Prefix: "### ", Color: stringPtr("#38BDF8"), Bold: boolPtr(true), }, }, H4: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ Prefix: "#### ", Color: stringPtr("#34D399"), Bold: boolPtr(true), }, }, H5: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ Prefix: "##### ", Color: stringPtr("#F472B6"), Bold: boolPtr(true), }, }, H6: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ Prefix: "###### ", Color: stringPtr("#94A3B8"), Bold: boolPtr(false), }, }, Text: ansi.StylePrimitive{ Color: stringPtr("#F1F5F9"), }, Strikethrough: ansi.StylePrimitive{ CrossedOut: boolPtr(true), }, Emph: ansi.StylePrimitive{ Italic: boolPtr(true), Color: stringPtr("#E2E8F0"), }, Strong: ansi.StylePrimitive{ Bold: boolPtr(true), Color: stringPtr("#FFFFFF"), }, HorizontalRule: ansi.StylePrimitive{ Color: stringPtr("#475569"), Format: "\n────────\n", }, Item: ansi.StylePrimitive{ BlockPrefix: "• ", Color: stringPtr("#818CF8"), }, Enumeration: ansi.StylePrimitive{ BlockPrefix: ". ", Color: stringPtr("#818CF8"), }, Task: ansi.StyleTask{ StylePrimitive: ansi.StylePrimitive{}, Ticked: "[✓] ", Unticked: "[ ] ", }, Link: ansi.StylePrimitive{ Color: stringPtr("#38BDF8"), Underline: boolPtr(true), }, LinkText: ansi.StylePrimitive{ Color: stringPtr("#818CF8"), Bold: boolPtr(true), }, Code: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ Prefix: " ", Suffix: " ", Color: stringPtr("#F472B6"), BackgroundColor: stringPtr("#1E293B"), }, }, CodeBlock: ansi.StyleCodeBlock{ StyleBlock: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ Color: stringPtr("#F8FAFC"), }, Margin: uintPtr(0), }, Chroma: &ansi.Chroma{ Text: ansi.StylePrimitive{ Color: stringPtr("#F8FAFC"), }, Error: ansi.StylePrimitive{ Color: stringPtr("#F8FAFC"), BackgroundColor: stringPtr("#EF4444"), }, Comment: ansi.StylePrimitive{ Color: stringPtr("#94A3B8"), }, CommentPreproc: ansi.StylePrimitive{ Color: stringPtr("#F472B6"), }, Keyword: ansi.StylePrimitive{ Color: stringPtr("#C084FC"), Bold: boolPtr(true), }, KeywordReserved: ansi.StylePrimitive{ Color: stringPtr("#F472B6"), Bold: boolPtr(true), }, KeywordNamespace: ansi.StylePrimitive{ Color: stringPtr("#F43F5E"), }, KeywordType: ansi.StylePrimitive{ Color: stringPtr("#A78BFA"), }, Operator: ansi.StylePrimitive{ Color: stringPtr("#38BDF8"), }, Punctuation: ansi.StylePrimitive{ Color: stringPtr("#CBD5E1"), }, Name: ansi.StylePrimitive{ Color: stringPtr("#F8FAFC"), }, NameBuiltin: ansi.StylePrimitive{ Color: stringPtr("#38BDF8"), }, NameTag: ansi.StylePrimitive{ Color: stringPtr("#F472B6"), }, NameAttribute: ansi.StylePrimitive{ Color: stringPtr("#A78BFA"), }, NameClass: ansi.StylePrimitive{ Color: stringPtr("#FBBF24"), Bold: boolPtr(true), }, NameConstant: ansi.StylePrimitive{ Color: stringPtr("#F472B6"), }, NameDecorator: ansi.StylePrimitive{ Color: stringPtr("#FBBF24"), }, NameFunction: ansi.StylePrimitive{ Color: stringPtr("#34D399"), Bold: boolPtr(true), }, LiteralNumber: ansi.StylePrimitive{ Color: stringPtr("#FBBF24"), }, LiteralString: ansi.StylePrimitive{ Color: stringPtr("#34D399"), }, LiteralStringEscape: ansi.StylePrimitive{ Color: stringPtr("#2DD4BF"), }, GenericDeleted: ansi.StylePrimitive{ Color: stringPtr("#F87171"), }, GenericEmph: ansi.StylePrimitive{ Italic: boolPtr(true), }, GenericInserted: ansi.StylePrimitive{ Color: stringPtr("#34D399"), }, GenericStrong: ansi.StylePrimitive{ Bold: boolPtr(true), }, GenericSubheading: ansi.StylePrimitive{ Color: stringPtr("#94A3B8"), }, Background: ansi.StylePrimitive{ BackgroundColor: stringPtr("#0F172A"), }, }, }, Table: ansi.StyleTable{ StyleBlock: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ Color: stringPtr("#F1F5F9"), }, }, CenterSeparator: stringPtr("+"), ColumnSeparator: stringPtr("|"), RowSeparator: stringPtr("-"), }, DefinitionDescription: ansi.StylePrimitive{ BlockPrefix: "\n🠶 ", }, }
XSQLDarkMarkdownStyle defines a refined, high-contrast Dark theme for Glamour. It eliminates any OSC 11 background probe (which caused garbled terminal echo in input box) and ensures crisp contrast for tables, headers, lists, code, and text on dark terminal backgrounds.
var XSQLLightMarkdownStyle = ansi.StyleConfig{ Document: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ Color: stringPtr("#0F172A"), }, Margin: uintPtr(0), }, BlockQuote: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ Color: stringPtr("#475569"), }, Indent: uintPtr(1), IndentToken: stringPtr("│ "), }, List: ansi.StyleList{ LevelIndent: 2, }, Heading: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ BlockSuffix: "\n", Bold: boolPtr(true), }, }, H1: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ Prefix: " ", Suffix: " ", Color: stringPtr("#FFFFFF"), BackgroundColor: stringPtr("#4F46E5"), Bold: boolPtr(true), }, }, H2: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ Prefix: "## ", Color: stringPtr("#4338CA"), Bold: boolPtr(true), }, }, H3: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ Prefix: "### ", Color: stringPtr("#0284C7"), Bold: boolPtr(true), }, }, H4: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ Prefix: "#### ", Color: stringPtr("#059669"), Bold: boolPtr(true), }, }, H5: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ Prefix: "##### ", Color: stringPtr("#BE185D"), Bold: boolPtr(true), }, }, H6: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ Prefix: "###### ", Color: stringPtr("#64748B"), Bold: boolPtr(false), }, }, Text: ansi.StylePrimitive{ Color: stringPtr("#0F172A"), }, Strikethrough: ansi.StylePrimitive{ CrossedOut: boolPtr(true), }, Emph: ansi.StylePrimitive{ Italic: boolPtr(true), Color: stringPtr("#334155"), }, Strong: ansi.StylePrimitive{ Bold: boolPtr(true), Color: stringPtr("#020617"), }, HorizontalRule: ansi.StylePrimitive{ Color: stringPtr("#CBD5E1"), Format: "\n────────\n", }, Item: ansi.StylePrimitive{ BlockPrefix: "• ", Color: stringPtr("#4F46E5"), }, Enumeration: ansi.StylePrimitive{ BlockPrefix: ". ", Color: stringPtr("#4F46E5"), }, Task: ansi.StyleTask{ StylePrimitive: ansi.StylePrimitive{}, Ticked: "[✓] ", Unticked: "[ ] ", }, Link: ansi.StylePrimitive{ Color: stringPtr("#0284C7"), Underline: boolPtr(true), }, LinkText: ansi.StylePrimitive{ Color: stringPtr("#4338CA"), Bold: boolPtr(true), }, Code: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ Prefix: " ", Suffix: " ", Color: stringPtr("#BE185D"), BackgroundColor: stringPtr("#F1F5F9"), }, }, CodeBlock: ansi.StyleCodeBlock{ StyleBlock: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ Color: stringPtr("#0F172A"), }, Margin: uintPtr(0), }, Chroma: &ansi.Chroma{ Text: ansi.StylePrimitive{ Color: stringPtr("#0F172A"), }, Error: ansi.StylePrimitive{ Color: stringPtr("#FFFFFF"), BackgroundColor: stringPtr("#EF4444"), }, Comment: ansi.StylePrimitive{ Color: stringPtr("#64748B"), }, CommentPreproc: ansi.StylePrimitive{ Color: stringPtr("#BE185D"), }, Keyword: ansi.StylePrimitive{ Color: stringPtr("#6D28D9"), Bold: boolPtr(true), }, KeywordReserved: ansi.StylePrimitive{ Color: stringPtr("#BE185D"), Bold: boolPtr(true), }, KeywordNamespace: ansi.StylePrimitive{ Color: stringPtr("#E11D48"), }, KeywordType: ansi.StylePrimitive{ Color: stringPtr("#6D28D9"), }, Operator: ansi.StylePrimitive{ Color: stringPtr("#0284C7"), }, Punctuation: ansi.StylePrimitive{ Color: stringPtr("#475569"), }, Name: ansi.StylePrimitive{ Color: stringPtr("#0F172A"), }, NameBuiltin: ansi.StylePrimitive{ Color: stringPtr("#0284C7"), }, NameTag: ansi.StylePrimitive{ Color: stringPtr("#BE185D"), }, NameAttribute: ansi.StylePrimitive{ Color: stringPtr("#6D28D9"), }, NameClass: ansi.StylePrimitive{ Color: stringPtr("#B45309"), Bold: boolPtr(true), }, NameConstant: ansi.StylePrimitive{ Color: stringPtr("#BE185D"), }, NameDecorator: ansi.StylePrimitive{ Color: stringPtr("#B45309"), }, NameFunction: ansi.StylePrimitive{ Color: stringPtr("#059669"), Bold: boolPtr(true), }, LiteralNumber: ansi.StylePrimitive{ Color: stringPtr("#B45309"), }, LiteralString: ansi.StylePrimitive{ Color: stringPtr("#059669"), }, LiteralStringEscape: ansi.StylePrimitive{ Color: stringPtr("#0D9488"), }, GenericDeleted: ansi.StylePrimitive{ Color: stringPtr("#E11D48"), }, GenericEmph: ansi.StylePrimitive{ Italic: boolPtr(true), }, GenericInserted: ansi.StylePrimitive{ Color: stringPtr("#059669"), }, GenericStrong: ansi.StylePrimitive{ Bold: boolPtr(true), }, GenericSubheading: ansi.StylePrimitive{ Color: stringPtr("#64748B"), }, Background: ansi.StylePrimitive{ BackgroundColor: stringPtr("#F8FAFC"), }, }, }, Table: ansi.StyleTable{ StyleBlock: ansi.StyleBlock{ StylePrimitive: ansi.StylePrimitive{ Color: stringPtr("#0F172A"), }, }, CenterSeparator: stringPtr("+"), ColumnSeparator: stringPtr("|"), RowSeparator: stringPtr("-"), }, DefinitionDescription: ansi.StylePrimitive{ BlockPrefix: "\n🠶 ", }, }
XSQLLightMarkdownStyle defines a clean, high-contrast Light theme for Glamour. It uses dark readable text on light backgrounds with vibrant Indigo/Sky accents.
Functions ¶
func DetectDarkBackground ¶ added in v1.20.2
func DetectDarkBackground() bool
DetectDarkBackground safely determines whether the terminal has a dark background by inspecting COLORFGBG and environment variables, completely avoiding OSC 11 probe sequences which cause terminal stdin race conditions and garbled text echo in interactive TUI applications.
func FormatTableResult ¶
func FormatTableResult(result *db.QueryResult, colOffset int, rowOffset int, termWidth int, isActive bool) string
FormatTableResult renders a beautiful terminal box table for SQL query results with column scrolling and row pagination.
func FormatVerticalResult ¶
func FormatVerticalResult(result *db.QueryResult) string
FormatVerticalResult renders SQL query results in full vertical (psql \x expanded) format with NO truncation.
func HighlightCode ¶
HighlightCode renders adaptive, high-contrast syntax-highlighted code for light & dark terminals.
func HighlightJS ¶
HighlightJS applies adaptive high-contrast syntax highlighting to JavaScript code blocks.
func HighlightSQL ¶
HighlightSQL applies adaptive high-contrast syntax highlighting to SQL statements.
func RenderMarkdown ¶
RenderMarkdown renders markdown text using Glamour with the active theme style.
func RenderMarkdownWithTheme ¶ added in v1.20.2
RenderMarkdownWithTheme renders markdown text using Glamour with an explicit theme style.
func SetThemeDark ¶ added in v1.20.2
func SetThemeDark(isDark bool)
SetThemeDark sets the theme preference across Lipgloss and Glamour without terminal probing