pelican/internal/ui/cardview.go
Dan Anglin e77c798fbe
All checks were successful
/ test (pull_request) Successful in 28s
/ lint (pull_request) Successful in 31s
feat(ui): add support for viewing cards
This commit adds support for viewing all the details of a card in a
separate widget. The user simply needs to press the Enter key to view
the card. To return to the Kanban board the user needs to press the
Escape key.

Part of apollo/pelican#16
2024-01-12 15:07:42 +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) print(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)
}