From 5c376d623d4c30a5bcbbcc9a3ad0f313f7f3ceaf Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Mon, 14 Jun 2021 16:52:00 -0400 Subject: [PATCH] Bump Bubble Tea, Bubbles and Lip Gloss and do related updates This update also removes any usage of the charm/common package --- config_cmd.go | 5 +- formatting.go | 15 ------ go.mod | 11 +++-- go.sum | 24 ++++------ main.go | 12 ++--- stash_cmd.go | 6 +-- style.go | 16 +++++++ ui/pager.go | 104 +++++++++++++++++++++++++++++------------ ui/stash.go | 54 +++++++++++++--------- ui/stashhelp.go | 3 +- ui/stashitem.go | 23 +++++----- ui/styles.go | 120 ++++++++++++++++++++++++++++-------------------- ui/ui.go | 9 +--- 13 files changed, 234 insertions(+), 168 deletions(-) delete mode 100644 formatting.go create mode 100644 style.go diff --git a/config_cmd.go b/config_cmd.go index a90b903..28286d1 100644 --- a/config_cmd.go +++ b/config_cmd.go @@ -7,7 +7,6 @@ import ( "os/exec" "path" - "github.com/charmbracelet/charm/ui/common" gap "github.com/muesli/go-app-paths" "github.com/spf13/cobra" ) @@ -27,8 +26,8 @@ var configCmd = &cobra.Command{ Use: "config", Hidden: false, Short: "Edit the glow config file", - Long: formatBlock(fmt.Sprintf("\n%s the glow config file. We’ll use EDITOR to determine which editor to use. If the config file doesn't exist, it will be created.", common.Keyword("Edit"))), - Example: formatBlock("glow config\nglow config --config path/to/config.yml"), + Long: paragraph(fmt.Sprintf("\n%s the glow config file. We’ll use EDITOR to determine which editor to use. If the config file doesn't exist, it will be created.", keyword("Edit"))), + Example: paragraph("glow config\nglow config --config path/to/config.yml"), Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { editor := os.Getenv("EDITOR") diff --git a/formatting.go b/formatting.go deleted file mode 100644 index 6e3dffa..0000000 --- a/formatting.go +++ /dev/null @@ -1,15 +0,0 @@ -package main - -import ( - "github.com/muesli/reflow/indent" - "github.com/muesli/reflow/wordwrap" -) - -const ( - wrapAt = 78 - indentAmount = 2 -) - -func formatBlock(s string) string { - return indent.String(wordwrap.String(s, wrapAt-indentAmount), indentAmount) -} diff --git a/go.mod b/go.mod index 30795d2..839b3e9 100644 --- a/go.mod +++ b/go.mod @@ -5,13 +5,14 @@ go 1.16 replace github.com/charmbracelet/charm => ../charm require ( - github.com/charmbracelet/bubbles v0.7.6 - github.com/charmbracelet/bubbletea v0.13.2 + github.com/charmbracelet/bubbles v0.8.0 + github.com/charmbracelet/bubbletea v0.14.0 github.com/charmbracelet/charm v0.0.0-00010101000000-000000000000 github.com/charmbracelet/glamour v0.2.1-0.20210402234443-abe9cda419ba - github.com/dgraph-io/badger/v3 v3.2011.1 // indirect + github.com/charmbracelet/lipgloss v0.2.1 + github.com/dgraph-io/badger/v3 v3.2011.1 github.com/dustin/go-humanize v1.0.1-0.20200219035652-afde56e7acac - github.com/google/uuid v1.1.2 // indirect + github.com/google/uuid v1.1.2 github.com/kylelemons/godebug v1.1.0 // indirect github.com/mattn/go-runewidth v0.0.12 github.com/meowgorithm/babyenv v1.3.1 @@ -26,6 +27,6 @@ require ( github.com/spf13/viper v1.7.1 golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect golang.org/x/sys v0.0.0-20210503173754-0981d6026fa6 - golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf + golang.org/x/term v0.0.0-20210422114643-f5beecf764ed golang.org/x/text v0.3.3 ) diff --git a/go.sum b/go.sum index ea0bc0a..f68ebea 100644 --- a/go.sum +++ b/go.sum @@ -48,14 +48,16 @@ github.com/calmh/randomart v1.1.0/go.mod h1:DQUbPVyP+7PAs21w/AnfMKG5NioxS3TbZ2F9 github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= -github.com/charmbracelet/bubbles v0.7.5/go.mod h1:IRTORFvhEI6OUH7WhN2Ks8Z8miNGimk1BE6cmHijOkM= -github.com/charmbracelet/bubbles v0.7.6 h1:SCAp4ZEUf2tBNEsufo+Xxxu2dvbFhYSDPrX45toQZrM= -github.com/charmbracelet/bubbles v0.7.6/go.mod h1:0D4XRYK0tjo8JMvflz1obpVcOikNZSG46SFauoZj22s= -github.com/charmbracelet/bubbletea v0.12.2/go.mod h1:3gZkYELUOiEUOp0bTInkxguucy/xRbGSOcbMs1geLxg= -github.com/charmbracelet/bubbletea v0.13.2 h1:fSOx3q0/VbA3ChWeiNcUsNeNysD9FFWD1tZypShBuCQ= -github.com/charmbracelet/bubbletea v0.13.2/go.mod h1:okqaA5VF0aSpEZ2HB+L/cxVw2HthIDZ1dmWoRZs8/4g= +github.com/charmbracelet/bubbles v0.8.0 h1:+l2op90Ag37Vn+30O1hbg/0wBl+e+sxHhgY1F/rvdHs= +github.com/charmbracelet/bubbles v0.8.0/go.mod h1:5WX1sSSjNCgCrzvRMN/z23HxvWaa+AI16Ch0KPZPeDs= +github.com/charmbracelet/bubbletea v0.13.1/go.mod h1:tp9tr9Dadh0PLhgiwchE5zZJXm5543JYjHG9oY+5qSg= +github.com/charmbracelet/bubbletea v0.14.0 h1:SBbtRPkZ/wGYyTAn2zrBERes/nwzxZR5QdJ5nvczmFw= +github.com/charmbracelet/bubbletea v0.14.0/go.mod h1:b5lOf5mLjMg1tRn1HVla54guZB+jvsyV0yYAQja95zE= github.com/charmbracelet/glamour v0.2.1-0.20210402234443-abe9cda419ba h1:smKYYwwVPZyMK2LCirIi2WY25tZZW0IU7GYe1ASGCe4= github.com/charmbracelet/glamour v0.2.1-0.20210402234443-abe9cda419ba/go.mod h1:nHP5wEbsv2eOJ7XfiScQV3p5dpZSM051R0VkxnOIPgg= +github.com/charmbracelet/lipgloss v0.1.2/go.mod h1:5D8zradw52m7QmxRF6QgwbwJi9je84g8MkWiGN07uKg= +github.com/charmbracelet/lipgloss v0.2.1 h1:knjqLRtlcDsxss6i0CUhNLuXrNW3TQhFDXlXII2UaZA= +github.com/charmbracelet/lipgloss v0.2.1/go.mod h1:uiZUfrHLQN14I0lJ5591WtcHyY1X76pOIPSaRKPY6dE= github.com/chris-ramon/douceur v0.2.0 h1:IDMEdxlEUUBYBKE4z/mJnFyVXox+MjuEVDJNN27glkU= github.com/chris-ramon/douceur v0.2.0/go.mod h1:wDW5xjJdeoMm1mRt4sD4c/LbF/mWdEpRXQKjTR8nIBE= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= @@ -230,7 +232,6 @@ github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/mattn/go-runewidth v0.0.12 h1:Y41i/hVW3Pgwr8gV+J23B9YEY0zxjptBuCWEaxmAOow= @@ -263,14 +264,12 @@ github.com/muesli/gitcha v0.2.0 h1:+wOgT2dI9s2Tznj1t1rb/qkK5e0cb6qD8c4IX2TR/YY= github.com/muesli/gitcha v0.2.0/go.mod h1:Ri8m9TZS4+ORG4JVmVKUQcWZuxDvUW3UKxMdQfzG2zI= github.com/muesli/go-app-paths v0.2.1 h1:Qi+2igkDX2aPqyRddp7P0sMQIBwBqhkfQfNcjdGjL6Y= github.com/muesli/go-app-paths v0.2.1/go.mod h1:SxS3Umca63pcFcLtbjVb+J0oD7cl4ixQWoBKhGEtEho= -github.com/muesli/reflow v0.1.0/go.mod h1:I9bWAt7QTg/que/qmUCJBGlj7wEq8OAFBjPNjc6xK4I= github.com/muesli/reflow v0.2.0/go.mod h1:qT22vjVmM9MIUeLgsVYe/Ye7eZlbv9dZjL3dVhUqLX8= github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68 h1:y1p/ycavWjGT9FnmSjdbWUlLGvcxrY0Rw3ATltrxOhk= github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68/go.mod h1:Xk+z4oIWdQqJzsxyjgl3P22oYZnHdZ8FFTHAQQt5BMQ= github.com/muesli/sasquatch v0.0.0-20200811221207-66979d92330a h1:Hw/15RYEOUD6T9UCRkUmNBa33kJkH33Fui6hE4sRLKU= github.com/muesli/sasquatch v0.0.0-20200811221207-66979d92330a/go.mod h1:+XG0ne5zXWBTSbbe7Z3/RWxaT8PZY6zaZ1dX6KjprYY= github.com/muesli/termenv v0.7.2/go.mod h1:ct2L5N2lmix82RaY3bMWwVu/jUFc9Ule0KGDCiKYPh8= -github.com/muesli/termenv v0.7.4/go.mod h1:pZ7qY9l3F7e5xsAOS0zCew2tME+p7bWeBkotCEcIIcc= github.com/muesli/termenv v0.8.1 h1:9q230czSP3DHVpkaPDXGp0TOfAwyjyYwXlUCQxQSaBk= github.com/muesli/termenv v0.8.1/go.mod h1:kzt/D/4a88RoheZmwfqorY3A+tnsSMA9HJC/fQSFKo0= github.com/muesli/toktok v0.0.0-20201007181047-c74187025f3f/go.mod h1:FmV+MTLqgtVrOUfvwWxUZXyoiCGzYt8siG4BqrY4Mb8= @@ -415,7 +414,6 @@ golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCc golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -466,14 +464,13 @@ golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200916030750-2334cc1a136f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201020230747-6e5568b54d1a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210503173754-0981d6026fa6 h1:cdsMqa2nXzqlgs183pHxtvoVwU7CyzaCTAUOg94af4c= golang.org/x/sys v0.0.0-20210503173754-0981d6026fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= -golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M= -golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210422114643-f5beecf764ed h1:Ei4bQjjpYUsS4efOUz+5Nz++IVkHk87n2zBA0NxBWc0= +golang.org/x/term v0.0.0-20210422114643-f5beecf764ed/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= @@ -502,7 +499,6 @@ golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191127201027-ecd32218bd7f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20201105001634-bc3cf281b174/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/main.go b/main.go index 47424e4..33b9fde 100644 --- a/main.go +++ b/main.go @@ -12,17 +12,15 @@ import ( "path/filepath" "strings" + tea "github.com/charmbracelet/bubbletea" + "github.com/charmbracelet/glamour" + "github.com/charmbracelet/glow/ui" + "github.com/charmbracelet/glow/utils" "github.com/meowgorithm/babyenv" gap "github.com/muesli/go-app-paths" "github.com/spf13/cobra" "github.com/spf13/viper" "golang.org/x/term" - - tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/charm/ui/common" - "github.com/charmbracelet/glamour" - "github.com/charmbracelet/glow/ui" - "github.com/charmbracelet/glow/utils" ) var ( @@ -41,7 +39,7 @@ var ( rootCmd = &cobra.Command{ Use: "glow [SOURCE|DIR]", Short: "Render markdown on the CLI, with pizzazz!", - Long: formatBlock(fmt.Sprintf("\nRender markdown on the CLI, %s!", common.Keyword("with pizzazz"))), + Long: paragraph(fmt.Sprintf("\nRender markdown on the CLI, %s!", keyword("with pizzazz"))), SilenceErrors: false, SilenceUsage: false, TraverseChildren: true, diff --git a/stash_cmd.go b/stash_cmd.go index 379e825..d889192 100644 --- a/stash_cmd.go +++ b/stash_cmd.go @@ -21,8 +21,8 @@ var ( Use: "stash [SOURCE]", Hidden: false, Short: "Stash a markdown", - Long: formatBlock(fmt.Sprintf("\nDo %s stuff. Run with no arguments to browse your stash or pass a path to a markdown file to stash it.", common.Keyword("stash"))), - Example: formatBlock("glow stash\nglow stash README.md\nglow stash -m \"secret notes\" path/to/notes.md"), + Long: paragraph(fmt.Sprintf("\nDo %s stuff. Run with no arguments to browse your stash or pass a path to a markdown file to stash it.", keyword("stash"))), + Example: paragraph("glow stash\nglow stash README.md\nglow stash -m \"secret notes\" path/to/notes.md"), Args: cobra.MaximumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { initConfig() @@ -63,7 +63,7 @@ var ( func initCharmClient() *client.Client { cc, err := client.NewClient() if err == charm.ErrMissingSSHAuth { - fmt.Println(formatBlock("We had some trouble authenticating via SSH. If this continues to happen the Charm tool may be able to help you. More info at https://github.com/charmbracelet/charm.")) + fmt.Println(paragraph("We had some trouble authenticating via SSH. If this continues to happen the Charm tool may be able to help you. More info at https://github.com/charmbracelet/charm.")) os.Exit(1) } else if err != nil { fmt.Println(err) diff --git a/style.go b/style.go new file mode 100644 index 0000000..7737dd2 --- /dev/null +++ b/style.go @@ -0,0 +1,16 @@ +package main + +import ( + . "github.com/charmbracelet/lipgloss" +) + +var ( + keyword = NewStyle(). + Foreground(AdaptiveColor{Light: "#04B575", Dark: "#04B575"}). + Render + + paragraph = NewStyle(). + Width(78). + Padding(0, 0, 0, 2). + Render +) diff --git a/ui/pager.go b/ui/pager.go index 321a104..bbab688 100644 --- a/ui/pager.go +++ b/ui/pager.go @@ -11,13 +11,12 @@ import ( "github.com/charmbracelet/bubbles/textinput" "github.com/charmbracelet/bubbles/viewport" tea "github.com/charmbracelet/bubbletea" - lib "github.com/charmbracelet/charm/ui/common" "github.com/charmbracelet/glamour" "github.com/charmbracelet/glow/client" + "github.com/charmbracelet/lipgloss" runewidth "github.com/mattn/go-runewidth" "github.com/muesli/reflow/ansi" "github.com/muesli/reflow/truncate" - te "github.com/muesli/termenv" ) const statusBarHeight = 1 @@ -25,27 +24,78 @@ const statusBarHeight = 1 var ( pagerHelpHeight int - mintGreen = lib.NewColorPair("#89F0CB", "#89F0CB") - darkGreen = lib.NewColorPair("#1C8760", "#1C8760") + mintGreen = lipgloss.AdaptiveColor{Light: "#89F0CB", Dark: "#89F0CB"} + darkGreen = lipgloss.AdaptiveColor{Light: "#1C8760", Dark: "#1C8760"} - noteHeading = te.String(" Set Memo "). - Foreground(lib.Cream.Color()). - Background(lib.Green.Color()). - String() + noteHeading = lipgloss.NewStyle(). + Foreground(cream). + Background(green). + Padding(0, 1). + Render("Set Memo") - statusBarNoteFg = lib.NewColorPair("#7D7D7D", "#656565") - statusBarBg = lib.NewColorPair("#242424", "#E6E6E6") + statusBarNoteFg = lipgloss.AdaptiveColor{Light: "#656565", Dark: "#7D7D7D"} + statusBarBg = lipgloss.AdaptiveColor{Light: "#E6E6E6", Dark: "#242424"} - // Styling funcs. - statusBarScrollPosStyle = newStyle(lib.NewColorPair("#5A5A5A", "#949494"), statusBarBg, false) - statusBarNoteStyle = newStyle(statusBarNoteFg, statusBarBg, false) - statusBarHelpStyle = newStyle(statusBarNoteFg, lib.NewColorPair("#323232", "#DCDCDC"), false) - statusBarStashDotStyle = newStyle(lib.Green, statusBarBg, false) - statusBarMessageStyle = newStyle(mintGreen, darkGreen, false) - statusBarMessageStashIconStyle = newStyle(mintGreen, darkGreen, false) - statusBarMessageScrollPosStyle = newStyle(mintGreen, darkGreen, false) - statusBarMessageHelpStyle = newStyle(lib.NewColorPair("#B6FFE4", "#B6FFE4"), lib.Green, false) - helpViewStyle = newStyle(statusBarNoteFg, lib.NewColorPair("#1B1B1B", "#f2f2f2"), false) + statusBarScrollPosStyle = lipgloss.NewStyle(). + Foreground(lipgloss.AdaptiveColor{Light: "#949494", Dark: "#5A5A5A"}). + Background(statusBarBg). + Render + + statusBarNoteStyle = lipgloss.NewStyle(). + Foreground(statusBarNoteFg). + Background(statusBarBg). + Render + + statusBarHelpStyle = lipgloss.NewStyle(). + Foreground(statusBarNoteFg). + Background(lipgloss.AdaptiveColor{Light: "#DCDCDC", Dark: "#323232"}). + Render + + statusBarStashDotStyle = lipgloss.NewStyle(). + Foreground(green). + Background(statusBarBg). + Render + + statusBarMessageStyle = lipgloss.NewStyle(). + Foreground(mintGreen). + Background(darkGreen). + Render + + statusBarMessageStashIconStyle = lipgloss.NewStyle(). + Foreground(mintGreen). + Background(darkGreen). + Render + + statusBarMessageScrollPosStyle = lipgloss.NewStyle(). + Foreground(mintGreen). + Background(darkGreen). + Render + + statusBarMessageHelpStyle = lipgloss.NewStyle(). + Foreground(lipgloss.Color("#B6FFE4")). + Background(green). + Render + + helpViewStyle = lipgloss.NewStyle(). + Foreground(statusBarNoteFg). + Background(lipgloss.AdaptiveColor{Light: "#f2f2f2", Dark: "#1B1B1B"}). + Render + + spinnerStyle = lipgloss.NewStyle(). + Foreground(statusBarNoteFg). + Background(statusBarBg) + + pagerNoteInputPromptStyle = lipgloss.NewStyle(). + Foreground(darkGray). + Background(yellowGreen). + Padding(0, 1) + + pagerNoteInputStyle = lipgloss.NewStyle(). + Foreground(darkGray). + Background(yellowGreen) + + pagerNoteInputCursorStyle = lipgloss.NewStyle(). + Foreground(fuschia) ) type contentRenderedMsg string @@ -89,20 +139,16 @@ func newPagerModel(common *commonModel) pagerModel { // Text input for notes/memos ti := textinput.NewModel() - ti.Prompt = te.String(" > "). - Foreground(lib.Color(darkGray)). - Background(lib.YellowGreen.Color()). - String() - ti.TextColor = darkGray - ti.BackgroundColor = lib.YellowGreen.String() - ti.CursorColor = lib.Fuschia.String() + ti.Prompt = " > " + ti.PromptStyle = pagerNoteInputPromptStyle + ti.TextStyle = pagerNoteInputStyle + ti.CursorStyle = pagerNoteInputCursorStyle ti.CharLimit = noteCharacterLimit ti.Focus() // Text input for search sp := spinner.NewModel() - sp.ForegroundColor = statusBarNoteFg.String() - sp.BackgroundColor = statusBarBg.String() + sp.Style = spinnerStyle sp.HideFor = time.Millisecond * 50 sp.MinimumLifetime = time.Millisecond * 180 diff --git a/ui/stash.go b/ui/stash.go index 614f384..9f8b47a 100644 --- a/ui/stash.go +++ b/ui/stash.go @@ -13,11 +13,10 @@ import ( "github.com/charmbracelet/bubbles/spinner" "github.com/charmbracelet/bubbles/textinput" tea "github.com/charmbracelet/bubbletea" - lib "github.com/charmbracelet/charm/ui/common" "github.com/charmbracelet/glow/client" + "github.com/charmbracelet/lipgloss" "github.com/muesli/reflow/ansi" "github.com/muesli/reflow/truncate" - te "github.com/muesli/termenv" "github.com/sahilm/fuzzy" ) @@ -35,10 +34,23 @@ var ( ) var ( - stashTextInputPromptStyle styleFunc = newFgStyle(lib.YellowGreen) - dividerDot string = darkGrayFg(" • ") - dividerBar string = darkGrayFg(" │ ") - offlineHeaderNote string = darkGrayFg("(Offline)") + dividerDot = darkGrayFg(" • ") + dividerBar = darkGrayFg(" │ ") + offlineHeaderNote = darkGrayFg("(Offline)") + + logoStyle = lipgloss.NewStyle(). + Foreground(lipgloss.Color("#ECFD65")). + Background(fuschia). + Bold(true) + + stashSpinnerStyle = lipgloss.NewStyle(). + Foreground(gray) + stashInputPromptStyle = lipgloss.NewStyle(). + Foreground(yellowGreen). + MarginRight(1) + stashInputCursorStyle = lipgloss.NewStyle(). + Foreground(fuschia). + MarginRight(1) ) // MSG @@ -499,20 +511,22 @@ func (m *stashModel) moveCursorDown() { func newStashModel(common *commonModel) stashModel { sp := spinner.NewModel() sp.Spinner = spinner.Line - sp.ForegroundColor = lib.SpinnerColor.String() + sp.Style = stashSpinnerStyle sp.HideFor = time.Millisecond * 100 sp.MinimumLifetime = time.Millisecond * 180 sp.Start() ni := textinput.NewModel() - ni.Prompt = stashTextInputPromptStyle("Memo: ") - ni.CursorColor = lib.Fuschia.String() + ni.Prompt = "Memo:" + ni.PromptStyle = stashInputPromptStyle + ni.CursorStyle = stashInputCursorStyle ni.CharLimit = noteCharacterLimit ni.Focus() si := textinput.NewModel() - si.Prompt = stashTextInputPromptStyle("Find: ") - si.CursorColor = lib.Fuschia.String() + si.Prompt = "Find:" + si.PromptStyle = stashInputPromptStyle + si.CursorStyle = stashInputCursorStyle si.CharLimit = noteCharacterLimit si.Focus() @@ -1195,7 +1209,7 @@ func (m stashModel) view() string { // pointers in our model should be refactored away. var p paginator.Model = *(m.paginator()) p.Type = paginator.Arabic - pagination = lib.Subtle(p.View()) + pagination = paginationStyle.Render(p.View()) } // We could also look at m.stashFullyLoaded and add an indicator @@ -1218,11 +1232,7 @@ func (m stashModel) view() string { } func glowLogoView(text string) string { - return te.String(text). - Bold(). - Foreground(glowLogoTextColor). - Background(lib.Fuschia.Color()). - String() + return logoStyle.Render(text) } func (m stashModel) headerView() string { @@ -1258,9 +1268,9 @@ func (m stashModel) headerView() string { } if m.stashedOnly() { - return lib.Subtle("Can’t load stash") + maybeOffline + return subtleStyle.Render("Can’t load stash") + maybeOffline } - return lib.Subtle("No markdown files found") + maybeOffline + return subtleStyle.Render("No markdown files found") + maybeOffline } // Tabs @@ -1288,9 +1298,9 @@ func (m stashModel) headerView() string { } if m.sectionIndex == i && len(m.sections) > 1 { - s = selectedTabColor(s) + s = selectedTabStyle.Render(s) } else { - s = tabColor(s) + s = tabStyle.Render(s) } sections = append(sections, s) } @@ -1379,7 +1389,7 @@ func loadRemoteMarkdown(cc *client.Client, md *markdown) tea.Cmd { newMD, err := fetchMarkdown(cc, md.ID, md.docType) if err != nil { if debug { - log.Printf("error loading %s markdown (ID %d, Note: '%s'): %v", md.docType, md.ID, md.Note, err) + log.Printf("error loading %s markdown (ID %s, Note: '%s'): %v", md.docType, md.ID, md.Note, err) } return markdownFetchFailedMsg{ err: err, diff --git a/ui/stashhelp.go b/ui/stashhelp.go index fea1fdf..a53dfca 100644 --- a/ui/stashhelp.go +++ b/ui/stashhelp.go @@ -4,7 +4,6 @@ import ( "fmt" "strings" - lib "github.com/charmbracelet/charm/ui/common" "github.com/muesli/reflow/ansi" ) @@ -195,7 +194,7 @@ func (m stashModel) miniHelpView(entries ...string) string { } var ( - truncationChar = lib.Subtle("…") + truncationChar = subtleStyle.Render("…") truncationWidth = ansi.PrintableRuneWidth(truncationChar) ) diff --git a/ui/stashitem.go b/ui/stashitem.go index 7c5005e..4389754 100644 --- a/ui/stashitem.go +++ b/ui/stashitem.go @@ -5,10 +5,9 @@ import ( "log" "strings" - lib "github.com/charmbracelet/charm/ui/common" + "github.com/charmbracelet/lipgloss" "github.com/muesli/reflow/ansi" "github.com/muesli/reflow/truncate" - "github.com/muesli/termenv" "github.com/sahilm/fuzzy" ) @@ -77,8 +76,8 @@ func stashItemView(b *strings.Builder, m stashModel, index int, md *markdown) { icon = dullFuchsiaFg(icon) if m.currentSection().key == filterSection && m.filterState == filterApplied || singleFilteredItem { - s := termenv.Style{}.Foreground(lib.Fuschia.Color()) - title = styleFilteredText(title, m.filterInput.Value(), s, s.Underline()) + s := lipgloss.NewStyle().Foreground(fuschia) + title = styleFilteredText(title, m.filterInput.Value(), s, s.Copy().Underline(true)) } else { title = fuchsiaFg(title) } @@ -100,8 +99,8 @@ func stashItemView(b *strings.Builder, m stashModel, index int, md *markdown) { title = dimIndigoFg(title) date = dimSubtleIndigoFg(date) } else { - s := termenv.Style{}.Foreground(lib.Indigo.Color()) - title = styleFilteredText(title, m.filterInput.Value(), s, s.Underline()) + s := lipgloss.NewStyle().Foreground(indigo) + title = styleFilteredText(title, m.filterInput.Value(), s, s.Copy().Underline(true)) date = subtleIndigoFg(date) } } else if isFiltering && m.filterInput.Value() == "" { @@ -117,8 +116,8 @@ func stashItemView(b *strings.Builder, m stashModel, index int, md *markdown) { if title == noMemoTitle { title = brightGrayFg(title) } else { - s := termenv.Style{}.Foreground(lib.NewColorPair("#dddddd", "#1a1a1a").Color()) - title = styleFilteredText(title, m.filterInput.Value(), s, s.Underline()) + s := lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#1a1a1a", Dark: "#dddddd"}) + title = styleFilteredText(title, m.filterInput.Value(), s, s.Copy().Underline(true)) } date = brightGrayFg(date) } @@ -128,7 +127,7 @@ func stashItemView(b *strings.Builder, m stashModel, index int, md *markdown) { fmt.Fprintf(b, "%s %s", gutter, date) } -func styleFilteredText(haystack, needles string, defaultStyle, matchedStyle termenv.Style) string { +func styleFilteredText(haystack, needles string, defaultStyle, matchedStyle lipgloss.Style) string { b := strings.Builder{} normalizedHay, err := normalize(haystack) @@ -138,7 +137,7 @@ func styleFilteredText(haystack, needles string, defaultStyle, matchedStyle term matches := fuzzy.Find(needles, []string{normalizedHay}) if len(matches) == 0 { - return defaultStyle.Styled(haystack) + return defaultStyle.Render(haystack) } m := matches[0] // only one match exists @@ -146,12 +145,12 @@ func styleFilteredText(haystack, needles string, defaultStyle, matchedStyle term styled := false for _, mi := range m.MatchedIndexes { if i == mi { - b.WriteString(matchedStyle.Styled(string(rune))) + b.WriteString(matchedStyle.Render(string(rune))) styled = true } } if !styled { - b.WriteString(defaultStyle.Styled(string(rune))) + b.WriteString(defaultStyle.Render(string(rune))) } } diff --git a/ui/styles.go b/ui/styles.go index ed527f4..fe7c0ff 100644 --- a/ui/styles.go +++ b/ui/styles.go @@ -1,63 +1,85 @@ package ui import ( - lib "github.com/charmbracelet/charm/ui/common" - te "github.com/muesli/termenv" + . "github.com/charmbracelet/lipgloss" ) -type styleFunc func(string) string +// Colors. +var ( + normal = AdaptiveColor{Light: "#1A1A1A", Dark: "#dddddd"} + normalDim = AdaptiveColor{Light: "#A49FA5", Dark: "#777777"} + gray = AdaptiveColor{Light: "#909090", Dark: "#626262"} + midGray = AdaptiveColor{Light: "#B2B2B2", Dark: "#4A4A4A"} + darkGray = AdaptiveColor{Light: "#DDDADA", Dark: "#3C3C3C"} + brightGray = AdaptiveColor{Light: "#847A85", Dark: "#979797"} + dimBrightGray = AdaptiveColor{Light: "#C2B8C2", Dark: "#4D4D4D"} + indigo = AdaptiveColor{Light: "#5A56E0", Dark: "#7571F9"} + dimIndigo = AdaptiveColor{Light: "#9498FF", Dark: "#494690"} + subtleIndigo = AdaptiveColor{Light: "#7D79F6", Dark: "#514DC1"} + dimSubtleIndigo = AdaptiveColor{Light: "#BBBDFF", Dark: "#383584"} + cream = AdaptiveColor{Light: "#FFFDF5", Dark: "#FFFDF5"} + yellowGreen = AdaptiveColor{Light: "#04B575", Dark: "#ECFD65"} + dullYellowGreen = AdaptiveColor{Light: "#6BCB94", Dark: "#9BA92F"} + fuschia = AdaptiveColor{Light: "#EE6FF8", Dark: "#EE6FF8"} + dimFuchsia = AdaptiveColor{Light: "#F1A8FF", Dark: "#99519E"} + dullFuchsia = AdaptiveColor{Dark: "#AD58B4", Light: "#F793FF"} + dimDullFuchsia = AdaptiveColor{Light: "#F6C9FF", Dark: "#6B3A6F"} + green = Color("#04B575") + red = AdaptiveColor{Light: "#FF4672", Dark: "#ED567A"} + faintRed = AdaptiveColor{Light: "#FF6F91", Dark: "#C74665"} -const ( - darkGray = "#333333" + semiDimGreen = AdaptiveColor{Light: "#35D79C", Dark: "#036B46"} + dimGreen = AdaptiveColor{Light: "#72D2B0", Dark: "#0B5137"} +) + +// Ulimately, we'll transition to named styles. +var ( + normalFg = NewStyle().Foreground(normal).Render + dimNormalFg = NewStyle().Foreground(normalDim).Render + + brightGrayFg = NewStyle().Foreground(brightGray).Render + dimBrightGrayFg = NewStyle().Foreground(dimBrightGray).Render + + grayFg = NewStyle().Foreground(gray).Render + midGrayFg = NewStyle().Foreground(midGray).Render + darkGrayFg = NewStyle().Foreground(darkGray).Render + + greenFg = NewStyle().Foreground(green).Render + semiDimGreenFg = NewStyle().Foreground(semiDimGreen).Render + dimGreenFg = NewStyle().Foreground(dimGreen).Render + + fuchsiaFg = NewStyle().Foreground(fuschia).Render + dimFuchsiaFg = NewStyle().Foreground(dimFuchsia).Render + + dullFuchsiaFg = NewStyle().Foreground(dullFuchsia).Render + dimDullFuchsiaFg = NewStyle().Foreground(dimDullFuchsia).Render + + indigoFg = NewStyle().Foreground(fuschia).Render + dimIndigoFg = NewStyle().Foreground(dimIndigo).Render + + subtleIndigoFg = NewStyle().Foreground(subtleIndigo).Render + dimSubtleIndigoFg = NewStyle().Foreground(dimSubtleIndigo).Render + + yellowFg = NewStyle().Foreground(yellowGreen).Render // renders light green on light backgrounds + dullYellowFg = NewStyle().Foreground(dullYellowGreen).Render // renders light green on light backgrounds + redFg = NewStyle().Foreground(red).Render + faintRedFg = NewStyle().Foreground(faintRed).Render ) var ( - normalFg = newFgStyle(lib.NewColorPair("#dddddd", "#1a1a1a")) - dimNormalFg = newFgStyle(lib.NewColorPair("#777777", "#A49FA5")) + tabStyle = NewStyle(). + Foreground(AdaptiveColor{Light: "#909090", Dark: "#626262"}) - brightGrayFg = newFgStyle(lib.NewColorPair("#979797", "#847A85")) - dimBrightGrayFg = newFgStyle(lib.NewColorPair("#4D4D4D", "#C2B8C2")) + selectedTabStyle = NewStyle(). + Foreground(AdaptiveColor{Light: "#333333", Dark: "#979797"}) - grayFg = newFgStyle(lib.NewColorPair("#626262", "#909090")) - midGrayFg = newFgStyle(lib.NewColorPair("#4A4A4A", "#B2B2B2")) - darkGrayFg = newFgStyle(lib.NewColorPair("#3C3C3C", "#DDDADA")) + errorTitleStyle = NewStyle(). + Foreground(cream). + Background(red). + Padding(0, 1) - greenFg = newFgStyle(lib.NewColorPair("#04B575", "#04B575")) - semiDimGreenFg = newFgStyle(lib.NewColorPair("#036B46", "#35D79C")) - dimGreenFg = newFgStyle(lib.NewColorPair("#0B5137", "#72D2B0")) + subtleStyle = NewStyle(). + Foreground(AdaptiveColor{Light: "#9B9B9B", Dark: "#5C5C5C"}) - fuchsiaFg = newFgStyle(lib.Fuschia) - dimFuchsiaFg = newFgStyle(lib.NewColorPair("#99519E", "#F1A8FF")) - - dullFuchsiaFg = newFgStyle(lib.NewColorPair("#AD58B4", "#F793FF")) - dimDullFuchsiaFg = newFgStyle(lib.NewColorPair("#6B3A6F", "#F6C9FF")) - - indigoFg = newFgStyle(lib.Indigo) - dimIndigoFg = newFgStyle(lib.NewColorPair("#494690", "#9498FF")) - - subtleIndigoFg = newFgStyle(lib.NewColorPair("#514DC1", "#7D79F6")) - dimSubtleIndigoFg = newFgStyle(lib.NewColorPair("#383584", "#BBBDFF")) - - yellowFg = newFgStyle(lib.YellowGreen) // renders light green on light backgrounds - dullYellowFg = newFgStyle(lib.NewColorPair("#9BA92F", "#6BCB94")) // renders light green on light backgrounds - redFg = newFgStyle(lib.Red) - faintRedFg = newFgStyle(lib.FaintRed) - - // Ultimately, we should transition to named styles - tabColor = newFgStyle(lib.NewColorPair("#626262", "#909090")) - selectedTabColor = newFgStyle(lib.NewColorPair("#979797", "#332F33")) + paginationStyle = subtleStyle.Copy() ) - -// Returns a termenv style with foreground and background options. -func newStyle(fg, bg lib.ColorPair, bold bool) func(string) string { - s := te.Style{}.Foreground(fg.Color()).Background(bg.Color()) - if bold { - s = s.Bold() - } - return s.Styled -} - -// Returns a new termenv style with background options only. -func newFgStyle(c lib.ColorPair) styleFunc { - return te.Style{}.Foreground(c.Color()).Styled -} diff --git a/ui/ui.go b/ui/ui.go index f26aa95..94b116f 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -14,7 +14,6 @@ import ( tea "github.com/charmbracelet/bubbletea" charm "github.com/charmbracelet/charm/proto" "github.com/charmbracelet/charm/ui/common" - lib "github.com/charmbracelet/charm/ui/common" "github.com/charmbracelet/charm/ui/keygen" "github.com/charmbracelet/glow/client" "github.com/charmbracelet/glow/utils" @@ -30,8 +29,7 @@ const ( ) var ( - config Config - glowLogoTextColor = lib.Color("#ECFD65") + config Config markdownExtensions = []string{ "*.md", "*.mdown", "*.mkdn", "*.mkd", "*.markdown", @@ -454,10 +452,7 @@ func errorView(err error, fatal bool) string { exitMsg += "return" } s := fmt.Sprintf("%s\n\n%v\n\n%s", - te.String(" ERROR "). - Foreground(lib.Cream.Color()). - Background(lib.Red.Color()). - String(), + errorTitleStyle.Render("ERROR"), err, common.Subtle(exitMsg), )