chat.go

 1package model
 2
 3import (
 4	"github.com/charmbracelet/bubbles/v2/key"
 5	tea "github.com/charmbracelet/bubbletea/v2"
 6	"github.com/charmbracelet/crush/internal/app"
 7	"github.com/charmbracelet/crush/internal/ui/common"
 8)
 9
10// ChatKeyMap defines key bindings for the chat model.
11type ChatKeyMap struct {
12	NewSession    key.Binding
13	AddAttachment key.Binding
14	Cancel        key.Binding
15	Tab           key.Binding
16	Details       key.Binding
17}
18
19// DefaultChatKeyMap returns the default key bindings for the chat model.
20func DefaultChatKeyMap() ChatKeyMap {
21	return ChatKeyMap{
22		NewSession: key.NewBinding(
23			key.WithKeys("ctrl+n"),
24			key.WithHelp("ctrl+n", "new session"),
25		),
26		AddAttachment: key.NewBinding(
27			key.WithKeys("ctrl+f"),
28			key.WithHelp("ctrl+f", "add attachment"),
29		),
30		Cancel: key.NewBinding(
31			key.WithKeys("esc", "alt+esc"),
32			key.WithHelp("esc", "cancel"),
33		),
34		Tab: key.NewBinding(
35			key.WithKeys("tab"),
36			key.WithHelp("tab", "change focus"),
37		),
38		Details: key.NewBinding(
39			key.WithKeys("ctrl+d"),
40			key.WithHelp("ctrl+d", "toggle details"),
41		),
42	}
43}
44
45// ChatModel represents the chat UI model.
46type ChatModel struct {
47	app *app.App
48	com *common.Common
49
50	keyMap ChatKeyMap
51}
52
53// NewChatModel creates a new instance of ChatModel.
54func NewChatModel(com *common.Common, app *app.App) *ChatModel {
55	return &ChatModel{
56		app:    app,
57		com:    com,
58		keyMap: DefaultChatKeyMap(),
59	}
60}
61
62// Init initializes the chat model.
63func (m *ChatModel) Init() tea.Cmd {
64	return nil
65}
66
67// Update handles incoming messages and updates the chat model state.
68func (m *ChatModel) Update(msg tea.Msg) (*ChatModel, tea.Cmd) {
69	// Handle messages here
70	return m, nil
71}
72
73// View renders the chat model's view.
74func (m *ChatModel) View() string {
75	return "Chat Model View"
76}
77
78// ShortHelp returns a brief help view for the chat model.
79func (m *ChatModel) ShortHelp() []key.Binding {
80	return nil
81}
82
83// FullHelp returns a detailed help view for the chat model.
84func (m *ChatModel) FullHelp() [][]key.Binding {
85	return nil
86}