132 lines
2.6 KiB
Go
132 lines
2.6 KiB
Go
|
package ui
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"github.com/gdamore/tcell/v2"
|
||
|
)
|
||
|
|
||
|
func (a *App) inputCapture() func(event *tcell.EventKey) *tcell.EventKey {
|
||
|
return func(event *tcell.EventKey) *tcell.EventKey {
|
||
|
key, letter := event.Key(), event.Rune()
|
||
|
|
||
|
switch {
|
||
|
case letter == 'h' || key == tcell.KeyLeft:
|
||
|
a.shiftColumnFocus(previous)
|
||
|
case letter == 'l' || key == tcell.KeyRight:
|
||
|
a.shiftColumnFocus(next)
|
||
|
case letter == 'c':
|
||
|
a.create()
|
||
|
case letter == 'm':
|
||
|
a.move()
|
||
|
case letter == 'e':
|
||
|
a.edit()
|
||
|
case key == tcell.KeyCtrlD:
|
||
|
a.delete()
|
||
|
case key == tcell.KeyCtrlQ:
|
||
|
a.quit()
|
||
|
case key == tcell.KeyESC:
|
||
|
a.escape()
|
||
|
case key == tcell.KeyEnter:
|
||
|
a.selectHandle()
|
||
|
}
|
||
|
|
||
|
return event
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (a *App) create() {
|
||
|
if a.mode == normal {
|
||
|
a.cardForm.mode = create
|
||
|
a.cardForm.updateInputFields("", "")
|
||
|
a.cardForm.frame.SetTitle(" Create Card ")
|
||
|
a.pages.ShowPage(cardFormPage)
|
||
|
a.SetFocus(a.cardForm)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (a *App) move() {
|
||
|
if a.mode == normal {
|
||
|
a.statusSelection.cardID = a.focusedCardID()
|
||
|
a.statusSelection.currentStatusID = a.focusedStatusID()
|
||
|
a.mode = selection
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (a *App) edit() {
|
||
|
if a.mode == normal {
|
||
|
a.cardForm.mode = edit
|
||
|
|
||
|
card, ok := a.getFocusedCard()
|
||
|
if !ok {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
a.cardForm.updateInputFields(card.Title, card.Description)
|
||
|
a.cardForm.frame.SetTitle(" Edit Card ")
|
||
|
a.pages.ShowPage(cardFormPage)
|
||
|
a.SetFocus(a.cardForm)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (a *App) delete() {
|
||
|
if a.mode == normal {
|
||
|
card, ok := a.getFocusedCard()
|
||
|
if !ok {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
text := fmt.Sprintf("Do you want to delete '%s'?", card.Title)
|
||
|
a.deleteCardModal.SetText(text)
|
||
|
a.pages.ShowPage(deleteCardModalPage)
|
||
|
a.SetFocus(a.deleteCardModal)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (a *App) quit() {
|
||
|
if a.mode == normal {
|
||
|
a.pages.ShowPage(quitPage)
|
||
|
a.SetFocus(a.quitModal)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (a *App) selectHandle() {
|
||
|
switch a.mode {
|
||
|
case normal:
|
||
|
card, ok := a.getFocusedCard()
|
||
|
if !ok {
|
||
|
break
|
||
|
}
|
||
|
|
||
|
status := a.focusedStatusName()
|
||
|
a.view.setText(card.ID, card.Title, status, card.Created, card.Description)
|
||
|
a.pages.ShowPage(viewPage)
|
||
|
a.SetFocus(a.view)
|
||
|
case selection:
|
||
|
a.statusSelection.nextStatusID = a.focusedStatusID()
|
||
|
if a.statusSelection.currentStatusID != a.statusSelection.nextStatusID {
|
||
|
if err := a.statusSelection.moveCard(a.board); err != nil {
|
||
|
a.statusbar.displayMessage(
|
||
|
errorLevel,
|
||
|
fmt.Sprintf("Failed to move card: %v", err),
|
||
|
)
|
||
|
} else {
|
||
|
a.statusbar.displayMessage(
|
||
|
infoLevel,
|
||
|
"Card moved successfully.",
|
||
|
)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
a.statusSelection = statusSelection{0, 0, 0}
|
||
|
a.mode = normal
|
||
|
a.refresh(false)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (a *App) escape() {
|
||
|
if a.mode != normal {
|
||
|
a.mode = normal
|
||
|
}
|
||
|
}
|