common.go

 1package common
 2
 3import (
 4	"image"
 5
 6	"github.com/charmbracelet/crush/internal/config"
 7	"github.com/charmbracelet/crush/internal/ui/styles"
 8	uv "github.com/charmbracelet/ultraviolet"
 9)
10
11// Common defines common UI options and configurations.
12type Common struct {
13	Config *config.Config
14	Styles *styles.Styles
15}
16
17// DefaultCommon returns the default common UI configurations.
18func DefaultCommon(cfg *config.Config) *Common {
19	s := styles.DefaultStyles()
20	return &Common{
21		Config: cfg,
22		Styles: &s,
23	}
24}
25
26// CenterRect returns a new [Rectangle] centered within the given area with the
27// specified width and height.
28func CenterRect(area uv.Rectangle, width, height int) uv.Rectangle {
29	centerX := area.Min.X + area.Dx()/2
30	centerY := area.Min.Y + area.Dy()/2
31	minX := centerX - width/2
32	minY := centerY - height/2
33	maxX := minX + width
34	maxY := minY + height
35	return image.Rect(minX, minY, maxX, maxY)
36}