Format comments with a gray foreground

This commit is contained in:
Gabe Cook
2024-11-10 03:30:03 -06:00
parent 39a81da170
commit 9caeb429ac
4 changed files with 29 additions and 20 deletions
+6
View File
@@ -56,6 +56,12 @@ func colorizeAndPrint(yamlBytes []byte, writer io.Writer) error {
Suffix: format(color.Reset),
}
}
p.Comment = func() *printer.Property {
return &printer.Property{
Prefix: format(color.FgHiBlack),
Suffix: format(color.Reset),
}
}
_, err := writer.Write([]byte(p.PrintTokens(tokens) + "\n"))
return err
}
+5 -1
View File
@@ -8,7 +8,8 @@ import (
"regexp"
"strings"
yaml "gopkg.in/yaml.v3"
"github.com/fatih/color"
"gopkg.in/yaml.v3"
)
type yamlEncoder struct {
@@ -54,6 +55,9 @@ func (ye *yamlEncoder) PrintLeadingContent(writer io.Writer, content string) err
if len(readline) > 0 && readline != "\n" && readline[0] != '%' && !commentLineRegEx.MatchString(readline) {
readline = "# " + readline
}
if ye.prefs.ColorsEnabled && strings.TrimSpace(readline) != "" {
readline = format(color.FgHiBlack) + readline + format(color.Reset)
}
if err := writeString(writer, readline); err != nil {
return err
}