summaryrefslogtreecommitdiff
path: root/internal/preview/preview.go
blob: eb7d344d8b2c3c3595f9e0ba662b25b8f9bacecf (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
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)
}