ui

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package ui provides the user interface for the application.

Index

Constants

View Source
const (
	// Borders and padding
	BORDER_SIZE       = 1
	HORIZONTAL_MARGIN = 2
	VERTICAL_MARGIN   = 1

	// Reserved space
	TITLE_HEIGHT        = 2  // Title + border
	STATUS_HEIGHT       = 2  // Status message
	INPUT_HEIGHT        = 2  // Input box + border
	HELP_TEXT_HEIGHT    = 1  // Help text
	BOTTOM_MARGIN       = 2  // Extra margin at bottom
	MIN_VIEWPORT_HEIGHT = 10 // Minimum height for chat viewport

	// Minimum dimensions
	MIN_TERMINAL_WIDTH  = 40
	MIN_TERMINAL_HEIGHT = 20
	MIN_MESSAGE_WIDTH   = 20
)

Layout constants

Variables

View Source
var (
	PrimaryColor    = lipgloss.Color("#FF6B9D")
	SecondaryColor  = lipgloss.Color("#B8E6B8")
	AccentColor     = lipgloss.Color("#FFE66D")
	BackgroundColor = lipgloss.Color("#1A1A2E")
	TextColor       = lipgloss.Color("#FFFFFF")
	MutedColor      = lipgloss.Color("#8E8E93")
	ErrorColor      = lipgloss.Color("#FF4757")
	SuccessColor    = lipgloss.Color("#2ECC71")
	WarningColor    = lipgloss.Color("#F39C12")
	InfoColor       = lipgloss.Color("#3498DB")

	TitleColor   = lipgloss.Color("#6143df")
	ContentColor = lipgloss.Color("#ff79d0")
	// Message background colors (improved for better contrast)
	UserBgColor      = lipgloss.Color("#2563eb") // Modern blue
	AssistantBgColor = lipgloss.Color("#6143df") // Modern purple
	SystemBgColor    = lipgloss.Color("#6b7280") // Neutral gray
)

Theme colors

View Source
var (
	// Header styles
	TitleStyle = lipgloss.NewStyle().
				Foreground(TitleColor).
				Bold(true).Transform(strings.ToUpper).MarginBottom(1).MarginTop(1).MarginLeft(2)

	ContentStyle = lipgloss.NewStyle().
					Foreground(ContentColor).MarginLeft(4)

	SubtitleStyle = lipgloss.NewStyle().
					Foreground(SecondaryColor).
					Bold(true).
					MarginBottom(0)

	MutedStyle = lipgloss.NewStyle().
				Foreground(MutedColor).
				Italic(true)

	// Message styles
	UserMessageStyle = lipgloss.NewStyle().
						Foreground(AccentColor).
						Bold(true).
						Padding(0, 1).
						Border(lipgloss.RoundedBorder()).
						BorderForeground(AccentColor).
						BorderLeft(true)

	AssistantMessageStyle = lipgloss.NewStyle().
							Foreground(SecondaryColor).
							Padding(0, 1).
							Border(lipgloss.RoundedBorder()).
							BorderForeground(SecondaryColor).
							BorderLeft(true)

	SystemMessageStyle = lipgloss.NewStyle().
						Foreground(MutedColor).
						Italic(true)
	// Status styles
	SuccessStyle = lipgloss.NewStyle().
					Foreground(SuccessColor).
					Bold(true)

	ErrorStyle = lipgloss.NewStyle().
				Foreground(ErrorColor).
				Bold(true)

	WarningStyle = lipgloss.NewStyle().
					Foreground(WarningColor).
					Bold(true)

	InfoStyle = lipgloss.NewStyle().
				Foreground(InfoColor).
				Bold(true)

	// Input styles
	InputStyle = lipgloss.NewStyle().
				Foreground(TextColor).
				Border(lipgloss.RoundedBorder()).
				BorderForeground(PrimaryColor).
				MarginBottom(1)

	// List styles
	ListItemStyle = lipgloss.NewStyle().
					Foreground(TextColor).
					Padding(0, 2)

	SelectedListItemStyle = lipgloss.NewStyle().
							Foreground(BackgroundColor).
							Background(PrimaryColor).
							Bold(true).
							Padding(0, 2)

	// Progress styles
	ProgressBarStyle = lipgloss.NewStyle().
						Foreground(PrimaryColor)

	ProgressTextStyle = lipgloss.NewStyle().
						Foreground(MutedColor)
)

Common styles

View Source
var ClockEmojis = []string{"🕛", "🕐", "🕑", "🕒", "🕓", "🕔", "🕕", "🕖", "🕘", "🕙"}

ClockEmojis for message age indication

Functions

func GetAssistantMessageStyle

func GetAssistantMessageStyle(terminalWidth int) lipgloss.Style

func GetChatBoxStyle

func GetChatBoxStyle(terminalWidth, terminalHeight int) lipgloss.Style

GetChatBoxStyle Chat box styles

func GetChatLayoutDimensions

func GetChatLayoutDimensions(terminalWidth, terminalHeight int) (viewportWidth, viewportHeight, inputHeight int)

GetChatLayoutDimensions Responsive layout helper

func GetChatTitleStyle

func GetChatTitleStyle(terminalWidth int) lipgloss.Style

func GetInputBoxStyle

func GetInputBoxStyle(terminalWidth int) lipgloss.Style

GetInputBoxStyle box style

func GetStatusStyle

func GetStatusStyle(terminalWidth int) lipgloss.Style

GetStatusStyle Status message style

func GetTerminalWidth

func GetTerminalWidth() int

GetTerminalWidth returns the current terminal width with fallback

func GetUserMessageStyle

func GetUserMessageStyle(terminalWidth int) lipgloss.Style

GetUserMessageStyle styles with proper width

func InitSpinner

func InitSpinner() spinner.Model

InitSpinner initializes the spinner component.

func InitTerminalSize

func InitTerminalSize() (int, int)

InitTerminalSize returns width and height, using defaults on error.

func InitTextArea

func InitTextArea(width, height int) textarea.Model

InitTextArea initializes the textarea component.

func InitViewport

func InitViewport(width, height int) viewport.Model

InitViewport initializes the viewport component.

func RenderAssistantMessage

func RenderAssistantMessage(personaName, message string, terminalWidth int, messageIndex int, isLatest bool) string

func RenderChatBoxBorder

func RenderChatBoxBorder(content string, terminalWidth, terminalHeight int) string

func RenderChatBoxTitle

func RenderChatBoxTitle(title string, terminalWidth int) string

RenderChatBoxTitle Chat box with decorative border

func RenderError

func RenderError(message string) string

func RenderGeneratingAudioStatus

func RenderGeneratingAudioStatus(terminalWidth int) string

RenderGeneratingAudioStatus Status messages with animated emojis

func RenderHelpBox

func RenderHelpBox(title, content string, terminalWidth int) string

RenderHelpBox renders help content in a chat-style box

func RenderInfo

func RenderInfo(message string) string

func RenderInputBox

func RenderInputBox(content string, terminalWidth int) string

func RenderMessageSpacing

func RenderMessageSpacing() string

Helper function to add visual spacing between message groups

func RenderMessageWithSeparator

func RenderMessageWithSeparator(message string, isLast bool) string

RenderMessageWithSeparator Enhanced message rendering with better visual separation

func RenderMuted

func RenderMuted(message string) string

RenderMuted helper function

func RenderMutedStatus

func RenderMutedStatus(terminalWidth int) string

RenderMutedStatus Status messages with animated emojis

func RenderPersonaDetails

func RenderPersonaDetails(persona, voice, instructions, prompt string, historyCount int, terminalWidth int) string

RenderPersonaDetails renders persona details in a chat-style box

func RenderPersonaListBox

func RenderPersonaListBox(personas []string, terminalWidth int) string

RenderPersonaListBox renders persona list in a chat-style box

func RenderPlayingStatus

func RenderPlayingStatus(terminalWidth int) string

RenderPlayingStatus Status messages with animated emojis

func RenderRecordingStatus

func RenderRecordingStatus(terminalWidth int) string

RenderRecordingStatus Status messages with animated emojis

func RenderSubtitle

func RenderSubtitle(subtitle string) string

func RenderSuccess

func RenderSuccess(message string) string

func RenderThinkingStatus

func RenderThinkingStatus(terminalWidth int) string

RenderThinkingStatus Status messages with animated emojis

func RenderTitle

func RenderTitle(title string) string

RenderTitle helper functions

func RenderTranscribingStatus

func RenderTranscribingStatus(terminalWidth int) string

RenderTranscribingStatus Status messages with animated emojis

func RenderUserMessage

func RenderUserMessage(message string, terminalWidth int, messageIndex int, isLatest bool) string

RenderUserMessage message renderers with PlaceHorizontal:

func RenderWarning

func RenderWarning(message string) string

Types

type AppMode

type AppMode int
const (
	ModePersonaSelector AppMode = iota
	ModeChat
)

type ChatModel

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

func NewChatModel

func NewChatModel(p *persona.Persona, ai *openai.OpenAI, manager *storage.Manager, inputDevice string, silenceThreshold int, silenceDuration int) *ChatModel

func NewChatModelWithSelector

func NewChatModelWithSelector(manager *storage.Manager, config *config.Config, openaiAPIKey string) *ChatModel

NewChatModelWithSelector creates a new chat model that starts with persona selection

func (*ChatModel) Cleanup

func (m *ChatModel) Cleanup()

Cleanup cleans up resources when the chat is closed

func (*ChatModel) Init

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

func (*ChatModel) SwitchToPersona

func (m *ChatModel) SwitchToPersona(personaName string) error

SwitchToPersona switches the chat model to a specific persona

func (*ChatModel) Update

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

func (*ChatModel) View

func (m *ChatModel) View() string

type ChatState

type ChatState int
const (
	StateIdle ChatState = iota
	StateRecording
	StateTranscribing
	StateChatting
	StateGeneratingAudio
	StatePlaying
	StateError
)

type PersonaItem

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

PersonaItem pour la liste des personas

func (PersonaItem) Description

func (i PersonaItem) Description() string

func (PersonaItem) FilterValue

func (i PersonaItem) FilterValue() string

func (PersonaItem) Title

func (i PersonaItem) Title() string

Jump to

Keyboard shortcuts

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