70 lines
1.4 KiB
Go
70 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)
|
||
|
}
|