ByteSock/internal/ui/update.go
2025-06-23 22:07:37 +02:00

38 lines
756 B
Go

package ui
import (
tea "github.com/charmbracelet/bubbletea"
)
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.Type {
case tea.KeyEnter:
m.logs = append(m.logs, "-> "+m.input)
m.input = ""
case tea.KeyBackspace:
if len(m.input) > 0 {
m.input = m.input[:len(m.input)-1]
}
case tea.KeyCtrlH:
msg := msgInfoStyle.Render(
"\nThe following actions are available:" +
"\n* Ctrl+H : Help" +
"\n* Ctrl+C : Exit" +
"\n* Ctrl+F : Command")
m.logs = append(m.logs, msg)
case tea.KeyCtrlC:
return m, tea.Quit
default:
m.input += msg.String()
}
case tea.WindowSizeMsg:
m.width = msg.Width
m.height = msg.Height
}
return m, nil
}