forked from sloum/bombadillo
Added ability to view a link's url with the check command
This commit is contained in:
parent
21fe5714a3
commit
8a3ddad58e
|
@ -1 +1,2 @@
|
||||||
bombadillo
|
bombadillo
|
||||||
|
*.asciinema
|
||||||
|
|
30
client.go
30
client.go
|
@ -386,16 +386,19 @@ func (c *client) doLinkCommandAs(action, target string, values []string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
switch action {
|
switch action {
|
||||||
case "ADD", "A":
|
case "ADD", "A":
|
||||||
links := c.PageState.History[c.PageState.Position].Links
|
|
||||||
if num >= len(links) {
|
|
||||||
c.SetMessage(fmt.Sprintf("Invalid link id: %s", target), true)
|
|
||||||
c.DrawMessage()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
bm := make([]string, 0, 5)
|
bm := make([]string, 0, 5)
|
||||||
bm = append(bm, links[num-1])
|
bm = append(bm, links[num])
|
||||||
bm = append(bm, values...)
|
bm = append(bm, values...)
|
||||||
msg, err := c.BookMarks.Add(bm)
|
msg, err := c.BookMarks.Add(bm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -455,6 +458,7 @@ func (c *client) doLinkCommand(action, target string) {
|
||||||
c.DrawMessage()
|
c.DrawMessage()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch action {
|
switch action {
|
||||||
case "DELETE", "D":
|
case "DELETE", "D":
|
||||||
msg, err := c.BookMarks.Delete(num)
|
msg, err := c.BookMarks.Delete(num)
|
||||||
|
@ -482,6 +486,18 @@ func (c *client) doLinkCommand(action, target string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.Visit(c.BookMarks.Links[num])
|
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:
|
default:
|
||||||
c.SetMessage(fmt.Sprintf("Action %q does not exist for target %q", action, target), true)
|
c.SetMessage(fmt.Sprintf("Action %q does not exist for target %q", action, target), true)
|
||||||
c.DrawMessage()
|
c.DrawMessage()
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue