Skip to content

Commit 8607d46

Browse files
committed
Open the browser to the web ui on start
1 parent 572d5ae commit 8607d46

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pkg/renderer/web.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"fmt"
66
"log"
77
"net/http"
8+
"os/exec"
9+
"runtime"
810
"sync"
911
"time"
1012

@@ -53,6 +55,7 @@ func (web *Web) Start(wg *sync.WaitGroup, rp chan protocol.RequestPayload, q cha
5355
defer wg.Done()
5456

5557
go func() {
58+
open(fmt.Sprintf("http://%s/", addr))
5659
err := srv.ListenAndServe()
5760
str := pterm.Error.WithShowLineNumber(false).Sprintf("Web: %s\n", err)
5861
pterm.Printo(str) // Overwrite last line
@@ -139,3 +142,22 @@ func (e *httpErrorLog) Write(b []byte) (n int, err error) {
139142
pterm.Error.WithShowLineNumber(false).Println(string(b))
140143
return len(b), nil
141144
}
145+
146+
// open opens the terminal to the web UI.
147+
// https://stackoverflow.com/a/39324149
148+
func open(url string) error {
149+
var cmd string
150+
var args []string
151+
152+
switch runtime.GOOS {
153+
case "windows":
154+
cmd = "cmd"
155+
args = []string{"/c", "start"}
156+
case "darwin":
157+
cmd = "open"
158+
default: // "linux", "freebsd", "openbsd", "netbsd"
159+
cmd = "xdg-open"
160+
}
161+
args = append(args, url)
162+
return exec.Command(cmd, args...).Start()
163+
}

0 commit comments

Comments
 (0)