Develop -> Master #172
10
Makefile
10
Makefile
|
@ -14,7 +14,7 @@ test : GOCMD := go1.11.13
|
||||||
BUILD_TIME := ${shell date "+%Y-%m-%dT%H:%M%z"}
|
BUILD_TIME := ${shell date "+%Y-%m-%dT%H:%M%z"}
|
||||||
|
|
||||||
# If VERSION is empty or not defined use the contents of the VERSION file
|
# If VERSION is empty or not defined use the contents of the VERSION file
|
||||||
VERSION := ${shell git describe --tags 2> /dev/null}
|
VERSION := ${shell git describe --exact-match 2> /dev/null}
|
||||||
ifndef VERSION
|
ifndef VERSION
|
||||||
VERSION := ${shell cat ./VERSION}
|
VERSION := ${shell cat ./VERSION}
|
||||||
endif
|
endif
|
||||||
|
@ -57,6 +57,7 @@ install-bin: build
|
||||||
clean:
|
clean:
|
||||||
${GOCMD} clean
|
${GOCMD} clean
|
||||||
rm -f ./bombadillo.1.gz 2> /dev/null
|
rm -f ./bombadillo.1.gz 2> /dev/null
|
||||||
|
rm -f ./${BINARY}_* 2> /dev/null
|
||||||
|
|
||||||
.PHONY: uninstall
|
.PHONY: uninstall
|
||||||
uninstall: clean
|
uninstall: clean
|
||||||
|
@ -66,6 +67,13 @@ uninstall: clean
|
||||||
rm -f ${DESTDIR}${DATAROOTDIR}/pixmaps/bombadillo-icon.png
|
rm -f ${DESTDIR}${DATAROOTDIR}/pixmaps/bombadillo-icon.png
|
||||||
-update-desktop-database 2> /dev/null
|
-update-desktop-database 2> /dev/null
|
||||||
|
|
||||||
|
.PHONY: release
|
||||||
|
release:
|
||||||
|
GOOS=linux GOARCH=amd64 ${GOCMD} build ${LDFLAGS} -o ${BINARY}_linux_64
|
||||||
|
GOOS=linux GOARCH=arm ${GOCMD} build ${LDFLAGS} -o ${BINARY}_linux_arm
|
||||||
|
GOOS=linux GOARCH=386 ${GOCMD} build ${LDFLAGS} -o ${BINARY}_linux_32
|
||||||
|
GOOS=darwin GOARCH=amd64 ${GOCMD} build ${LDFLAGS} -o ${BINARY}_darwin_64
|
||||||
|
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: clean build
|
test: clean build
|
||||||
|
|
|
@ -27,6 +27,7 @@ These instructions will get a copy of the project up and running on your local m
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
|
|
||||||
You will need to have [Go](https://golang.org/) version >= 1.11.
|
You will need to have [Go](https://golang.org/) version >= 1.11.
|
||||||
|
To use the Makefile you will need a make that is GNU Make compatible (sorry BSD folks)
|
||||||
|
|
||||||
### Building, Installing, Uninstalling
|
### Building, Installing, Uninstalling
|
||||||
|
|
||||||
|
|
19
client.go
19
client.go
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -121,15 +122,11 @@ func (c *client) Draw() {
|
||||||
} else {
|
} else {
|
||||||
for i := 0; i < c.Height-3; i++ {
|
for i := 0; i < c.Height-3; i++ {
|
||||||
if i < len(pageContent) {
|
if i < len(pageContent) {
|
||||||
extra := 0
|
screen.WriteString(pageContent[i])
|
||||||
escapes := re.FindAllString(pageContent[i], -1)
|
screen.WriteString("\033[0K")
|
||||||
for _, esc := range escapes {
|
|
||||||
extra += len(esc)
|
|
||||||
}
|
|
||||||
screen.WriteString(fmt.Sprintf("%-*.*s", c.Width+extra, c.Width+extra, pageContent[i]))
|
|
||||||
screen.WriteString("\n")
|
screen.WriteString("\n")
|
||||||
} else {
|
} else {
|
||||||
screen.WriteString(fmt.Sprintf("%-*.*s", c.Width, c.Width, " "))
|
screen.WriteString("\033[0K")
|
||||||
screen.WriteString("\n")
|
screen.WriteString("\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -700,20 +697,20 @@ func (c *client) search(query, uri, question string) {
|
||||||
var rootUrl string
|
var rootUrl string
|
||||||
switch u.Scheme {
|
switch u.Scheme {
|
||||||
case "gopher":
|
case "gopher":
|
||||||
if ind := strings.Index(entry, "\t"); ind >= 0 {
|
if ind := strings.Index(u.Full, "\t"); ind >= 0 {
|
||||||
rootUrl = u.Full[:ind]
|
rootUrl = u.Full[:ind]
|
||||||
} else {
|
} else {
|
||||||
rootUrl = u.Full
|
rootUrl = u.Full
|
||||||
}
|
}
|
||||||
c.Visit(fmt.Sprintf("%s\t%s", rootUrl, entry))
|
c.Visit(fmt.Sprintf("%s\t%s", rootUrl, entry))
|
||||||
case "gemini":
|
case "gemini":
|
||||||
if ind := strings.Index(entry, "?"); ind >= 0 {
|
if ind := strings.Index(u.Full, "?"); ind >= 0 {
|
||||||
rootUrl = u.Full[:ind]
|
rootUrl = u.Full[:ind]
|
||||||
} else {
|
} else {
|
||||||
rootUrl = u.Full
|
rootUrl = u.Full
|
||||||
}
|
}
|
||||||
// escapedEntry := url.QueryEscape(entry) // TODO confirm expected behavior re: escaping
|
escapedEntry := url.PathEscape(entry)
|
||||||
c.Visit(fmt.Sprintf("%s?%s", rootUrl, entry))
|
c.Visit(fmt.Sprintf("%s?%s", rootUrl, escapedEntry))
|
||||||
case "http", "https":
|
case "http", "https":
|
||||||
c.Visit(u.Full)
|
c.Visit(u.Full)
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -343,8 +344,7 @@ func Visit(host, port, resource string, td *TofuDigest) (Capsule, error) {
|
||||||
resource = "/"
|
resource = "/"
|
||||||
}
|
}
|
||||||
currentUrl := fmt.Sprintf("gemini://%s:%s%s", host, port, resource)
|
currentUrl := fmt.Sprintf("gemini://%s:%s%s", host, port, resource)
|
||||||
rootUrl := fmt.Sprintf("gemini://%s:%s", host, port)
|
capsule.Content, capsule.Links = parseGemini(body, currentUrl)
|
||||||
capsule.Content, capsule.Links = parseGemini(body, rootUrl, currentUrl)
|
|
||||||
} else {
|
} else {
|
||||||
capsule.Content = body
|
capsule.Content = body
|
||||||
}
|
}
|
||||||
|
@ -365,7 +365,7 @@ func Visit(host, port, resource string, td *TofuDigest) (Capsule, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseGemini(b, rootUrl, currentUrl string) (string, []string) {
|
func parseGemini(b, currentUrl string) (string, []string) {
|
||||||
splitContent := strings.Split(b, "\n")
|
splitContent := strings.Split(b, "\n")
|
||||||
links := make([]string, 0, 10)
|
links := make([]string, 0, 10)
|
||||||
|
|
||||||
|
@ -399,7 +399,7 @@ func parseGemini(b, rootUrl, currentUrl string) (string, []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.Index(link, "://") < 0 {
|
if strings.Index(link, "://") < 0 {
|
||||||
link = handleRelativeUrl(link, rootUrl, currentUrl)
|
link, _ = handleRelativeUrl(link, currentUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
links = append(links, link)
|
links = append(links, link)
|
||||||
|
@ -417,42 +417,17 @@ func parseGemini(b, rootUrl, currentUrl string) (string, []string) {
|
||||||
return strings.Join(splitContent[:outputIndex], "\n"), links
|
return strings.Join(splitContent[:outputIndex], "\n"), links
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleRelativeUrl(u, root, current string) string {
|
// handleRelativeUrl provides link completion
|
||||||
if len(u) < 1 {
|
func handleRelativeUrl(relLink, current string) (string, error) {
|
||||||
return u
|
base, err := url.Parse(current)
|
||||||
|
if err != nil {
|
||||||
|
return relLink, err
|
||||||
}
|
}
|
||||||
currentIsDir := (current[len(current)-1] == '/')
|
rel, err := url.Parse(relLink)
|
||||||
|
if err != nil {
|
||||||
if u[0] == '/' {
|
return relLink, err
|
||||||
return fmt.Sprintf("%s%s", root, u)
|
|
||||||
} else if strings.HasPrefix(u, "../") {
|
|
||||||
currentDir := strings.LastIndex(current, "/")
|
|
||||||
if currentIsDir {
|
|
||||||
upOne := strings.LastIndex(current[:currentDir], "/")
|
|
||||||
dirRoot := current[:upOne]
|
|
||||||
return dirRoot + u[2:]
|
|
||||||
}
|
|
||||||
return current[:currentDir] + u[2:]
|
|
||||||
}
|
}
|
||||||
|
return base.ResolveReference(rel).String(), nil
|
||||||
if strings.HasPrefix(u, "./") {
|
|
||||||
if len(u) == 2 {
|
|
||||||
return current
|
|
||||||
}
|
|
||||||
u = u[2:]
|
|
||||||
}
|
|
||||||
|
|
||||||
if currentIsDir {
|
|
||||||
indPrevDir := strings.LastIndex(current[:len(current)-1], "/")
|
|
||||||
if indPrevDir < 9 {
|
|
||||||
return current + u
|
|
||||||
}
|
|
||||||
return current[:indPrevDir+1] + u
|
|
||||||
}
|
|
||||||
|
|
||||||
ind := strings.LastIndex(current, "/")
|
|
||||||
current = current[:ind+1]
|
|
||||||
return current + u
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func hashCert(cert []byte) string {
|
func hashCert(cert []byte) string {
|
||||||
|
|
Loading…
Reference in New Issue