From 01a9fc8b40d795f2d7dd075dadae207aa6d4529a Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Mon, 16 Sep 2024 17:37:30 -0400 Subject: [PATCH] feat: add colorprofile example --- examples/colorprofile/main.go | 53 +++++++++++++++++++++++++++++++++++ examples/go.mod | 7 ++--- examples/go.sum | 6 ++-- go.mod | 2 +- go.sum | 2 ++ 5 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 examples/colorprofile/main.go diff --git a/examples/colorprofile/main.go b/examples/colorprofile/main.go new file mode 100644 index 0000000000..75d67600c8 --- /dev/null +++ b/examples/colorprofile/main.go @@ -0,0 +1,53 @@ +package main + +import ( + "image/color" + "log" + + tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/colorprofile" + "github.com/charmbracelet/x/ansi" + "github.com/lucasb-eyer/go-colorful" +) + +var myFancyColor color.Color + +type model struct{} + +var _ tea.Model = model{} + +// Init implements tea.Model. +func (m model) Init() (tea.Model, tea.Cmd) { + return m, tea.Batch( + tea.RequestCapability("RGB"), + tea.RequestCapability("Tc"), + ) +} + +// Update implements tea.Model. +func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { + switch msg := msg.(type) { + case tea.KeyMsg: + return m, tea.Quit + case tea.ColorProfileMsg: + return m, tea.Println("Color profile changed to ", msg) + } + return m, nil +} + +// View implements tea.Model. +func (m model) View() string { + return "This will produce the wrong colors on Apple Terminal :)\n\n" + + ansi.Style{}.ForegroundColor(myFancyColor).Styled("Howdy!") + + "\n\n" + + "Press any key to exit." +} + +func main() { + myFancyColor, _ = colorful.Hex("#6b50ff") + + p := tea.NewProgram(model{}, tea.WithColorProfile(colorprofile.TrueColor)) + if _, err := p.Run(); err != nil { + log.Fatal(err) + } +} diff --git a/examples/go.mod b/examples/go.mod index 0e8d888f65..aa6aa8c1bb 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -1,15 +1,15 @@ module examples -go 1.21 - -toolchain go1.22.5 +go 1.23.1 require ( github.com/charmbracelet/bubbles v0.20.1-0.20240910180436-8972b56c9dde github.com/charmbracelet/bubbletea v1.1.2-0.20240911170800-098540620292 + github.com/charmbracelet/colorprofile v0.1.1 github.com/charmbracelet/glamour v0.8.0 github.com/charmbracelet/harmonica v0.2.0 github.com/charmbracelet/lipgloss v0.13.0 + github.com/charmbracelet/x/ansi v0.3.2 github.com/charmbracelet/x/exp/teatest v0.0.0-20240912153648-d6041061ead9 github.com/fogleman/ease v0.0.0-20170301025033-8da417bf1776 github.com/lucasb-eyer/go-colorful v1.2.0 @@ -22,7 +22,6 @@ require ( github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/aymanbagabas/go-udiff v0.2.0 // indirect github.com/aymerick/douceur v0.2.0 // indirect - github.com/charmbracelet/x/ansi v0.3.1 // indirect github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b // indirect github.com/charmbracelet/x/term v0.2.0 // indirect github.com/charmbracelet/x/windows v0.2.0 // indirect diff --git a/examples/go.sum b/examples/go.sum index 39015a0f11..025b7bec06 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -16,14 +16,16 @@ github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuP github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4= github.com/charmbracelet/bubbles v0.20.1-0.20240910180436-8972b56c9dde h1:/u+F3xZsfJYhEQ3MjKvqiXb2Y6LV8/4YHAMICxjGVhY= github.com/charmbracelet/bubbles v0.20.1-0.20240910180436-8972b56c9dde/go.mod h1:M5Z4yZGaxq8TZoEY2rs529UxFTeZLnAhmAzqd2wd48M= +github.com/charmbracelet/colorprofile v0.1.1 h1:YsvIsmZ2bazhejG+5g5MPPMpllc7Ks66Nk8l3IvGJ2g= +github.com/charmbracelet/colorprofile v0.1.1/go.mod h1:1htIKZYeI4TQs+OykPvpuBTUbUJxBYeSYBDIZuejMj0= github.com/charmbracelet/glamour v0.8.0 h1:tPrjL3aRcQbn++7t18wOpgLyl8wrOHUEDS7IZ68QtZs= github.com/charmbracelet/glamour v0.8.0/go.mod h1:ViRgmKkf3u5S7uakt2czJ272WSg2ZenlYEZXT2x7Bjw= github.com/charmbracelet/harmonica v0.2.0 h1:8NxJWRWg/bzKqqEaaeFNipOu77YR5t8aSwG4pgaUBiQ= github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao= github.com/charmbracelet/lipgloss v0.13.0 h1:4X3PPeoWEDCMvzDvGmTajSyYPcZM4+y8sCA/SsA3cjw= github.com/charmbracelet/lipgloss v0.13.0/go.mod h1:nw4zy0SBX/F/eAO1cWdcvy6qnkDUxr8Lw7dvFrAIbbY= -github.com/charmbracelet/x/ansi v0.3.1 h1:CRO6lc/6HCx2/D6S/GZ87jDvRvk6GtPyFP+IljkNtqI= -github.com/charmbracelet/x/ansi v0.3.1/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= +github.com/charmbracelet/x/ansi v0.3.2 h1:wsEwgAN+C9U06l9dCVMX0/L3x7ptvY1qmjMwyfE6USY= +github.com/charmbracelet/x/ansi v0.3.2/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b h1:MnAMdlwSltxJyULnrYbkZpp4k58Co7Tah3ciKhSNo0Q= github.com/charmbracelet/x/exp/golden v0.0.0-20240815200342-61de596daa2b/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= github.com/charmbracelet/x/exp/teatest v0.0.0-20240912153648-d6041061ead9 h1:2q41wBBupsw4GATbF/C3NZ3JtccZ/iYu7cL3doHOnuo= diff --git a/go.mod b/go.mod index 3b686ad706..f1ef6aa8b4 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( require ( github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect - github.com/charmbracelet/colorprofile v0.1.0 // indirect + github.com/charmbracelet/colorprofile v0.1.1 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.16 // indirect diff --git a/go.sum b/go.sum index 448b3bca20..5541537087 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiE github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= github.com/charmbracelet/colorprofile v0.1.0 h1:klE4lnH3GpQ0iI05UqEhExt5JHZUJFEBR5VxGzbbGG4= github.com/charmbracelet/colorprofile v0.1.0/go.mod h1:Bx3b9S36dLIjuGZOO9z1WytjG4sALQQNtu97AmKYW24= +github.com/charmbracelet/colorprofile v0.1.1 h1:YsvIsmZ2bazhejG+5g5MPPMpllc7Ks66Nk8l3IvGJ2g= +github.com/charmbracelet/colorprofile v0.1.1/go.mod h1:1htIKZYeI4TQs+OykPvpuBTUbUJxBYeSYBDIZuejMj0= github.com/charmbracelet/lipgloss v0.13.0 h1:4X3PPeoWEDCMvzDvGmTajSyYPcZM4+y8sCA/SsA3cjw= github.com/charmbracelet/lipgloss v0.13.0/go.mod h1:nw4zy0SBX/F/eAO1cWdcvy6qnkDUxr8Lw7dvFrAIbbY= github.com/charmbracelet/x/ansi v0.3.2 h1:wsEwgAN+C9U06l9dCVMX0/L3x7ptvY1qmjMwyfE6USY=