2023-06-14 06:31:19 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "github.com/charmbracelet/bubbles/key"
|
|
|
|
|
|
|
|
// KeyMap represents the key bindings for the application.
|
|
|
|
type KeyMap struct {
|
|
|
|
NextInput key.Binding
|
|
|
|
PrevInput key.Binding
|
|
|
|
Send key.Binding
|
|
|
|
Attach key.Binding
|
|
|
|
Unattach key.Binding
|
2023-06-15 16:52:28 +03:00
|
|
|
Back key.Binding
|
2023-06-14 06:31:19 +03:00
|
|
|
Quit key.Binding
|
|
|
|
}
|
|
|
|
|
|
|
|
func DefaultKeybinds() KeyMap {
|
|
|
|
return KeyMap{
|
|
|
|
NextInput: key.NewBinding(
|
2023-06-14 06:53:24 +03:00
|
|
|
key.WithKeys("tab"),
|
2023-06-14 06:31:19 +03:00
|
|
|
key.WithHelp("tab", "next"),
|
|
|
|
),
|
|
|
|
PrevInput: key.NewBinding(
|
2023-06-14 06:53:24 +03:00
|
|
|
key.WithKeys("shift+tab"),
|
2023-06-14 06:31:19 +03:00
|
|
|
),
|
|
|
|
Send: key.NewBinding(
|
|
|
|
key.WithKeys("ctrl+d", "enter"),
|
|
|
|
key.WithHelp("enter", "send"),
|
|
|
|
key.WithDisabled(),
|
|
|
|
),
|
|
|
|
Attach: key.NewBinding(
|
2023-06-15 21:43:58 +03:00
|
|
|
key.WithKeys("enter"),
|
|
|
|
key.WithHelp("enter", "attach file"),
|
2023-06-14 06:31:19 +03:00
|
|
|
key.WithDisabled(),
|
|
|
|
),
|
|
|
|
Unattach: key.NewBinding(
|
|
|
|
key.WithKeys("x"),
|
|
|
|
key.WithHelp("x", "remove"),
|
|
|
|
key.WithDisabled(),
|
|
|
|
),
|
2023-06-15 16:52:28 +03:00
|
|
|
Back: key.NewBinding(
|
|
|
|
key.WithKeys("esc"),
|
|
|
|
key.WithHelp("esc", "back"),
|
|
|
|
key.WithDisabled(),
|
|
|
|
),
|
2023-06-14 06:31:19 +03:00
|
|
|
Quit: key.NewBinding(
|
|
|
|
key.WithKeys("ctrl+c"),
|
|
|
|
key.WithHelp("ctrl+c", "quit"),
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (k KeyMap) ShortHelp() []key.Binding {
|
|
|
|
return []key.Binding{
|
|
|
|
k.NextInput,
|
|
|
|
k.Quit,
|
|
|
|
k.Attach,
|
|
|
|
k.Unattach,
|
|
|
|
k.Send,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (k KeyMap) FullHelp() [][]key.Binding {
|
|
|
|
return [][]key.Binding{
|
|
|
|
{k.NextInput, k.Send, k.Attach, k.Unattach, k.Quit},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Model) updateKeymap() {
|
|
|
|
m.keymap.Attach.SetEnabled(m.state == editingAttachments)
|
2023-06-15 21:38:57 +03:00
|
|
|
m.keymap.Send.SetEnabled(m.canSend() && m.state == hoveringSendButton)
|
2023-06-14 06:31:19 +03:00
|
|
|
m.keymap.Unattach.SetEnabled(m.state == editingAttachments && len(m.Attachments.Items()) > 0)
|
2023-06-15 16:52:28 +03:00
|
|
|
m.keymap.Back.SetEnabled(m.state == pickingFile)
|
2023-06-14 06:31:19 +03:00
|
|
|
}
|
2023-06-15 21:38:57 +03:00
|
|
|
|
|
|
|
func (m Model) canSend() bool {
|
|
|
|
return m.From.Value() != "" && m.To.Value() != "" && m.Subject.Value() != "" && m.Body.Value() != ""
|
|
|
|
}
|