summaryrefslogtreecommitdiff
path: root/internal/preview/preview.go
blob: ef4c9f0926a15c6e215df97f1f9778bfd722d059 (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
package preview

import (
	"strings"

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

const runeBlock = "█"

type Model struct {
	size int // height of the square in rows
	hex  string
}

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

func New(hex string) *Model {
	return &Model{
		size: 5,
		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))
	// size is doubled since terminal cells are 2:1 (h:w)
	oneRow := strings.Repeat(runeBlock, m.size*2)
	block := strings.Repeat(oneRow+"\n", m.size)
	return style.Render(block)
}