From 5933a5ae5fd8decf70e1e49bc2d877441f0e4479 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 20 Dec 2020 19:15:15 +0100 Subject: Set `pkg/browser`'s `Stderr` and `Stdout` to ours We need to connect our `Stderr` and `Stdout` to those in `github.com/pkg/browser` so that custom writers get linked correctly in the underlying library. Previously, customising these writers only worked for the command specified in the `BROWSER` environment variable, not when `BROWSER` was unset. --- browserenv.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'browserenv.go') diff --git a/browserenv.go b/browserenv.go index 8401a32..ff31ead 100644 --- a/browserenv.go +++ b/browserenv.go @@ -42,6 +42,8 @@ func OpenFile(path string) error { return runBrowserCommand(envCommand, url) } + setBrowserStdDescriptors() + return browser.OpenFile(path) } @@ -63,6 +65,8 @@ func OpenReader(r io.Reader) error { return OpenFile(tempFile.Name()) } + setBrowserStdDescriptors() + return browser.OpenReader(r) } @@ -73,6 +77,8 @@ func OpenURL(url string) error { return runBrowserCommand(envCommand, url) } + setBrowserStdDescriptors() + return browser.OpenURL(url) } @@ -150,3 +156,10 @@ func fmtWithURL(command, url string) string { func escapeURL(url string) string { return strings.ReplaceAll(url, "'", "%27") } + +// setBrowserStdDescriptors sets browser.Stderr and browser.Stdout to Stderr +// and Stdout respectively. +func setBrowserStdDescriptors() { + browser.Stderr = Stderr + browser.Stdout = Stdout +} -- cgit v1.2.3