diff --git a/main.go b/main.go index 56f9892f..78764c64 100644 --- a/main.go +++ b/main.go @@ -409,7 +409,9 @@ func main() { if svgConversionErr != nil { printErrorFatal("Unable to convert SVG to PNG", svgConversionErr) } - printFilenameOutput(config.Output) + if istty { + printFilenameOutput(config.Output) + } default: // output file specified. diff --git a/png.go b/png.go index af0348f0..d019621d 100644 --- a/png.go +++ b/png.go @@ -9,8 +9,11 @@ import ( "github.com/beevik/etree" "github.com/charmbracelet/freeze/font" "github.com/kanrichan/resvg-go" + "github.com/mattn/go-isatty" ) +var istty = isatty.IsTerminal(os.Stdout.Fd()) + func libsvgConvert(doc *etree.Document, w, h float64, output string) error { _, err := exec.LookPath("rsvg-convert") if err != nil { @@ -27,6 +30,9 @@ func libsvgConvert(doc *etree.Document, w, h float64, output string) error { rsvgConvert := exec.Command("rsvg-convert", "-o", output) rsvgConvert.Stdin = bytes.NewReader(svg) err = rsvgConvert.Run() + if !istty { + _, err = doc.WriteTo(os.Stdout) + } return err } @@ -94,5 +100,8 @@ func resvgConvert(doc *etree.Document, w, h float64, output string) error { if err != nil { return err } + if !istty { + _, err = doc.WriteTo(os.Stdout) + } return err }