Added ability to view a link's url with the check command

This commit is contained in:
sloumdrone 2019-09-17 21:57:21 -07:00
parent 21fe5714a3
commit 8a3ddad58e
3 changed files with 107 additions and 7 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
bombadillo
*.asciinema

View File

@ -386,16 +386,19 @@ func (c *client) doLinkCommandAs(action, target string, values []string) {
return
}
switch action {
case "ADD", "A":
num -= 1
links := c.PageState.History[c.PageState.Position].Links
if num >= len(links) {
if num >= len(links) || num < 0 {
c.SetMessage(fmt.Sprintf("Invalid link id: %s", target), true)
c.DrawMessage()
return
}
switch action {
case "ADD", "A":
bm := make([]string, 0, 5)
bm = append(bm, links[num-1])
bm = append(bm, links[num])
bm = append(bm, values...)
msg, err := c.BookMarks.Add(bm)
if err != nil {
@ -455,6 +458,7 @@ func (c *client) doLinkCommand(action, target string) {
c.DrawMessage()
}
switch action {
case "DELETE", "D":
msg, err := c.BookMarks.Delete(num)
@ -482,6 +486,18 @@ func (c *client) doLinkCommand(action, target string) {
return
}
c.Visit(c.BookMarks.Links[num])
case "CHECK", "C":
num -= 1
links := c.PageState.History[c.PageState.Position].Links
if num >= len(links) || num < 0 {
c.SetMessage(fmt.Sprintf("Invalid link id: %s", target), true)
c.DrawMessage()
return
}
link := links[num]
c.SetMessage(fmt.Sprintf("[%d] %s", num + 1, link), false)
c.DrawMessage()
default:
c.SetMessage(fmt.Sprintf("Action %q does not exist for target %q", action, target), true)
c.DrawMessage()

83
gemini/gemini.go Normal file
View File

@ -0,0 +1,83 @@
package gemini
import (
"crypto/tls"
"fmt"
"net"
"io/ioutil"
// "strings"
"time"
// "tildegit.org/sloum/mailcap"
)
//------------------------------------------------\\
// + + + F U N C T I O N S + + + \\
//--------------------------------------------------\\
func Retrieve(host, port, resource string) ([]byte, error) {
nullRes := make([]byte, 0)
timeOut := time.Duration(5) * time.Second
if host == "" || port == "" {
return nullRes, fmt.Errorf("Incomplete request url")
}
addr := host + ":" + port
conf := &tls.Config{
InsecureSkipVerify: true,
}
conn, err := net.DialTimeout("tcp", addr, timeOut)
if err != nil {
return nullRes, err
}
secureConn := tls.Client(conn, conf)
send := resource + "\n"
_, err = secureConn.Write([]byte(send))
if err != nil {
return nullRes, err
}
result, err := ioutil.ReadAll(conn)
if err != nil {
return nullRes, err
}
return result, nil
}
func Visit(host, port, resource string) (string, []string, error) {
resp, err := Retrieve(host, port, resource)
if err != nil {
return "", []string{}, err
}
// TODO break out the header
// header := ""
mime := ""
mimeMaj := mime
mimeMin := mime
// status := ""
content := string(resp)
if mimeMaj == "text" && mimeMin == "gemini" {
// text := string(resp)
// links := []string{}
// TODO parse geminimap from 'content'
} else if mimeMaj == "text" {
// TODO just return the text
} else {
// TODO use mailcap to try and open the file
}
return content, []string{}, nil
}