commandspane

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package commandspane provides a commands pane component for the terminal user interface.

The commands pane component displays a scrollable list of executed commands, including:

  • Timestamp of execution in [HH:MM:SS] format
  • Working directory with a distinct background
  • Command text in an accent color

Component Structure

The Model type represents the commands pane component and provides the following methods:

  • Init: Initializes the component (required by bubbletea.Model)
  • Update: Handles messages and updates the component state
  • View: Renders the component's current state

The component supports configuration through options:

  • WithTheme: Sets the theme for styling the component

Styling

Each command is styled using dedicated styling methods:

  • timestampStyle: formats the timestamp with a neutral color
  • workdirStyle: highlights the working directory with a distinct background
  • commandStyle: renders the command text in an accent color
  • containerStyle: provides the overall pane styling with borders
  • titleStyle: formats the "Commands" title

Theme Integration:

  • Base colors are used for backgrounds and borders
  • Accent colors are used for command text highlighting
  • All colors are configurable through the theme

Component Features

The component automatically handles:

  • Dynamic resizing of the viewport
  • Command history accumulation
  • Automatic scrolling to the latest command
  • Proper text wrapping based on available width
  • Long command wrapping with proper indentation
  • Viewport scrolling for command history

Message Handling

The component responds to:

  • tea.WindowSizeMsg: Updates viewport dimensions
  • tool.Command: Adds new command to history

The component is built using the Bubble Tea framework and Lip Gloss styling library, providing a consistent look and feel with the rest of the application.

Example usage:

commandspane := commandspane.New(
    commandspane.WithTheme(theme),
)

// Initialize the component
cmd := commandspane.Init()

// Handle window resize
model, cmd := commandspane.Update(tea.WindowSizeMsg{Width: 100, Height: 50})

// Add a new command
model, cmd = commandspane.Update(tool.Command{
    Command:          "ls -la",
    WorkingDirectory: "~/project",
    StartedAt:        time.Now(),
})

// Render the component
view := commandspane.View()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Model

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

Model represents the commands pane component. It maintains the state of the commands list and viewport, handling command history and display formatting.

func New

func New(opts ...Option) *Model

New creates a new commands pane component.

func (*Model) Init

func (m *Model) Init() tea.Cmd

Init initializes the commands pane component.

func (*Model) Update

func (m *Model) Update(msg tea.Msg) (*Model, tea.Cmd)

Update handles messages and updates the commands pane component.

func (*Model) View

func (m *Model) View() string

View renders the commands pane component.

type Option

type Option func(*Model)

Option is a function that modifies the Model.

func WithTheme

func WithTheme(theme thememanager.Theme) Option

WithTheme sets the theme for the commands pane component.

Jump to

Keyboard shortcuts

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