mirror of
https://github.com/charmbracelet/glow.git
synced 2026-08-21 23:54:17 +02:00
Use a plain-text renderer when not printing to Terminal
This commit is contained in:
parent
dca563ea25
commit
f09d2907bd
1 changed files with 9 additions and 4 deletions
13
main.go
13
main.go
|
|
@ -10,6 +10,7 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/mattn/go-isatty"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/charmbracelet/gold"
|
||||
|
|
@ -80,12 +81,16 @@ func execute(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
}
|
||||
defer in.Close()
|
||||
|
||||
b, _ := ioutil.ReadAll(in)
|
||||
r, err := gold.NewTermRenderer(style)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
r := gold.NewPlainTermRenderer()
|
||||
if isatty.IsTerminal(os.Stdout.Fd()) {
|
||||
r, err = gold.NewTermRenderer(style)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
out := r.RenderBytes(b)
|
||||
fmt.Printf("%s", string(out))
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue