1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
// Package format allows you to render formatted text from the command line.
//
// It supports the following types:
//
// 1. Markdown
// 2. Code
// 3. Emoji
// 4. Template
//
// For more information, see the format/README.md file.
package format
import (
"fmt"
"strings"
"github.com/charmbracelet/gum/internal/stdin"
)
// Run runs the format command.
func (o Options) Run() error {
var input, output string
var err error
if len(o.Template) > 0 {
input = strings.Join(o.Template, "\n")
} else {
input, _ = stdin.Read(stdin.StripANSI(o.StripANSI))
}
switch o.Type {
case "code":
output, err = code(input, o.Language)
case "emoji":
output, err = emoji(input)
case "template":
output, err = template(input)
default:
output, err = markdown(input, o.Theme)
}
if err != nil {
return err
}
fmt.Print(output)
return nil
}
|