aboutsummaryrefslogtreecommitdiffstats
path: root/browserenv.go
diff options
context:
space:
mode:
authorTeddy Wing2020-12-20 19:15:15 +0100
committerTeddy Wing2020-12-20 19:18:15 +0100
commit5933a5ae5fd8decf70e1e49bc2d877441f0e4479 (patch)
tree147ce1cd4981ddb4825accc2c3dbfaf7023a091b /browserenv.go
parent8d4c2f66ce0998f39f0dda1986afd0cc641a7dc1 (diff)
downloadbrowserenv-5933a5ae5fd8decf70e1e49bc2d877441f0e4479.tar.bz2
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.
Diffstat (limited to 'browserenv.go')
-rw-r--r--browserenv.go13
1 files changed, 13 insertions, 0 deletions
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
+}