mirror of
https://github.com/charmbracelet/gum.git
synced 2024-09-11 06:16:03 +03:00
feat: allow passing language to parse code
This commit is contained in:
parent
b6daeece02
commit
95ddbdb416
@ -29,7 +29,7 @@ func (o Options) Run() error {
|
||||
|
||||
switch o.Type {
|
||||
case "code":
|
||||
output, err = code(input)
|
||||
output, err = code(input, o.Language)
|
||||
case "emoji":
|
||||
output, err = emoji(input)
|
||||
case "template":
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"github.com/muesli/termenv"
|
||||
)
|
||||
|
||||
func code(input string) (string, error) {
|
||||
func code(input, language string) (string, error) {
|
||||
renderer, err := glamour.NewTermRenderer(
|
||||
glamour.WithAutoStyle(),
|
||||
glamour.WithWordWrap(0),
|
||||
@ -17,7 +17,7 @@ func code(input string) (string, error) {
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unable to create renderer: %w", err)
|
||||
}
|
||||
output, err := renderer.Render(fmt.Sprintf("```\n%s\n```", input))
|
||||
output, err := renderer.Render(fmt.Sprintf("```%s\n%s\n```", language, input))
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unable to render: %w", err)
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ package format
|
||||
type Options struct {
|
||||
Template []string `arg:"" optional:"" help:"Template string to format (can also be provided via stdin)"`
|
||||
Theme string `help:"Glamour theme to use for markdown formatting" default:"pink"`
|
||||
Language string `help:"Programming language to parse code" short:"l" default:""`
|
||||
|
||||
Type string `help:"Format to use (markdown,template,code,emoji)" enum:"markdown,template,code,emoji" short:"t" default:"markdown"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user