fix: escape attachments
This commit is contained in:
@@ -9,6 +9,7 @@ type KeyMap struct {
|
|||||||
Send key.Binding
|
Send key.Binding
|
||||||
Attach key.Binding
|
Attach key.Binding
|
||||||
Unattach key.Binding
|
Unattach key.Binding
|
||||||
|
Back key.Binding
|
||||||
Quit key.Binding
|
Quit key.Binding
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,6 +37,11 @@ func DefaultKeybinds() KeyMap {
|
|||||||
key.WithHelp("x", "remove"),
|
key.WithHelp("x", "remove"),
|
||||||
key.WithDisabled(),
|
key.WithDisabled(),
|
||||||
),
|
),
|
||||||
|
Back: key.NewBinding(
|
||||||
|
key.WithKeys("esc"),
|
||||||
|
key.WithHelp("esc", "back"),
|
||||||
|
key.WithDisabled(),
|
||||||
|
),
|
||||||
Quit: key.NewBinding(
|
Quit: key.NewBinding(
|
||||||
key.WithKeys("ctrl+c"),
|
key.WithKeys("ctrl+c"),
|
||||||
key.WithHelp("ctrl+c", "quit"),
|
key.WithHelp("ctrl+c", "quit"),
|
||||||
@@ -64,4 +70,5 @@ func (m *Model) updateKeymap() {
|
|||||||
canSend := m.From.Value() != "" && m.To.Value() != "" && m.Subject.Value() != "" && m.Body.Value() != ""
|
canSend := m.From.Value() != "" && m.To.Value() != "" && m.Subject.Value() != "" && m.Body.Value() != ""
|
||||||
m.keymap.Send.SetEnabled(canSend && m.state != editingBody && m.state != pickingFile)
|
m.keymap.Send.SetEnabled(canSend && m.state != editingBody && m.state != pickingFile)
|
||||||
m.keymap.Unattach.SetEnabled(m.state == editingAttachments && len(m.Attachments.Items()) > 0)
|
m.keymap.Unattach.SetEnabled(m.state == editingAttachments && len(m.Attachments.Items()) > 0)
|
||||||
|
m.keymap.Back.SetEnabled(m.state == pickingFile)
|
||||||
}
|
}
|
||||||
|
|||||||
8
model.go
8
model.go
@@ -127,7 +127,6 @@ func NewModel() Model {
|
|||||||
func (m Model) Init() tea.Cmd {
|
func (m Model) Init() tea.Cmd {
|
||||||
return tea.Batch(
|
return tea.Batch(
|
||||||
m.From.Cursor.BlinkCmd(),
|
m.From.Cursor.BlinkCmd(),
|
||||||
m.filepicker.Init(),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,6 +173,10 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
m.focusActiveInput()
|
m.focusActiveInput()
|
||||||
|
|
||||||
|
case key.Matches(msg, m.keymap.Back):
|
||||||
|
m.state = editingAttachments
|
||||||
|
m.updateKeymap()
|
||||||
|
return m, nil
|
||||||
case key.Matches(msg, m.keymap.Send):
|
case key.Matches(msg, m.keymap.Send):
|
||||||
m.state = sendingEmail
|
m.state = sendingEmail
|
||||||
return m, tea.Batch(
|
return m, tea.Batch(
|
||||||
@@ -182,6 +185,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
)
|
)
|
||||||
case key.Matches(msg, m.keymap.Attach):
|
case key.Matches(msg, m.keymap.Attach):
|
||||||
m.state = pickingFile
|
m.state = pickingFile
|
||||||
|
return m, m.filepicker.Init()
|
||||||
case key.Matches(msg, m.keymap.Unattach):
|
case key.Matches(msg, m.keymap.Unattach):
|
||||||
m.Attachments.RemoveItem(m.Attachments.Index())
|
m.Attachments.RemoveItem(m.Attachments.Index())
|
||||||
m.Attachments.SetHeight(max(len(m.Attachments.Items()), 1) + 2)
|
m.Attachments.SetHeight(max(len(m.Attachments.Items()), 1) + 2)
|
||||||
@@ -276,7 +280,7 @@ func (m Model) View() string {
|
|||||||
|
|
||||||
switch m.state {
|
switch m.state {
|
||||||
case pickingFile:
|
case pickingFile:
|
||||||
return "\n" + activeLabelStyle.Render("Attachments") +
|
return "\n" + activeLabelStyle.Render("Attachments") + " " + commentStyle.Render(m.filepicker.CurrentDirectory) +
|
||||||
"\n\n" + m.filepicker.View()
|
"\n\n" + m.filepicker.View()
|
||||||
case sendingEmail:
|
case sendingEmail:
|
||||||
return "\n " + m.loadingSpinner.View() + "Sending email"
|
return "\n " + m.loadingSpinner.View() + "Sending email"
|
||||||
|
|||||||
Reference in New Issue
Block a user