released the mock

This commit is contained in:
Luxferre
2026-03-21 18:32:07 +02:00
parent 6db2d20652
commit 4b2474b403
5 changed files with 305 additions and 28 deletions
+31 -21
View File
@@ -117,6 +117,27 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
)
switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.width = msg.Width
m.height = msg.Height
headerHeight := 1
inputHeight := 5 // Textarea height(3) + border/padding
vpWidth := msg.Width - 4 // Account for viewportStyle padding and border
vpHeight := msg.Height - headerHeight - inputHeight - 2
if !m.ready {
m.viewport = viewport.New(vpWidth, vpHeight)
m.viewport.SetContent(strings.Join(m.messages, "\n\n"))
m.ready = true
} else {
m.viewport.Width = vpWidth
m.viewport.Height = vpHeight
}
m.textarea.SetWidth(msg.Width - 4)
case tea.KeyMsg:
switch msg.Type {
case tea.KeyCtrlC, tea.KeyEsc:
@@ -129,40 +150,29 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if strings.TrimSpace(v) == "" || m.isThinking {
return m, nil
}
m.messages = append(m.messages, userStyle.Render("You")+"\n"+v)
wrappedUser := lipgloss.NewStyle().Width(m.viewport.Width).Render(userStyle.Render("You") + "\n" + v)
m.messages = append(m.messages, wrappedUser)
m.textarea.Reset()
m.viewport.SetContent(strings.Join(m.messages, "\n\n"))
m.viewport.GotoBottom()
m.isThinking = true
return m, m.runAgent(v)
}
case agentResponseMsg:
m.isThinking = false
var newMsg string
if msg.err != nil {
m.messages = append(m.messages, sysStyle.Render(fmt.Sprintf("Error: %v", msg.err)))
newMsg = sysStyle.Render(fmt.Sprintf("Error: %v", msg.err))
} else {
m.messages = append(m.messages, agentStyle.Render("Sidekick")+"\n"+msg.response)
newMsg = agentStyle.Render("Sidekick") + "\n" + msg.response
}
wrappedMsg := lipgloss.NewStyle().Width(m.viewport.Width).Render(newMsg)
m.messages = append(m.messages, wrappedMsg)
m.viewport.SetContent(strings.Join(m.messages, "\n\n"))
m.viewport.GotoBottom()
return m, nil
case tea.WindowSizeMsg:
m.width = msg.Width
m.height = msg.Height
headerHeight := 1
inputHeight := 5 // Textarea height(3) + border/padding
if !m.ready {
m.viewport = viewport.New(msg.Width-2, msg.Height-headerHeight-inputHeight-2)
m.viewport.SetContent(strings.Join(m.messages, "\n\n"))
m.ready = true
} else {
m.viewport.Width = msg.Width - 2
m.viewport.Height = msg.Height - headerHeight - inputHeight - 2
}
m.textarea.SetWidth(msg.Width - 4)
}
m.textarea, tiCmd = m.textarea.Update(msg)
@@ -192,7 +202,7 @@ func (m model) View() string {
statusStyle.Render(" "+status+" "),
)
vpView := viewportStyle.Width(m.width - 2).Height(m.height - 10).Render(m.viewport.View())
vpView := viewportStyle.Width(m.width - 2).Render(m.viewport.View())
taStyle := textareaStyle
if m.textarea.Focused() {