pelican/internal/ui/cardview.go
Dan Anglin 43095b9932
fix(ui): display status message when moving card
After moving cards from one status to another the status bar now shows
either a confirmation or an error message depending on the success of
the move.
2024-01-13 19:54:24 +00:00

69 lines
1.4 KiB
Go

package ui
import (
"fmt"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
type cardView struct {
*tview.TextView
frame *tview.Frame
contentFormat string
}
func newCardView() *cardView {
border := tcell.ColorOrangeRed.TrueColor()
background := tcell.ColorBlack.TrueColor()
content := tview.NewTextView()
// Stylise the TextView
content.SetDynamicColors(true).
SetBorder(true).
SetBorderPadding(0, 0, 1, 1).
SetBorderColor(border).
SetBackgroundColor(background)
cardContentFormat := `[green::b][#%d[] %s[-:-:-:-]
[green::b]Status:[white::-] %s [green::b]Created:[white::-] %s
[green::b]Description:[white::-]
%s
`
view := cardView{
TextView: content,
frame: tview.NewFrame(content),
contentFormat: cardContentFormat,
}
return &view
}
func (c *cardView) setDoneFunc(handler func(key tcell.Key)) {
c.SetDoneFunc(handler)
}
func (c *cardView) setText(id int, title, status, created, description string) {
fmt.Fprintf(c, c.contentFormat, id, title, status, created, description)
}
func (c *cardView) Draw(screen tcell.Screen) {
height := 25
width := 50
screenWidth, screenHeight := screen.Size()
// Set the form's position and size.
x := (screenWidth - width) / 2
y := (screenHeight - height) / 2
c.SetRect(x, y, width, height)
// Draw the frame.
c.frame.SetRect(x, y, width, height)
c.frame.Draw(screen)
}