Skip to content
Myr

main.go

This file

Path

examples/colorprofile/main.go

53 lines · 1.1 KiB · Go

Last changed by

Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97

History of this file

Take it

1package main23import (4	"image/color"5	"log"67	tea "charm.land/bubbletea/v2"8	"github.com/charmbracelet/colorprofile"9	"github.com/charmbracelet/x/ansi"10	"github.com/lucasb-eyer/go-colorful"11)1213var myFancyColor color.Color1415type model struct{}1617var _ tea.Model = model{}1819// Init implements tea.Model.20func (m model) Init() tea.Cmd {21	return tea.Batch(22		tea.RequestCapability("RGB"),23		tea.RequestCapability("Tc"),24	)25}2627// Update implements tea.Model.28func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {29	switch msg := msg.(type) {30	case tea.KeyMsg:31		return m, tea.Quit32	case tea.ColorProfileMsg:33		return m, tea.Println("Color profile manually set to ", msg)34	}35	return m, nil36}3738// View implements tea.Model.39func (m model) View() tea.View {40	return tea.NewView("This will produce the wrong colors on Apple Terminal :)\n\n" +41		ansi.Style{}.ForegroundColor(myFancyColor).Styled("Howdy!") +42		"\n\n" +43		"Press any key to exit.")44}4546func main() {47	myFancyColor, _ = colorful.Hex("#6b50ff")4849	p := tea.NewProgram(model{}, tea.WithColorProfile(colorprofile.TrueColor))50	if _, err := p.Run(); err != nil {51		log.Fatal(err)52	}53}