Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#58): write to stdout if not tty #102

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}