Skip to content

Commit

Permalink
feat: update glamour
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Aug 6, 2024
1 parent e98d7ff commit 19d21b8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)")
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
}

Expand Down
31 changes: 17 additions & 14 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down

0 comments on commit 19d21b8

Please sign in to comment.