Browse Source

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

pull/40/head
sloumdrone 2 years ago
parent
commit
8a3ddad58e
  1. 1
      .gitignore
  2. 30
      client.go
  3. 83
      gemini/gemini.go

1
.gitignore

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

30
client.go

@ -386,16 +386,19 @@ func (c *client) doLinkCommandAs(action, target string, values []string) {
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 {
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 = 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

@ -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…
Cancel
Save