feat: update glamour (#634)

* feat: updating glamour

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* fix: trim space

* chore: bump

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* chore(deps): bump

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* fix: perms

* fix: improve logs

* feat: update glamour

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker 2024-08-21 14:43:05 -03:00 committed by GitHub
parent 4578bc149a
commit c89c8bd6e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 31 additions and 25 deletions

2
go.mod
View file

@ -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

4
go.sum
View file

@ -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=

4
log.go
View file

@ -1,6 +1,7 @@
package main
import (
"io"
"os"
"path/filepath"
@ -17,12 +18,13 @@ func getLogFilePath() (string, error) {
}
func setupLog() (func() error, error) {
log.SetOutput(io.Discard)
// Log to file, if set
logFile, err := getLogFilePath()
if err != nil {
return nil, err
}
if err := os.MkdirAll(filepath.Dir(logFile), 0o644); err != nil {
if err := os.MkdirAll(filepath.Dir(logFile), 0o755); err != nil {
// log disabled
return func() error { return nil }, nil
}

View file

@ -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)

View file

@ -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
}
}

View file

@ -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)
}