Skip to content

Commit

Permalink
feat: add colorprofile example
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Sep 16, 2024
1 parent 8b51296 commit 36eac98
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 6 deletions.
53 changes: 53 additions & 0 deletions examples/colorprofile/main.go
Original file line number Diff line number Diff line change
@@ -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{}

This comment has been minimized.

Copy link
@meowgorithm

meowgorithm Sep 17, 2024

Member

What happens here?

This comment has been minimized.

Copy link
@aymanbagabas

aymanbagabas Sep 17, 2024

Author Member

This just ensures that type model conforms to tea.Model, otherwise, the program won’t compile

This comment has been minimized.

Copy link
@meowgorithm

meowgorithm Sep 17, 2024

Member

Wow, how weird. I've never had to do that. Why does it need to happen in this case?


// 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)
}
}
7 changes: 3 additions & 4 deletions examples/go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
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.0
github.com/charmbracelet/glamour v0.8.0
github.com/charmbracelet/harmonica v0.2.0
github.com/charmbracelet/lipgloss v0.13.0
Expand All @@ -22,7 +21,7 @@ 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/ansi v0.3.2 // 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
Expand Down
6 changes: 4 additions & 2 deletions examples/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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.0 h1:klE4lnH3GpQ0iI05UqEhExt5JHZUJFEBR5VxGzbbGG4=
github.com/charmbracelet/colorprofile v0.1.0/go.mod h1:Bx3b9S36dLIjuGZOO9z1WytjG4sALQQNtu97AmKYW24=
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=
Expand Down

0 comments on commit 36eac98

Please sign in to comment.