Skip to content

Commit

Permalink
feat(charmbracelet#58): write to stdout if not tty
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroSuero committed Jun 3, 2024
1 parent fc03c0d commit c00a827
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions png.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}

0 comments on commit c00a827

Please sign in to comment.