From 19d21b8d697562e6a6e73f8445aa24f42333199c Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Tue, 6 Aug 2024 16:07:24 -0300 Subject: [PATCH] feat: update glamour --- go.mod | 2 +- go.sum | 4 ++-- main.go | 7 ++++--- ui/ui.go | 8 ++++---- utils/utils.go | 31 +++++++++++++++++-------------- 5 files changed, 28 insertions(+), 24 deletions(-) diff --git a/go.mod b/go.mod index abba41ac..21e029d7 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/caarlos0/env/v11 v11.0.1 github.com/charmbracelet/bubbles v0.18.0 github.com/charmbracelet/bubbletea v0.26.7-0.20240711210516-ea13ffb9a18d - github.com/charmbracelet/glamour v0.7.1-0.20240725142829-adb0b8d1c3ea + github.com/charmbracelet/glamour v0.8.0 github.com/charmbracelet/lipgloss v0.12.2-0.20240712161825-87dd58def709 github.com/charmbracelet/log v0.4.0 github.com/charmbracelet/x/editor v0.0.0-20240625164403-2627ec16405d diff --git a/go.sum b/go.sum index 1fd41c14..dc8370ec 100644 --- a/go.sum +++ b/go.sum @@ -59,8 +59,8 @@ github.com/charmbracelet/bubbles v0.18.0 h1:PYv1A036luoBGroX6VWjQIE9Syf2Wby2oOl/ github.com/charmbracelet/bubbles v0.18.0/go.mod h1:08qhZhtIwzgrtBjAcJnij1t1H0ZRjwHyGsy6AL11PSw= github.com/charmbracelet/bubbletea v0.26.7-0.20240711210516-ea13ffb9a18d h1:IHcf2pu0D9dau/Z1Jff53mke0Yc62lf1sVRl0vWsAew= github.com/charmbracelet/bubbletea v0.26.7-0.20240711210516-ea13ffb9a18d/go.mod h1:MT/hMxp8fkrH8YV7AZ0KM7SeveivHPy0lUaZL0sBOxU= -github.com/charmbracelet/glamour v0.7.1-0.20240725142829-adb0b8d1c3ea h1:+zL7DrRjedvLEMQtKEajxpGMHMMD1y9yyk30TZyEx34= -github.com/charmbracelet/glamour v0.7.1-0.20240725142829-adb0b8d1c3ea/go.mod h1:8oyd4gn8mrEWXeMnQq172bcowKd6LSmR8tOCS3sXn/s= +github.com/charmbracelet/glamour v0.8.0 h1:tPrjL3aRcQbn++7t18wOpgLyl8wrOHUEDS7IZ68QtZs= +github.com/charmbracelet/glamour v0.8.0/go.mod h1:ViRgmKkf3u5S7uakt2czJ272WSg2ZenlYEZXT2x7Bjw= github.com/charmbracelet/lipgloss v0.12.2-0.20240712161825-87dd58def709 h1:xKyYI89iCZPBA4QOBN1WQ8Fqt+iH09K3Ywx0qOKVPUo= github.com/charmbracelet/lipgloss v0.12.2-0.20240712161825-87dd58def709/go.mod h1:lVwxBOJ0KkZflL9y+DObgGY8V90IZUJ1e6jjZ+PBcnE= github.com/charmbracelet/log v0.4.0 h1:G9bQAcx8rWA2T3pWvx7YtPTPwgqpk7D68BX21IRW8ZM= diff --git a/main.go b/main.go index 513482aa..31ae6f32 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,7 @@ import ( "github.com/caarlos0/env/v11" "github.com/charmbracelet/glamour" + "github.com/charmbracelet/glamour/styles" "github.com/charmbracelet/glow/ui" "github.com/charmbracelet/glow/utils" "github.com/charmbracelet/lipgloss" @@ -149,7 +150,7 @@ func validateOptions(cmd *cobra.Command) error { // validate the glamour style style = viper.GetString("style") - if style != glamour.AutoStyle && glamour.DefaultStyles[style] == nil { + if style != styles.AutoStyle && styles.DefaultStyles[style] == nil { style = utils.ExpandPath(style) if _, err := os.Stat(style); errors.Is(err, fs.ErrNotExist) { return fmt.Errorf("Specified style does not exist: %s", style) @@ -357,7 +358,7 @@ func init() { // "Glow Classic" cli arguments rootCmd.PersistentFlags().StringVar(&configFile, "config", "", fmt.Sprintf("config file (default %s)", viper.GetViper().ConfigFileUsed())) rootCmd.Flags().BoolVarP(&pager, "pager", "p", false, "display with pager") - rootCmd.Flags().StringVarP(&style, "style", "s", glamour.AutoStyle, "style name or JSON path") + rootCmd.Flags().StringVarP(&style, "style", "s", styles.AutoStyle, "style name or JSON path") rootCmd.Flags().UintVarP(&width, "width", "w", 0, "word-wrap at width (set to 0 to disable)") rootCmd.Flags().BoolVarP(&showAllFiles, "all", "a", false, "show system files and directories (TUI-mode only)") rootCmd.Flags().BoolVarP(&showLineNumbers, "line-numbers", "l", false, "show line numbers (TUI-mode only)") @@ -374,7 +375,7 @@ func init() { _ = viper.BindPFlag("showLineNumbers", rootCmd.Flags().Lookup("line-numbers")) _ = viper.BindPFlag("showAllFiles", rootCmd.Flags().Lookup("all")) - viper.SetDefault("style", glamour.AutoStyle) + viper.SetDefault("style", styles.AutoStyle) viper.SetDefault("width", 0) rootCmd.AddCommand(configCmd, manCmd) diff --git a/ui/ui.go b/ui/ui.go index 512df581..960f82c3 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -9,7 +9,7 @@ import ( "github.com/charmbracelet/bubbles/list" tea "github.com/charmbracelet/bubbletea" - "github.com/charmbracelet/glamour" + "github.com/charmbracelet/glamour/styles" "github.com/charmbracelet/glow/utils" "github.com/charmbracelet/lipgloss" "github.com/charmbracelet/log" @@ -134,11 +134,11 @@ func (m *model) unloadDocument() []tea.Cmd { func newModel(cfg Config) tea.Model { initSections() - if cfg.GlamourStyle == glamour.AutoStyle { + if cfg.GlamourStyle == styles.AutoStyle { if te.HasDarkBackground() { - cfg.GlamourStyle = glamour.DarkStyle + cfg.GlamourStyle = styles.DarkStyle } else { - cfg.GlamourStyle = glamour.LightStyle + cfg.GlamourStyle = styles.LightStyle } } diff --git a/utils/utils.go b/utils/utils.go index 693cccc1..8240c36f 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -8,6 +8,7 @@ import ( "github.com/charmbracelet/glamour" "github.com/charmbracelet/glamour/ansi" + "github.com/charmbracelet/glamour/styles" "github.com/charmbracelet/lipgloss" "github.com/mitchellh/go-homedir" ) @@ -69,7 +70,7 @@ func IsMarkdownFile(filename string) bool { func GlamourStyle(style string, isCode bool) glamour.TermRendererOption { if !isCode { - if style == glamour.AutoStyle { + if style == styles.AutoStyle { return glamour.WithAutoStyle() } else { return glamour.WithStylePath(style) @@ -82,22 +83,24 @@ func GlamourStyle(style string, isCode bool) glamour.TermRendererOption { var styleConfig ansi.StyleConfig switch style { - case glamour.AutoStyle: + case styles.AutoStyle: if lipgloss.HasDarkBackground() { - styleConfig = glamour.DarkStyleConfig + styleConfig = styles.DarkStyleConfig } else { - styleConfig = glamour.LightStyleConfig + styleConfig = styles.LightStyleConfig } - case glamour.DarkStyle: - styleConfig = glamour.DarkStyleConfig - case glamour.LightStyle: - styleConfig = glamour.LightStyleConfig - case glamour.PinkStyle: - styleConfig = glamour.PinkStyleConfig - case glamour.NoTTYStyle: - styleConfig = glamour.NoTTYStyleConfig - case glamour.DraculaStyle: - styleConfig = glamour.DraculaStyleConfig + case styles.DarkStyle: + styleConfig = styles.DarkStyleConfig + case styles.LightStyle: + styleConfig = styles.LightStyleConfig + case styles.PinkStyle: + styleConfig = styles.PinkStyleConfig + case styles.NoTTYStyle: + styleConfig = styles.NoTTYStyleConfig + case styles.DraculaStyle: + styleConfig = styles.DraculaStyleConfig + case styles.TokyoNightStyle: + styleConfig = styles.DraculaStyleConfig default: return glamour.WithStylesFromJSONFile(style) }