From 776c15f0da16d2b1058a079ec6a08a2e1170d721 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Fri, 18 Nov 2022 16:02:18 -0500 Subject: [PATCH] chore(examples): update ssh example chore(examples): go mod tidy --- examples/go.mod | 3 +- examples/go.sum | 23 ++----- examples/ssh/main.go | 144 +++++++------------------------------------ 3 files changed, 29 insertions(+), 141 deletions(-) diff --git a/examples/go.mod b/examples/go.mod index 5908799c..9d86b46e 100644 --- a/examples/go.mod +++ b/examples/go.mod @@ -5,12 +5,11 @@ go 1.16 replace github.com/charmbracelet/lipgloss => ../ require ( - github.com/charmbracelet/bubbletea v0.20.0 github.com/charmbracelet/lipgloss v0.4.0 github.com/charmbracelet/wish v0.5.0 github.com/gliderlabs/ssh v0.3.4 github.com/kr/pty v1.1.1 github.com/lucasb-eyer/go-colorful v1.2.0 - github.com/muesli/termenv v0.13.0 + github.com/muesli/termenv v0.14.0 golang.org/x/term v0.0.0-20210422114643-f5beecf764ed ) diff --git a/examples/go.sum b/examples/go.sum index bb95ba2e..801a2a10 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -6,22 +6,19 @@ github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYU github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= -github.com/aymanbagabas/go-osc52 v1.0.3 h1:DTwqENW7X9arYimJrPeGZcV0ln14sGMt3pHZspWD+Mg= -github.com/aymanbagabas/go-osc52 v1.0.3/go.mod h1:zT8H+Rk4VSabYN90pWyugflM3ZhpTZNC7cASDfUCdT4= +github.com/aymanbagabas/go-osc52 v1.2.1 h1:q2sWUyDcozPLcLabEMd+a+7Ea2DitxZVN9hTxab9L4E= +github.com/aymanbagabas/go-osc52 v1.2.1/go.mod h1:zT8H+Rk4VSabYN90pWyugflM3ZhpTZNC7cASDfUCdT4= github.com/caarlos0/sshmarshal v0.0.0-20220308164159-9ddb9f83c6b3/go.mod h1:7Pd/0mmq9x/JCzKauogNjSQEhivBclCQHfr9dlpDIyA= github.com/caarlos0/sshmarshal v0.1.0 h1:zTCZrDORFfWh526Tsb7vCm3+Yg/SfW/Ub8aQDeosk0I= github.com/caarlos0/sshmarshal v0.1.0/go.mod h1:7Pd/0mmq9x/JCzKauogNjSQEhivBclCQHfr9dlpDIyA= -github.com/charmbracelet/bubbletea v0.20.0 h1:/b8LEPgCbNr7WWZ2LuE/BV1/r4t5PyYJtDb+J3vpwxc= github.com/charmbracelet/bubbletea v0.20.0/go.mod h1:zpkze1Rioo4rJELjRyGlm9T2YNou1Fm4LIJQSa5QMEM= github.com/charmbracelet/keygen v0.3.0 h1:mXpsQcH7DDlST5TddmXNXjS0L7ECk4/kLQYyBcsan2Y= github.com/charmbracelet/keygen v0.3.0/go.mod h1:1ukgO8806O25lUZ5s0IrNur+RlwTBERlezdgW71F5rM= github.com/charmbracelet/wish v0.5.0 h1:FkkdNBFqrLABR1ciNrAL2KCxoyWfKhXnIGZw6GfAtPg= github.com/charmbracelet/wish v0.5.0/go.mod h1:5GAn5SrDSZ7cgKjnC+3kDmiIo7I6k4/AYiRzC4+tpCk= -github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw= github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= @@ -52,25 +49,23 @@ github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA= github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= -github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= +github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b h1:1XF24mVaiu7u+CFywTdcDo2ie1pzzhwjt6RHqzpMU34= github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho= github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s= github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8= github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs= -github.com/muesli/termenv v0.13.0 h1:wK20DRpJdDX8b7Ek2QfhvqhRQFZ237RGRO0RQ/Iqdy0= -github.com/muesli/termenv v0.13.0/go.mod h1:sP1+uffeLaEYpyOTb8pLCUctGcGLnoFjSn4YJK5e2bc= +github.com/muesli/termenv v0.14.0 h1:8x9NFfOe8lmIWK4pgy3IfVEy47f+ppe3tUqdPZG2Uy0= +github.com/muesli/termenv v0.14.0/go.mod h1:kG/pF1E7fh949Xhe156crRUrHNyK221IuGO7Ez60Uc8= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= @@ -79,13 +74,9 @@ github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNX github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0= golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= @@ -129,5 +120,3 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/examples/ssh/main.go b/examples/ssh/main.go index b5e543f1..8a451078 100644 --- a/examples/ssh/main.go +++ b/examples/ssh/main.go @@ -6,13 +6,11 @@ import ( "os" "strings" - tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" "github.com/charmbracelet/wish" lm "github.com/charmbracelet/wish/logging" "github.com/gliderlabs/ssh" "github.com/kr/pty" - "github.com/lucasb-eyer/go-colorful" "github.com/muesli/termenv" ) @@ -80,37 +78,38 @@ func main() { } w, _ := pty.Window.Width, pty.Window.Height - renderer := lipgloss.NewRenderer(lipgloss.WithTermenvOutput(output)) + renderer := lipgloss.NewRenderer(lipgloss.WithTermenvOutput(output), + lipgloss.WithColorProfile(termenv.TrueColor)) str := strings.Builder{} fmt.Fprintf(&str, "\n%s %s %s %s %s", - renderer.NewStyle("bold").Bold(true), - renderer.NewStyle("faint").Faint(true), - renderer.NewStyle("italic").Italic(true), - renderer.NewStyle("underline").Underline(true), - renderer.NewStyle("crossout").Strikethrough(true), + renderer.NewStyle().SetString("bold").Bold(true), + renderer.NewStyle().SetString("faint").Faint(true), + renderer.NewStyle().SetString("italic").Italic(true), + renderer.NewStyle().SetString("underline").Underline(true), + renderer.NewStyle().SetString("crossout").Strikethrough(true), ) fmt.Fprintf(&str, "\n%s %s %s %s %s %s %s", - renderer.NewStyle("red").Foreground(lipgloss.Color("#E88388")), - renderer.NewStyle("green").Foreground(lipgloss.Color("#A8CC8C")), - renderer.NewStyle("yellow").Foreground(lipgloss.Color("#DBAB79")), - renderer.NewStyle("blue").Foreground(lipgloss.Color("#71BEF2")), - renderer.NewStyle("magenta").Foreground(lipgloss.Color("#D290E4")), - renderer.NewStyle("cyan").Foreground(lipgloss.Color("#66C2CD")), - renderer.NewStyle("gray").Foreground(lipgloss.Color("#B9BFCA")), + renderer.NewStyle().SetString("red").Foreground(lipgloss.Color("#E88388")), + renderer.NewStyle().SetString("green").Foreground(lipgloss.Color("#A8CC8C")), + renderer.NewStyle().SetString("yellow").Foreground(lipgloss.Color("#DBAB79")), + renderer.NewStyle().SetString("blue").Foreground(lipgloss.Color("#71BEF2")), + renderer.NewStyle().SetString("magenta").Foreground(lipgloss.Color("#D290E4")), + renderer.NewStyle().SetString("cyan").Foreground(lipgloss.Color("#66C2CD")), + renderer.NewStyle().SetString("gray").Foreground(lipgloss.Color("#B9BFCA")), ) fmt.Fprintf(&str, "\n%s %s %s %s %s %s %s\n\n", - renderer.NewStyle("red").Foreground(lipgloss.Color("0")).Background(lipgloss.Color("#E88388")), - renderer.NewStyle("green").Foreground(lipgloss.Color("0")).Background(lipgloss.Color("#A8CC8C")), - renderer.NewStyle("yellow").Foreground(lipgloss.Color("0")).Background(lipgloss.Color("#DBAB79")), - renderer.NewStyle("blue").Foreground(lipgloss.Color("0")).Background(lipgloss.Color("#71BEF2")), - renderer.NewStyle("magenta").Foreground(lipgloss.Color("0")).Background(lipgloss.Color("#D290E4")), - renderer.NewStyle("cyan").Foreground(lipgloss.Color("0")).Background(lipgloss.Color("#66C2CD")), - renderer.NewStyle("gray").Foreground(lipgloss.Color("0")).Background(lipgloss.Color("#B9BFCA")), + renderer.NewStyle().SetString("red").Foreground(lipgloss.Color("0")).Background(lipgloss.Color("#E88388")), + renderer.NewStyle().SetString("green").Foreground(lipgloss.Color("0")).Background(lipgloss.Color("#A8CC8C")), + renderer.NewStyle().SetString("yellow").Foreground(lipgloss.Color("0")).Background(lipgloss.Color("#DBAB79")), + renderer.NewStyle().SetString("blue").Foreground(lipgloss.Color("0")).Background(lipgloss.Color("#71BEF2")), + renderer.NewStyle().SetString("magenta").Foreground(lipgloss.Color("0")).Background(lipgloss.Color("#D290E4")), + renderer.NewStyle().SetString("cyan").Foreground(lipgloss.Color("0")).Background(lipgloss.Color("#66C2CD")), + renderer.NewStyle().SetString("gray").Foreground(lipgloss.Color("0")).Background(lipgloss.Color("#B9BFCA")), ) - fmt.Fprintf(&str, "%s %t\n", renderer.NewStyle("Has dark background?").Bold(true), renderer.HasDarkBackground()) + fmt.Fprintf(&str, "%s %t\n", renderer.NewStyle().SetString("Has dark background?").Bold(true), renderer.HasDarkBackground()) fmt.Fprintln(&str) wish.WriteString(s, renderer.Place(w, lipgloss.Height(str.String()), lipgloss.Center, lipgloss.Center, str.String())) @@ -129,102 +128,3 @@ func main() { log.Fatal(err) } } - -type model struct { - detectedProfile termenv.Profile - renderer *lipgloss.Renderer -} - -func (m model) Init() tea.Cmd { - return nil -} - -func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { - switch msg := msg.(type) { - case tea.KeyMsg: - switch msg.String() { - case "ctrl+c", "q": - return m, tea.Quit - } - } - return m, nil -} - -func (m model) View() string { - s := strings.Builder{} - m.renderer.SetColorProfile(m.detectedProfile) - fmt.Fprintf(&s, "Detected Color Profile: %s\n", colorProfile(m.renderer.ColorProfile())) - - // Color grid - fmt.Fprintf(&s, "%s\n", colors(m.renderer)) - - // Enforced color profile - m.renderer.SetColorProfile(termenv.TrueColor) - fmt.Fprintf(&s, "Enforce True Color\n") - - // Color grid - fmt.Fprintf(&s, "%s\n", colors(m.renderer)) - - // Detect dark background - fmt.Fprintf(&s, "Has Dark Background: %v\n", m.renderer.HasDarkBackground()) - - return s.String() -} - -func colors(r *lipgloss.Renderer) string { - colors := colorGrid(14, 8) - - b := strings.Builder{} - for _, x := range colors { - for _, y := range x { - s := r.NewStyle(" ").Background(lipgloss.Color(y)) - b.WriteString(s.String()) - } - b.WriteRune('\n') - } - - return b.String() -} - -func colorGrid(xSteps, ySteps int) [][]string { - x0y0, _ := colorful.Hex("#F25D94") - x1y0, _ := colorful.Hex("#EDFF82") - x0y1, _ := colorful.Hex("#643AFF") - x1y1, _ := colorful.Hex("#14F9D5") - - x0 := make([]colorful.Color, ySteps) - for i := range x0 { - x0[i] = x0y0.BlendLuv(x0y1, float64(i)/float64(ySteps)) - } - - x1 := make([]colorful.Color, ySteps) - for i := range x1 { - x1[i] = x1y0.BlendLuv(x1y1, float64(i)/float64(ySteps)) - } - - grid := make([][]string, ySteps) - for x := 0; x < ySteps; x++ { - y0 := x0[x] - grid[x] = make([]string, xSteps) - for y := 0; y < xSteps; y++ { - grid[x][y] = y0.BlendLuv(x1[x], float64(y)/float64(xSteps)).Hex() - } - } - - return grid -} - -func colorProfile(p termenv.Profile) string { - switch p { - case termenv.TrueColor: - return "True Color" - case termenv.ANSI256: - return "ANSI 256" - case termenv.ANSI: - return "ANSI" - case termenv.Ascii: - return "No Color" - default: - return "Unknown" - } -}