Skip to content

Commit

Permalink
fix glow_style and glamour_style usage
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-sol committed Mar 4, 2025
1 parent 7dc4b9c commit 3375e47
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
13 changes: 3 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,7 @@ func executeCLI(cmd *cobra.Command, src *source, w io.Writer) error {
// display
switch {
case pager || cmd.Flags().Changed("pager"):
pagerCmd := os.Getenv("PAGER")
if pagerCmd == "" {
pagerCmd = "less -r"
}
pagerCmd := utils.Getenv("PAGER", "less -r")

pa := strings.Split(pagerCmd, " ")
c := exec.Command(pa[0], pa[1:]...) // nolint:gosec
Expand All @@ -332,15 +329,11 @@ func runTUI(path string, content string) error {
return fmt.Errorf("error parsing config: %v", err)
}

// use style set in env, or auto if unset
if err := validateStyle(cfg.GlamourStyle); err != nil {
cfg.GlamourStyle = style
}

cfg.Path = path
cfg.ShowAllFiles = showAllFiles
cfg.ShowLineNumbers = showLineNumbers
cfg.GlamourMaxWidth = width
cfg.GlamourStyle = style
cfg.EnableMouse = mouse
cfg.PreserveNewLines = preserveNewLines

Expand Down Expand Up @@ -400,7 +393,7 @@ func init() {
_ = viper.BindPFlag("showLineNumbers", rootCmd.Flags().Lookup("line-numbers"))
_ = viper.BindPFlag("all", rootCmd.Flags().Lookup("all"))

viper.SetDefault("style", styles.AutoStyle)
viper.SetDefault("style", utils.Getenv("GLAMOUR_STYLE", styles.AutoStyle))
viper.SetDefault("width", 0)
viper.SetDefault("all", true)

Expand Down
2 changes: 1 addition & 1 deletion ui/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type Config struct {
Gopath string `env:"GOPATH"`
HomeDir string `env:"HOME"`
GlamourMaxWidth uint
GlamourStyle string `env:"GLAMOUR_STYLE"`
GlamourStyle string
EnableMouse bool
PreserveNewLines bool

Expand Down
9 changes: 9 additions & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ func ExpandPath(path string) string {
return os.ExpandEnv(path)
}

// Getenv retrieves the value of the environment variable named by the key.
// It returns the value, or fallback value if the variable is not present.
func Getenv(key string, fallback string) string {
if v := os.Getenv(key); v != "" {
return v
}
return fallback
}

// WrapCodeBlock wraps a string in a code block with the given language.
func WrapCodeBlock(s, language string) string {
return "```" + language + "\n" + s + "```"
Expand Down

0 comments on commit 3375e47

Please sign in to comment.