Provide a Glamour CLI tool
chrisgilmerproj opened this issue · comments
I'm using charmbracelet/gum and realized I didn't have a good way to use this project to format markdown files. Ideally I'd be able to use gum pager --glamour < myfile.md
. I'm not sure if the team would even want glamour built into gum so I thought a better solution would be glamour myfile.md | gum pager
for my needs. I used the code below to build it. Would this project be interested in including a CLI tool for glamour that we could install with brew on mac or on linux? I'm sure a more full-featured CLI tool could be built.
package main
import (
"fmt"
"os"
"github.com/charmbracelet/glamour"
)
func main() {
if len(os.Args) < 2 {
fmt.Println("Usage: glamour <filename.md>")
os.Exit(1)
}
markdownFile := os.Args[1]
markdownContent, err := os.ReadFile(markdownFile)
if err != nil {
fmt.Println("Error reading Markdown file:", err)
os.Exit(1)
}
renderer, err := glamour.NewTermRenderer(
glamour.WithAutoStyle(),
)
if err != nil {
fmt.Println("Error creating Glamour renderer:", err)
os.Exit(1)
}
formattedOutput, err := renderer.RenderBytes(markdownContent)
if err != nil {
fmt.Println("Error formatting Markdown content:", err)
os.Exit(1)
}
fmt.Println(string(formattedOutput))
}
Hey @chrisgilmerproj, maybe we need to document this better but I think gum format
is what you might be looking for:
gum format --format markdown --theme dark file.md
@maaslalani - You are correct. What I needed was:
gum format --theme dark --type markdown < file.md
This helps a lot. Sorry for opening the ticket here. I might suggest putting this in the README.md for this project and linking over to gum. Thanks.
I should mention that I am not entirely clear how to use gum pager
and gum format
together. If you could help me out I'd appreciate it.