summaryrefslogtreecommitdiff
path: root/internal/preview/preview.go
blob: 1ab86be7c6797ac5bd232af6934a78ff29a777ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package preview

import (
	"strings"

	tea "github.com/charmbracelet/bubbletea"
	"github.com/charmbracelet/lipgloss"
)

const (
	runeBlock     = "█"
	defaultHeight = 5
	defaultWidth  = 78
)

type Model struct {
	height int
	width  int
	hex    string
}

func (m *Model) SetColor(hex string) { m.hex = hex }

func (m *Model) SetHeight(size int) { m.height = size }

func (m *Model) SetWidth(size int) { m.width = size }

func New(hex string) *Model {
	return &Model{
		height: defaultHeight,
		width:  defaultWidth,
		hex:    hex,
	}
}

func (m Model) Init() tea.Cmd { return nil }

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, nil }

func (m Model) View() string {
	style := lipgloss.NewStyle().Foreground(lipgloss.Color(m.hex))
	oneRow := strings.Repeat(runeBlock, m.width)
	block := strings.Repeat(oneRow+"\n", m.height)
	return style.Render(block)
}