header

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: 4 Imported by: 0

Documentation

Overview

Package header provides a header component for the terminal user interface. The header displays the current task and can be styled using themes.

Component Structure

The Model type represents the header 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:

  • WithTask: Sets the task text to display
  • WithTheme: Sets the theme for styling the component

Message Handling

The component responds to:

  • tea.WindowSizeMsg: Updates viewport dimensions and text wrapping

Styling

Each element is styled using dedicated styling methods:

  • containerStyle: provides the overall header styling with background
  • textStyle: formats the text content with appropriate colors

Theme Integration:

  • Base colors are used for backgrounds and text
  • All colors are configurable through the theme

Component Features

The component automatically handles:

  • Dynamic resizing based on window width
  • Text wrapping for long task descriptions
  • Bold label with regular task text
  • Proper spacing and padding
  • Theme-based styling

Thread Safety

The header component is safe for concurrent access:

  • All updates are handled through message passing
  • No internal mutable state is exposed
  • Theme and task text are immutable after creation

Example usage:

header := header.New(
	header.WithTask("Current Task"),
	header.WithTheme(myTheme),
)

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

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

// Render the component
view := header.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 a header component that displays the current task.

func New

func New(opts ...Option) *Model

New creates a new header Model with the given options. If no options are provided, it creates a header with default values.

func (*Model) Init

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

Init initializes the header Model. It implements the tea.Model interface.

func (*Model) Update

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

Update handles messages and updates the header Model accordingly. It implements the tea.Model interface.

func (*Model) View

func (m *Model) View() string

View renders the header component.

type Option

type Option func(*Model)

Option is a function that modifies the Model.

func WithTask

func WithTask(task string) Option

WithTask returns an Option that sets the task text in the header.

func WithTheme

func WithTheme(theme thememanager.Theme) Option

WithTheme returns an Option that sets the theme for the header.

Jump to

Keyboard shortcuts

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