Adds web support in lynx mode
This commit is contained in:
parent
cc27c82703
commit
552e211139
|
@ -215,8 +215,13 @@ homeurl
|
|||
The url that \fBbombadillo\fP navigates to when the program loads or when the \fIhome\fP or \fIh\fP LINE COMMAND is issued. This should be a valid url. If a scheme/protocol is not included, gopher will be assumed.
|
||||
.TP
|
||||
.B
|
||||
lynxmode
|
||||
Will use lynx as a rendering engine for http/https requests if lynx is installed and \fIopenhttp\fP is set to \fItrue\fP. Valid values are \fItrue\fP and \fIfalse\fP.
|
||||
.TP
|
||||
.B
|
||||
openhttp
|
||||
Tells the client whether or not to try to follow web (http/https) links. If set to \fItrue\fP, \fBbombadillo\fP will try to open a user's default web browser to the link in question. Any value other than \fItrue\fP is considered false.
|
||||
Tells the client whether or not to try to follow web (http/https) links. If set to \fItrue\fP, \fBbombadillo\fP will try to open a user's default web browser to the link in question. Valid values are \fItrue\fP and \fIfalse\fP.
|
||||
|
||||
.TP
|
||||
.B
|
||||
savelocation
|
||||
|
@ -232,7 +237,7 @@ Tells the client what command to use to start a telnet session. Should be a vali
|
|||
.TP
|
||||
.B
|
||||
terminalonly
|
||||
Sets whether or not to try to open non-text files served via gemini in gui programs or not. If set to \fItrue\fP, bombdaillo will only attempt to use terminal programs to open files. If set to anything else, \fBbombadillo\fP may choose from the appropriate programs installed on the system, if one is present.
|
||||
Sets whether or not to try to open non-text files served via gemini in gui programs or not. If set to \fItrue\fP \fBbombdaillo\fP will only attempt to use terminal programs to open files. If set to \fIfalse\fP \fBbombadillo\fP may choose from the appropriate programs installed on the system, including graphical ones.
|
||||
.TP
|
||||
.B
|
||||
theme
|
||||
|
|
44
client.go
44
client.go
|
@ -972,19 +972,41 @@ func (c *client) Visit(url string) {
|
|||
}
|
||||
c.Draw()
|
||||
case "http", "https":
|
||||
c.SetMessage("Attempting to open in web browser", false)
|
||||
c.DrawMessage()
|
||||
if strings.ToUpper(c.Options["openhttp"]) == "TRUE" {
|
||||
msg, err := http.OpenInBrowser(u.Full)
|
||||
if err != nil {
|
||||
c.SetMessage(err.Error(), true)
|
||||
} else {
|
||||
c.SetMessage(msg, false)
|
||||
}
|
||||
c.DrawMessage()
|
||||
} else {
|
||||
if strings.ToUpper(c.Options["openhttp"]) != "TRUE" {
|
||||
c.SetMessage("'openhttp' is not set to true, cannot open web link", false)
|
||||
c.DrawMessage()
|
||||
return
|
||||
}
|
||||
switch strings.ToUpper(c.Options["lynxmode"]) {
|
||||
case "TRUE":
|
||||
page, err := http.Visit(u.Full, c.Width - 1)
|
||||
if err != nil {
|
||||
c.SetMessage(fmt.Sprintf("Lynx error: %s", err.Error()), true)
|
||||
c.DrawMessage()
|
||||
return
|
||||
}
|
||||
pg := MakePage(u, page.Content, page.Links)
|
||||
pg.WrapContent(c.Width - 1)
|
||||
c.PageState.Add(pg)
|
||||
c.SetPercentRead()
|
||||
c.ClearMessage()
|
||||
c.SetHeaderUrl()
|
||||
c.Draw()
|
||||
default:
|
||||
if strings.ToUpper(c.Options["terminalonly"]) == "TRUE" {
|
||||
c.SetMessage("'terminalonly' is set to true and 'lynxmode' is not enabled, cannot open web link", false)
|
||||
c.DrawMessage()
|
||||
} else {
|
||||
c.SetMessage("Attempting to open in web browser", false)
|
||||
c.DrawMessage()
|
||||
msg, err := http.OpenInBrowser(u.Full)
|
||||
if err != nil {
|
||||
c.SetMessage(err.Error(), true)
|
||||
} else {
|
||||
c.SetMessage(msg, false)
|
||||
}
|
||||
c.DrawMessage()
|
||||
}
|
||||
}
|
||||
case "local":
|
||||
content, err := local.Open(u.Resource)
|
||||
|
|
|
@ -16,12 +16,12 @@ var defaultOptions = map[string]string{
|
|||
"savelocation": userinfo.HomeDir,
|
||||
"searchengine": "gopher://gopher.floodgap.com:70/7/v2/vs",
|
||||
"openhttp": "false",
|
||||
"httpbrowser": "lynx",
|
||||
"telnetcommand": "telnet",
|
||||
"configlocation": userinfo.HomeDir,
|
||||
"theme": "normal", // "normal", "inverted"
|
||||
"terminalonly": "true",
|
||||
"tlscertificate": "",
|
||||
"tlskey": "",
|
||||
"lynxmode": "false",
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
package http
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type page struct {
|
||||
Content string
|
||||
Links []string
|
||||
}
|
||||
|
||||
func Visit(url string, width int) (page, error) {
|
||||
if width > 80 {
|
||||
width = 80
|
||||
}
|
||||
w := fmt.Sprintf("-width=%d", width)
|
||||
c, err := exec.Command("lynx", "-dump", w, url).Output()
|
||||
if err != nil {
|
||||
return page{}, err
|
||||
}
|
||||
return parseLinks(string(c)), nil
|
||||
}
|
||||
|
||||
func parseLinks(c string) page {
|
||||
var out page
|
||||
contentUntil := strings.LastIndex(c, "References")
|
||||
if contentUntil >= 1 {
|
||||
out.Content = c[:contentUntil]
|
||||
} else {
|
||||
out.Content = c
|
||||
out.Links = make([]string, 0)
|
||||
return out
|
||||
}
|
||||
links := c[contentUntil+11:]
|
||||
links = strings.TrimSpace(links)
|
||||
linkSlice := strings.Split(links, "\n")
|
||||
out.Links = make([]string, 0, len(linkSlice))
|
||||
for _, link := range linkSlice {
|
||||
ls := strings.SplitN(link, ".", 2)
|
||||
if len(ls) < 2 {
|
||||
continue
|
||||
}
|
||||
out.Links = append(out.Links, strings.TrimSpace(ls[1]))
|
||||
}
|
||||
return out
|
||||
|
||||
}
|
4
main.go
4
main.go
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
// Bombadillo is a gopher and gemini client for the terminal of unix or unix-like systems.
|
||||
// Bombadillo is an internet client for the terminal of unix or
|
||||
// unix-like systems.
|
||||
//
|
||||
// Copyright (C) 2019 Brian Evans
|
||||
//
|
||||
|
@ -68,6 +69,7 @@ func validateOpt(opt, val string) bool {
|
|||
"openhttp": []string{"true", "false"},
|
||||
"theme": []string{"normal", "inverse"},
|
||||
"terminalonly": []string{"true", "false"},
|
||||
"lynxmode": []string{"true", "false"},
|
||||
}
|
||||
|
||||
opt = strings.ToLower(opt)
|
||||
|
|
Loading…
Reference in New Issue