layout

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package layout provides responsive layout calculations for the OpenCode TUI. This file contains box model definitions and styling helpers.

The Box model represents a rectangular region with styling, supporting:

  • Dimension specification (width, height)
  • Lipgloss styling (background, foreground, borders)
  • Content rendering
  • Functional options for configuration

Package layout provides layout components for the OpenCode TUI, including containers, splits, overlays, and other UI layout utilities.

Package layout provides responsive layout calculations for the OpenCode TUI. It offers utilities for dimension calculation, split panes, and container wrappers that automatically adapt to terminal window size changes.

The package provides:

  • LayoutEngine: Responsive dimension calculator for all UI sections
  • SplitPaneLayout: Horizontal/vertical split container layout
  • Container: Wrapper with padding and borders
  • Sizeable, Bindings, Focusable: Core interfaces for tea.Model components

Package layout provides responsive layout calculations for the OpenCode TUI.

Package layout provides responsive layout calculations for the OpenCode TUI.

Package layout provides responsive layout calculations for the OpenCode TUI. It offers utilities for dimension calculation, split panes, and container wrappers that automatically adapt to terminal window size changes.

The package provides:

  • LayoutEngine: Responsive dimension calculator for all UI sections
  • SplitPaneLayout: Horizontal/vertical split container layout
  • Container: Wrapper with padding and borders
  • Sizeable, Bindings, Focusable: Core interfaces for tea.Model components

Package layout provides responsive layout calculations for the OpenCode TUI. It offers a LayoutManager for calculating 3-pane layouts with header, sidebar, and footer sections, along with component implementations for each pane.

Package layout provides responsive layout calculations for the OpenCode TUI. This file contains overlay placement functions for rendering content on top of backgrounds.

The overlay functionality is borrowed and modified from the lipgloss library (https://github.com/charmbracelet/lipgloss/pull/102) to support:

  • Placing foreground content over background content
  • Optional shadow rendering
  • Precise x, y coordinate placement

Package layout provides responsive layout calculations for the OpenCode TUI. This file contains helper functions for rendering with the layout engine.

Package layout provides responsive layout calculations for the OpenCode TUI.

Index

Constants

View Source
const (
	// CharacterCellWidth is the typical width of a character cell in pixels.
	// This is used to convert pixel dimensions to cell dimensions.
	CharacterCellWidth = 8
	// CharacterCellHeight is the typical height of a character cell in pixels.
	// This is used to convert pixel dimensions to cell dimensions.
	CharacterCellHeight = 16

	// DefaultTopBarHeight is the default height of the top bar.
	DefaultTopBarHeight = 1
	// DefaultWarningBarHeight is the default height of the warning bar.
	DefaultWarningBarHeight = 1
	// DefaultBottomBarHeight is the default height of the bottom bar.
	DefaultBottomBarHeight = 1
	// DefaultSidebarMinWidth is the minimum width of the sidebar.
	DefaultSidebarMinWidth = 20
	// DefaultSidebarMaxWidth is the maximum width of the sidebar.
	DefaultSidebarMaxWidth = 45
	// DefaultSidebarRatio is the default ratio of sidebar width to terminal width (25%).
	DefaultSidebarRatio = 0.25
	// DefaultInputMinHeight is the minimum height of the input area.
	DefaultInputMinHeight = 3
	// DefaultInputMaxHeight is the maximum height of the input area.
	DefaultInputMaxHeight = 15
	// DefaultMinTerminalWidth is the minimum terminal width supported.
	DefaultMinTerminalWidth = 60
	// DefaultMinTerminalHeight is the minimum terminal height supported.
	DefaultMinTerminalHeight = 15
)

============================================================================ Layout Constants - Default dimensions based on HTML design ============================================================================ These are now in TERMINAL CELLS (Rows/Cols), not pixels!

Variables

This section is empty.

Functions

func AdaptiveHeight added in v1.10.0

func AdaptiveHeight(content string, padding int) int

AdaptiveHeight returns a height that fits content with optional padding.

func AdaptiveWidth added in v1.10.0

func AdaptiveWidth(content string, padding int) int

AdaptiveWidth returns a width that fits content with optional padding.

func Clamp added in v1.10.0

func Clamp(value, min, max int) int

Clamp ensures value is within min/max bounds. If value is less than min, returns min. If value is greater than max, returns max. Otherwise returns value unchanged.

func FlexJoinHorizontal added in v1.10.0

func FlexJoinHorizontal(align lipgloss.Position, boxes ...*Box) string

FlexJoinHorizontal joins boxes horizontally with optional spacing.

func FlexJoinVertical added in v1.10.0

func FlexJoinVertical(align lipgloss.Position, boxes ...*Box) string

FlexJoinVertical joins boxes vertically with optional spacing.

func GetBorderColor added in v1.10.0

func GetBorderColor(pane PaneType, focused PaneType) lipgloss.AdaptiveColor

GetBorderColor returns the appropriate border color for a pane based on whether it is focused or unfocused.

func GetBorderStyle added in v1.10.0

func GetBorderStyle(pane PaneType, focused PaneType) lipgloss.Border

GetBorderStyle returns the appropriate lipgloss.Border for a pane based on whether it is focused or unfocused.

func GetPaneStyle added in v1.10.0

func GetPaneStyle(pane PaneType, focused PaneType) lipgloss.Style

GetPaneStyle returns a lipgloss.Style configured for a specific pane with appropriate borders and colors.

func Height added in v1.10.0

func Height(s string) int

Height returns the number of lines in a string when rendered.

func JoinHorizontal added in v1.10.0

func JoinHorizontal(blocks ...string) string

JoinHorizontal joins multiple content blocks horizontally with proper spacing.

func JoinVertical added in v1.10.0

func JoinVertical(blocks ...string) string

JoinVertical joins multiple content blocks vertically with proper spacing.

func KeyMapToSlice

func KeyMapToSlice(t any) (bindings []key.Binding)

KeyMapToSlice extracts key bindings from a struct into a slice. The struct fields must be of type key.Binding.

func Max added in v1.10.0

func Max(a, b int) int

Max returns the larger of two integers.

func MeasureContent added in v1.10.0

func MeasureContent(content string) (width, height int)

MeasureContent returns the width and height needed to render content.

func Min added in v1.10.0

func Min(a, b int) int

Min returns the smaller of two integers.

func PixelsToCells added in v1.10.0

func PixelsToCells(pixelWidth, pixelHeight int) (cellsWidth, cellsHeight int)

PixelsToCells converts pixel dimensions to terminal cell dimensions. This is necessary because tea.WindowSizeMsg provides pixel dimensions, but the layout engine works with terminal cell dimensions. Typical character cell size is 8x16 pixels (width x height).

Note: This function uses conservative estimates. For more accurate conversion, use LayoutEngine.CalculateFromPixels() which can determine actual cell size.

func PlaceContent added in v1.10.0

func PlaceContent(box *Box, content string, hAlign, vAlign lipgloss.Position) string

PlaceContent positions content within a box using lipgloss placement.

func PlaceOverlay

func PlaceOverlay(
	x, y int,
	fg, bg string,
	shadow bool, opts ...WhitespaceOption,
) string

PlaceOverlay places fg (foreground) on top of bg (background) at position (x, y). The shadow parameter enables a drop shadow effect behind the foreground. Additional WhitespaceOption parameters can customize the placement behavior.

This function is useful for rendering dialogs, tooltips, or other overlay content on top of the main UI background.

func ResponsiveValue added in v1.10.0

func ResponsiveValue(terminalSize, threshold int, value, fallback int) int

ResponsiveValue returns value if terminal is large enough, otherwise returns fallback.

func ResponsiveWidth added in v1.10.0

func ResponsiveWidth(terminalWidth int, thresholds []int, values []int) int

ResponsiveWidth returns responsive width based on terminal width.

func Width added in v1.10.0

func Width(s string) int

Width returns the printable width of a string (ignoring ANSI escape codes).

Types

type Bindings

type Bindings interface {
	// BindingKeys returns the keyboard bindings for this component.
	BindingKeys() []key.Binding
}

Bindings is an interface for components that have keyboard bindings. Implement this to expose keyboard shortcuts to the application.

type Box added in v1.10.0

type Box struct {
	Rect
	Style   lipgloss.Style
	Content string
}

Box represents a rectangular region with styling for the TUI. It combines dimension (Rect) with lipgloss styling and content.

func ChatBox added in v1.10.0

func ChatBox(rect Rect) *Box

ChatBox creates a chat area box with proper padding.

func InputBox added in v1.10.0

func InputBox(rect Rect) *Box

InputBox creates an input area box.

func NewBox added in v1.10.0

func NewBox(width, height int, opts ...BoxOption) *Box

NewBox creates a new Box with the given dimensions and options. Use functional options to configure the box with custom styling and content.

Example:

box := NewBox(80, 24,
	WithBoxStyle(lipgloss.NewStyle().Background(lipgloss.Color("#222222"))),
	WithBoxContent("Hello, World!"),
)

func PanelBox added in v1.10.0

func PanelBox(rect Rect) *Box

PanelBox creates a panel-style box using the current theme.

func SidebarBox added in v1.10.0

func SidebarBox(rect Rect) *Box

SidebarBox creates a sidebar-style box.

func StatusBox added in v1.10.0

func StatusBox(rect Rect) *Box

StatusBox creates a status bar box.

func WarningBox added in v1.10.0

func WarningBox(rect Rect) *Box

WarningBox creates a warning bar box with orange background.

func (*Box) GetInnerDimensions added in v1.10.0

func (b *Box) GetInnerDimensions() (width, height int)

GetInnerDimensions returns the inner content dimensions accounting for borders/padding.

func (*Box) Render added in v1.10.0

func (b *Box) Render(content string) string

Render renders the box content with its style. It properly accounts for borders and padding to prevent layout wrapping.

func (*Box) RenderWithFullDimensions added in v1.10.0

func (b *Box) RenderWithFullDimensions(content string) string

RenderWithFullDimensions renders content using the FULL allocated dimensions. Use this when you need the outer dimensions (including borders).

type BoxOption added in v1.10.0

type BoxOption func(*Box)

BoxOption configures a Box using the functional options pattern.

func WithBoxBackground added in v1.10.0

func WithBoxBackground(color lipgloss.Color) BoxOption

WithBoxBackground sets the background color.

func WithBoxBorder added in v1.10.0

func WithBoxBorder(border lipgloss.Border) BoxOption

WithBoxBorder sets border on all sides.

func WithBoxBorderForeground added in v1.10.0

func WithBoxBorderForeground(color lipgloss.Color) BoxOption

WithBoxBorderForeground sets border color.

func WithBoxContent added in v1.10.0

func WithBoxContent(content string) BoxOption

WithBoxContent sets the content for the box.

func WithBoxForeground added in v1.10.0

func WithBoxForeground(color lipgloss.Color) BoxOption

WithBoxForeground sets the foreground (text) color.

func WithBoxMargin added in v1.10.0

func WithBoxMargin(margin int) BoxOption

WithBoxMargin sets margin on all sides.

func WithBoxPadding added in v1.10.0

func WithBoxPadding(padding int) BoxOption

WithBoxPadding sets padding on all sides.

func WithBoxPaddingXY added in v1.10.0

func WithBoxPaddingXY(horizontal, vertical int) BoxOption

WithBoxPaddingXY sets horizontal and vertical padding.

func WithBoxStyle added in v1.10.0

func WithBoxStyle(style lipgloss.Style) BoxOption

WithBoxStyle sets the lipgloss style for the box.

type Container

type Container interface {
	tea.Model
	Sizeable
	Bindings
}

Container is a UI component that can contain other tea.Model components with optional padding and borders.

func NewContainer

func NewContainer(content tea.Model, options ...ContainerOption) Container

NewContainer creates a new Container with the given content and options. It initializes the container with default values and applies any provided options.

type ContainerOption

type ContainerOption func(*container)

ContainerOption is a function that configures a Container.

func WithBorder

func WithBorder(top, right, bottom, left bool) ContainerOption

WithBorder allows you to set borders for each side of the container. You can specify different values for top, right, bottom, and left borders.

func WithBorderAll

func WithBorderAll() ContainerOption

WithBorderAll sets borders on all sides of the container.

func WithBorderHorizontal

func WithBorderHorizontal() ContainerOption

WithBorderHorizontal sets borders on the left and right sides of the container.

func WithBorderStyle

func WithBorderStyle(style lipgloss.Border) ContainerOption

WithBorderStyle sets the style of the border.

func WithBorderVertical

func WithBorderVertical() ContainerOption

WithBorderVertical sets borders on the top and bottom sides of the container.

func WithDoubleBorder

func WithDoubleBorder() ContainerOption

WithDoubleBorder sets the style of the border to DoubleBorder.

func WithPadding

func WithPadding(top, right, bottom, left int) ContainerOption

WithPadding allows you to set padding for each side of the container. You can specify different values for top, right, bottom, and left padding.

func WithPaddingAll

func WithPaddingAll(padding int) ContainerOption

WithPaddingAll sets the same padding value for all sides of the container.

func WithPaddingHorizontal

func WithPaddingHorizontal(padding int) ContainerOption

WithPaddingHorizontal sets the same padding value for the left and right sides of the container.

func WithPaddingVertical

func WithPaddingVertical(padding int) ContainerOption

WithPaddingVertical sets the same padding value for the top and bottom sides of the container.

func WithRoundedBorder

func WithRoundedBorder() ContainerOption

WithRoundedBorder sets the style of the border to RoundedBorder.

func WithThickBorder

func WithThickBorder() ContainerOption

WithThickBorder sets the style of the border to ThickBorder.

type Dimensions added in v1.10.0

type Dimensions struct {
	// Terminal
	TerminalWidth  int
	TerminalHeight int

	// Main sections
	TopBar      Rect
	WarningBar  Rect
	BottomBar   Rect
	ContentArea Rect // Combined sidebar + workspace

	// Content area splits
	Sidebar   Rect // Left panel (~320px or 25%)
	Workspace Rect // Right panel (remaining space)

	// Workspace splits
	ChatArea  Rect // Scrollable chat
	InputArea Rect // Input box
}

Dimensions holds the calculated dimensions for all UI sections. Each field represents a rectangular region with position and size.

type Focusable

type Focusable interface {
	// Focus gives focus to the component.
	Focus() tea.Cmd
	// Blur removes focus from the component.
	Blur() tea.Cmd
	// IsFocused returns true if the component currently has focus.
	IsFocused() bool
}

Focusable is an interface for components that can receive focus. Implement this interface to enable keyboard navigation support.

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

Footer represents the bottom bar of the TUI application. It displays status information, keyboard shortcuts, and contextual hints.

func NewFooter added in v1.10.0

func NewFooter() *Footer

NewFooter creates a new Footer component with default values.

func (*Footer) GetDimensions added in v1.10.0

func (f *Footer) GetDimensions() Rect

GetDimensions returns the current dimensions of the footer.

func (*Footer) Render added in v1.10.0

func (f *Footer) Render(content string) string

Render renders the footer with the given content.

func (*Footer) RenderDefault added in v1.10.0

func (f *Footer) RenderDefault() string

RenderDefault renders the footer with default styling and content.

func (*Footer) SetDimensions added in v1.10.0

func (f *Footer) SetDimensions(dims Rect) *Footer

SetDimensions sets the dimensions for the footer.

func (*Footer) SetFocused added in v1.10.0

func (f *Footer) SetFocused(focused bool) *Footer

SetFocused sets the focused state of the footer.

func (*Footer) SetHint added in v1.10.0

func (f *Footer) SetHint(hint string) *Footer

SetHint sets the hint message displayed in the footer.

func (*Footer) SetStatus added in v1.10.0

func (f *Footer) SetStatus(status string) *Footer

SetStatus sets the status message displayed in the footer.

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

Header represents the top bar of the TUI application. It displays application title, mode indicators, and status information.

func NewHeader added in v1.10.0

func NewHeader() *Header

NewHeader creates a new Header component with default values.

func (*Header) GetDimensions added in v1.10.0

func (h *Header) GetDimensions() Rect

GetDimensions returns the current dimensions of the header.

func (*Header) Render added in v1.10.0

func (h *Header) Render(content string) string

Render renders the header with the given content.

func (*Header) RenderDefault added in v1.10.0

func (h *Header) RenderDefault() string

RenderDefault renders the header with default styling and content.

func (*Header) SetDimensions added in v1.10.0

func (h *Header) SetDimensions(dims Rect) *Header

SetDimensions sets the dimensions for the header.

func (*Header) SetFocused added in v1.10.0

func (h *Header) SetFocused(focused bool) *Header

SetFocused sets the focused state of the header.

func (*Header) SetMode added in v1.10.0

func (h *Header) SetMode(mode string) *Header

SetMode sets the current mode displayed in the header.

func (*Header) SetTitle added in v1.10.0

func (h *Header) SetTitle(title string) *Header

SetTitle sets the header title.

type LayoutConfig added in v1.10.0

type LayoutConfig struct {
	// Sidebar configuration
	SidebarWidth    int     // Fixed width, 0 = use ratio
	SidebarRatio    float64 // Percentage of total width (0.0-1.0)
	SidebarMinWidth int     // Minimum sidebar width
	SidebarMaxWidth int     // Maximum sidebar width

	// Fixed heights (0 = auto-calculate)
	TopBarHeight     int
	WarningBarHeight int
	BottomBarHeight  int

	// Input configuration
	InputMinHeight int
	InputMaxHeight int
	InputRatio     float64 // Ratio of remaining space for input

	// Padding
	ContentPaddingHorizontal int
	ContentPaddingVertical   int
}

LayoutConfig contains configuration options for the layout engine. All values are used to customize the layout calculation.

func DefaultLayoutConfig added in v1.10.0

func DefaultLayoutConfig() LayoutConfig

DefaultLayoutConfig returns the default layout configuration. This configuration uses sensible defaults for a standard chat interface.

type LayoutEngine added in v1.10.0

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

LayoutEngine calculates and manages responsive dimensions for all UI sections. It provides methods to compute layout based on terminal size and configuration.

func NewLayoutEngine added in v1.10.0

func NewLayoutEngine() *LayoutEngine

NewLayoutEngine creates a new layout engine with default configuration.

func (*LayoutEngine) Calculate added in v1.10.0

func (e *LayoutEngine) Calculate(width, height int) Dimensions

Calculate computes all layout dimensions based on terminal size (in cells). This should be called with cell dimensions from the terminal.

func (*LayoutEngine) CalculateFromPixels added in v1.10.0

func (e *LayoutEngine) CalculateFromPixels(pixelWidth, pixelHeight int) Dimensions

CalculateFromPixels computes layout from pixel dimensions. It stores the original pixel values and converts to cells using the stored cell size, or estimates it if not yet determined.

func (*LayoutEngine) GetChatStyle added in v1.10.0

func (e *LayoutEngine) GetChatStyle() lipgloss.Style

GetChatStyle returns a lipgloss style for the chat area with padding.

func (*LayoutEngine) GetDimensions added in v1.10.0

func (e *LayoutEngine) GetDimensions() Dimensions

GetDimensions returns the cached dimensions. Returns zero dimensions if Calculate() hasn't been called.

func (*LayoutEngine) GetInputStyle added in v1.10.0

func (e *LayoutEngine) GetInputStyle() lipgloss.Style

GetInputStyle returns a lipgloss style for the input area.

func (*LayoutEngine) GetPixelDimensions added in v1.10.0

func (e *LayoutEngine) GetPixelDimensions() (int, int)

GetPixelDimensions returns the original pixel dimensions. Returns (0, 0) if CalculateFromPixels() hasn't been called.

func (*LayoutEngine) GetSidebarStyle added in v1.10.0

func (e *LayoutEngine) GetSidebarStyle() lipgloss.Style

GetSidebarStyle returns a lipgloss style for the sidebar with proper dimensions.

func (*LayoutEngine) GetTerminalDimensions added in v1.10.0

func (e *LayoutEngine) GetTerminalDimensions() (int, int)

GetTerminalDimensions returns the terminal dimensions in cells.

func (*LayoutEngine) GetWorkspaceStyle added in v1.10.0

func (e *LayoutEngine) GetWorkspaceStyle() lipgloss.Style

GetWorkspaceStyle returns a lipgloss style for the workspace.

func (*LayoutEngine) WithConfig added in v1.10.0

func (e *LayoutEngine) WithConfig(config LayoutConfig) *LayoutEngine

WithConfig sets the layout configuration and returns the engine for chaining.

type LayoutManager added in v1.10.0

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

LayoutManager calculates and manages the dimensions of a 3-pane TUI layout. It divides the terminal window into:

  • Header: fixed 3 lines at the top
  • Footer: fixed 1 line at the bottom
  • Sidebar: 20-25% of remaining width on the left
  • Main: remaining space for the primary content

func NewLayoutManager added in v1.10.0

func NewLayoutManager(width, height int) *LayoutManager

NewLayoutManager creates a new LayoutManager with the given dimensions.

func (*LayoutManager) Calculate added in v1.10.0

func (m *LayoutManager) Calculate(width, height int)

Calculate recalculates all pane dimensions based on the given window size.

func (*LayoutManager) GetFocusedPane added in v1.10.0

func (m *LayoutManager) GetFocusedPane() PaneType

GetFocusedPane returns the currently focused pane.

func (*LayoutManager) GetFooterDimensions added in v1.10.0

func (m *LayoutManager) GetFooterDimensions() PaneDimensions

GetFooterDimensions returns the dimensions for the footer pane.

func (*LayoutManager) GetHeaderDimensions added in v1.10.0

func (m *LayoutManager) GetHeaderDimensions() PaneDimensions

GetHeaderDimensions returns the dimensions for the header pane.

func (*LayoutManager) GetHeight added in v1.10.0

func (m *LayoutManager) GetHeight() int

GetHeight returns the current total height.

func (*LayoutManager) GetMainDimensions added in v1.10.0

func (m *LayoutManager) GetMainDimensions() PaneDimensions

GetMainDimensions returns the dimensions for the main content pane.

func (*LayoutManager) GetSidebarDimensions added in v1.10.0

func (m *LayoutManager) GetSidebarDimensions() PaneDimensions

GetSidebarDimensions returns the dimensions for the sidebar pane.

func (*LayoutManager) GetWidth added in v1.10.0

func (m *LayoutManager) GetWidth() int

GetWidth returns the current total width.

func (*LayoutManager) Render added in v1.10.0

func (m *LayoutManager) Render(headerContent, sidebarContent, mainContent, footerContent string) string

Render assembles and renders the complete layout with all panes. It takes content strings for each pane and returns the complete UI. CRITICAL: This properly calculates inner dimensions accounting for borders to prevent layout wrapping issues.

func (*LayoutManager) SetFocusedPane added in v1.10.0

func (m *LayoutManager) SetFocusedPane(pane PaneType)

SetFocusedPane sets which pane currently has focus.

type MainLayout added in v1.10.0

type MainLayout struct {
	TopBar  lipgloss.Style
	Sidebar lipgloss.Style
	Content lipgloss.Style
	Status  lipgloss.Style
}

MainLayout holds the lipgloss styles for all main layout sections.

func BuildMainLayout added in v1.10.0

func BuildMainLayout(dims *Dimensions, theme theme.Theme) MainLayout

BuildMainLayout creates the complete main layout structure with all styles.

type PaneDimensions added in v1.10.0

type PaneDimensions struct {
	Width  int
	Height int
}

PaneDimensions holds the width and height of a layout pane.

type PaneType added in v1.10.0

type PaneType int

PaneType represents the different panes in the layout.

const (
	PaneHeader PaneType = iota
	PaneSidebar
	PaneMain
	PaneFooter
)

type Rect added in v1.10.0

type Rect struct {
	X      int // Horizontal position (column)
	Y      int // Vertical position (row)
	Width  int // Width in characters
	Height int // Height in rows
}

Rect represents a rectangular region with position and size.

type Renderer added in v1.10.0

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

Renderer combines layout calculations with theme-aware rendering.

func NewRenderer added in v1.10.0

func NewRenderer(engine *LayoutEngine) *Renderer

NewRenderer creates a new renderer with the given layout engine.

func NewRendererWithTheme added in v1.10.0

func NewRendererWithTheme(engine *LayoutEngine, t theme.Theme) *Renderer

NewRendererWithTheme creates a new renderer with custom theme.

func (*Renderer) RenderBottomBar added in v1.10.0

func (r *Renderer) RenderBottomBar(content string) string

RenderBottomBar renders the bottom bar (status bar) section.

func (*Renderer) RenderChatArea added in v1.10.0

func (r *Renderer) RenderChatArea(content string) string

RenderChatArea renders the main chat area.

func (*Renderer) RenderChatMessage added in v1.10.0

func (r *Renderer) RenderChatMessage(role, content, timestamp string) string

RenderChatMessage renders a chat message with role and content.

func (*Renderer) RenderDiffBlock added in v1.10.0

func (r *Renderer) RenderDiffBlock(lines []string) string

RenderDiffBlock renders a complete diff block.

func (*Renderer) RenderDiffLine added in v1.10.0

func (r *Renderer) RenderDiffLine(lineType, content string) string

RenderDiffLine renders a single diff line with appropriate styling.

func (*Renderer) RenderInputArea added in v1.10.0

func (r *Renderer) RenderInputArea(content string) string

RenderInputArea renders the input area.

func (*Renderer) RenderMainLayout added in v1.10.0

func (r *Renderer) RenderMainLayout(
	topBarContent,
	warningContent,
	sidebarContent,
	chatContent,
	inputContent,
	bottomBarContent string,
) string

RenderMainLayout renders the complete main layout with all sections.

func (*Renderer) RenderSidebar added in v1.10.0

func (r *Renderer) RenderSidebar(content string) string

RenderSidebar renders the sidebar section with proper borders.

func (*Renderer) RenderStatusBar added in v1.10.0

func (r *Renderer) RenderStatusBar(segments []string, activeIndex int) string

RenderStatusBar renders a complete status bar with segments.

func (*Renderer) RenderStatusSegment added in v1.10.0

func (r *Renderer) RenderStatusSegment(text string, isActive bool) string

RenderStatusSegment renders a single status segment with Powerline style.

func (*Renderer) RenderToolBadge added in v1.10.0

func (r *Renderer) RenderToolBadge(toolName string) string

RenderToolBadge renders a tool name as a badge.

func (*Renderer) RenderTopBar added in v1.10.0

func (r *Renderer) RenderTopBar(content string) string

RenderTopBar renders the top bar section.

func (*Renderer) RenderWarningBar added in v1.10.0

func (r *Renderer) RenderWarningBar(content string) string

RenderWarningBar renders the warning bar section.

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

Sidebar represents the left pane of the TUI application. It displays file tree, session list, or other navigation content.

func NewSidebar added in v1.10.0

func NewSidebar() *Sidebar

NewSidebar creates a new Sidebar component with default values.

func (*Sidebar) GetDimensions added in v1.10.0

func (s *Sidebar) GetDimensions() PaneDimensions

GetDimensions returns the current dimensions of the sidebar.

func (*Sidebar) GetSelected added in v1.10.0

func (s *Sidebar) GetSelected() int

GetSelected returns the currently selected item index.

func (*Sidebar) Render added in v1.10.0

func (s *Sidebar) Render(content string) string

Render renders the sidebar with the given content.

func (*Sidebar) RenderDefault added in v1.10.0

func (s *Sidebar) RenderDefault() string

RenderDefault renders the sidebar with default styling and content.

func (*Sidebar) RenderItem added in v1.10.0

func (s *Sidebar) RenderItem(index int, itemContent string, isSelected bool) string

RenderItem renders a single sidebar item with the given index and content.

func (*Sidebar) SetDimensions added in v1.10.0

func (s *Sidebar) SetDimensions(width, height int) *Sidebar

SetDimensions sets the dimensions for the sidebar.

func (*Sidebar) SetFocused added in v1.10.0

func (s *Sidebar) SetFocused(focused bool) *Sidebar

SetFocused sets the focused state of the sidebar.

func (*Sidebar) SetItems added in v1.10.0

func (s *Sidebar) SetItems(items []string) *Sidebar

SetItems sets the sidebar items.

func (*Sidebar) SetSelected added in v1.10.0

func (s *Sidebar) SetSelected(index int) *Sidebar

SetSelected sets the selected item index.

func (*Sidebar) SetTitle added in v1.10.0

func (s *Sidebar) SetTitle(title string) *Sidebar

SetTitle sets the sidebar title.

type Sizeable

type Sizeable interface {
	// SetSize sets the dimensions of the component.
	SetSize(width, height int) tea.Cmd
	// GetSize returns the current dimensions of the component.
	GetSize() (int, int)
}

Sizeable is an interface for components that can be sized. All visual components should implement this to support responsive layouts.

type SplitPaneLayout

type SplitPaneLayout interface {
	tea.Model
	Sizeable
	Bindings
	// SetLeftPanel sets the left panel of the split pane.
	SetLeftPanel(panel Container) tea.Cmd
	// SetRightPanel sets the right panel of the split pane.
	SetRightPanel(panel Container) tea.Cmd
	// SetBottomPanel sets the bottom panel of the split pane.
	SetBottomPanel(panel Container) tea.Cmd

	// ClearLeftPanel removes the left panel.
	ClearLeftPanel() tea.Cmd
	// ClearRightPanel removes the right panel.
	ClearRightPanel() tea.Cmd
	// ClearBottomPanel removes the bottom panel.
	ClearBottomPanel() tea.Cmd
}

SplitPaneLayout is an interface for a split pane layout that divides the terminal into left/right panels and optionally a bottom panel. It implements tea.Model, Sizeable, and Bindings interfaces.

func NewSplitPane

func NewSplitPane(options ...SplitPaneOption) SplitPaneLayout

NewSplitPane creates a new SplitPaneLayout with optional configuration. The default horizontal ratio is 0.7 (70% left, 30% right) and vertical ratio is 0.9 (90% top, 10% bottom).

type SplitPaneOption

type SplitPaneOption func(*splitPaneLayout)

SplitPaneOption is a functional option for configuring a SplitPaneLayout.

func WithBottomPanel

func WithBottomPanel(panel Container) SplitPaneOption

WithBottomPanel sets the initial bottom panel for the split pane.

func WithLeftPanel

func WithLeftPanel(panel Container) SplitPaneOption

WithLeftPanel sets the initial left panel for the split pane.

func WithRatio

func WithRatio(ratio float64) SplitPaneOption

WithRatio sets the horizontal split ratio. A ratio of 0.7 means 70% for left panel, 30% for right.

func WithRightPanel

func WithRightPanel(panel Container) SplitPaneOption

WithRightPanel sets the initial right panel for the split pane.

func WithVerticalRatio

func WithVerticalRatio(ratio float64) SplitPaneOption

WithVerticalRatio sets the vertical split ratio. A ratio of 0.9 means 90% for top section, 10% for bottom panel.

type WhitespaceOption

type WhitespaceOption func(*whitespace)

WhitespaceOption sets a styling rule for rendering whitespace.

Jump to

Keyboard shortcuts

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