change openBrowser to use conditional compilation rather than a runtime switch
This commit is contained in:
parent
288e1acf62
commit
ee0f2e3e9b
|
@ -163,5 +163,8 @@ func HandleAlternateScreen(opt string) {
|
||||||
cmd := exec.Command("tput", opt)
|
cmd := exec.Command("tput", opt)
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Run()
|
err := cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,3 @@ func (b Bookmarks) IniDump() string {
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeBookmarks() Bookmarks {
|
|
||||||
return Bookmarks{[]string{}, []string{}}
|
|
||||||
}
|
|
||||||
|
|
|
@ -8,8 +8,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"os/exec"
|
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -90,10 +88,11 @@ func Visit(addr, openhttp string) (View, error) {
|
||||||
|
|
||||||
if u.Gophertype == "h" {
|
if u.Gophertype == "h" {
|
||||||
if res, tf := isWebLink(u.Resource); tf && strings.ToUpper(openhttp) == "TRUE" {
|
if res, tf := isWebLink(u.Resource); tf && strings.ToUpper(openhttp) == "TRUE" {
|
||||||
err := openbrowser(res)
|
err := openBrowser(res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return View{}, err
|
return View{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return View{}, fmt.Errorf("")
|
return View{}, fmt.Errorf("")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,12 +112,12 @@ func Visit(addr, openhttp string) (View, error) {
|
||||||
return MakeView(u, pageContent), nil
|
return MakeView(u, pageContent), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetType(t string) string {
|
func getType(t string) string {
|
||||||
if val, ok := types[t]; ok {
|
if val, ok := types[t]; ok {
|
||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
return "???"
|
|
||||||
|
|
||||||
|
return "???"
|
||||||
}
|
}
|
||||||
|
|
||||||
func isWebLink(resource string) (string, bool) {
|
func isWebLink(resource string) (string, bool) {
|
||||||
|
@ -128,24 +127,3 @@ func isWebLink(resource string) (string, bool) {
|
||||||
}
|
}
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
func openbrowser(url string) error {
|
|
||||||
// gist.github.com/hyg/9c4afcd91fe24316cbf0
|
|
||||||
var err error
|
|
||||||
|
|
||||||
switch runtime.GOOS {
|
|
||||||
case "linux":
|
|
||||||
err = exec.Command("xdg-open", url).Start()
|
|
||||||
case "windows":
|
|
||||||
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
|
|
||||||
case "darwin":
|
|
||||||
err = exec.Command("open", url).Start()
|
|
||||||
default:
|
|
||||||
err = fmt.Errorf("Unsupported os for browser detection")
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
// +build darwin
|
||||||
|
|
||||||
|
package gopher
|
||||||
|
|
||||||
|
import "os/exec"
|
||||||
|
|
||||||
|
func openBrowser(url string) error {
|
||||||
|
return exec.Command("open", url).Start()
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
// +build linux
|
||||||
|
|
||||||
|
package gopher
|
||||||
|
|
||||||
|
import "os/exec"
|
||||||
|
|
||||||
|
func openBrowser(url string) error {
|
||||||
|
return exec.Command("xdg-open", url).Start()
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
// +build !linux
|
||||||
|
// +build !darwin
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package gopher
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func openBrowser(url string) error {
|
||||||
|
return fmt.Errorf("Unsupported os for browser detection")
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
// +build windows
|
||||||
|
|
||||||
|
package gopher
|
||||||
|
|
||||||
|
import "os/exec"
|
||||||
|
|
||||||
|
func openBrowser(url string) error {
|
||||||
|
return exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
|
||||||
|
}
|
|
@ -57,13 +57,15 @@ func MakeUrl(u string) (Url, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if out.Host == "" {
|
if out.Host == "" {
|
||||||
return out, errors.New("No host.")
|
return out, errors.New("no host")
|
||||||
}
|
}
|
||||||
|
|
||||||
if out.Scheme == "gopher" && out.Port == "" {
|
if out.Scheme == "gopher" && out.Port == "" {
|
||||||
out.Port = "70"
|
out.Port = "70"
|
||||||
} else if out.Scheme == "http" || out.Scheme == "https" && out.Port == "" {
|
} else if out.Scheme == "http" && out.Port == "" {
|
||||||
out.Port = "80"
|
out.Port = "80"
|
||||||
|
} else if out.Scheme == "https" && out.Port == "" {
|
||||||
|
out.Port = "443"
|
||||||
}
|
}
|
||||||
|
|
||||||
if out.Gophertype == "" && (out.Resource == "" || out.Resource == "/") {
|
if out.Gophertype == "" && (out.Resource == "" || out.Resource == "/") {
|
||||||
|
|
|
@ -52,7 +52,7 @@ func (v *View) ParseMap() {
|
||||||
} else if len(line) >= 4 {
|
} else if len(line) >= 4 {
|
||||||
fulllink := fmt.Sprintf("%s:%s/%s%s", line[2], line[3], string(line[0][0]), line[1])
|
fulllink := fmt.Sprintf("%s:%s/%s%s", line[2], line[3], string(line[0][0]), line[1])
|
||||||
v.Links = append(v.Links, fulllink)
|
v.Links = append(v.Links, fulllink)
|
||||||
linktext := fmt.Sprintf("(%s) %2d %s", GetType(string(line[0][0])), len(v.Links), title)
|
linktext := fmt.Sprintf("(%s) %2d %s", getType(string(line[0][0])), len(v.Links), title)
|
||||||
v.Content[i] = linktext
|
v.Content[i] = linktext
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue