Skip to content

Commit 22bcbe7

Browse files
committed
feat: experimental gopher full-text search support
Closes: https://todo.sr.ht/~hedy/gelim/40
1 parent eede8de commit 22bcbe7

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

client.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,13 @@ func (c *Client) Input(u string, sensitive bool) (ok bool) {
448448
c.style.ErrorMsg("Error reading input: " + err.Error())
449449
return false
450450
}
451-
u = u + "?" + queryEscape(query)
451+
if strings.HasPrefix(u, "gopher://") {
452+
// Crude, but works because gopher URLs are fully formed when saved in
453+
// c.links.
454+
u = u + "%09" + queryEscape(query)
455+
} else {
456+
u = u + "?" + queryEscape(query)
457+
}
452458
return c.HandleURLWrapper(u)
453459
}
454460

@@ -722,9 +728,10 @@ func (c *Client) HandleGopherParsedURL(parsed *url.URL) bool {
722728

723729
page.bodyBytes = bodyBytes
724730

725-
// TODO: check file extension
726731
if res.gophertype == "1" {
727732
page.mediaType = "gophermap"
733+
} else if res.gophertype == "7" {
734+
page.mediaType = "gophermap"
728735
} else {
729736
// Assume plain text for now
730737
page.mediaType = "text/plain"

cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ Examples:
288288
continue
289289
}
290290
link, _ := c.GetLinkFromIndex(index)
291-
fmt.Println(index, link) // TODO: also save the label in c.links
291+
fmt.Println(index, link)
292292
}
293293
},
294294
help: `[<index>...] : peek what a link index would link to, or see the list of all links

gelim.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,12 @@ func main() {
245245
c.style.ErrorMsg("No history yet, cannot use link indexing")
246246
continue
247247
}
248-
u, spartanInput := c.GetLinkFromIndex(index)
248+
u, isInput := c.GetLinkFromIndex(index)
249249
if u == "" {
250-
// TODO: When is this reached? Add message?
250+
c.style.ErrorMsg("Empty URL for this input link!")
251251
continue
252252
}
253-
if spartanInput {
253+
if isInput {
254254
c.Input(u, false)
255255
continue
256256
}

gopher.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ func (c *Client) ParseGophermap(page *Page) string {
115115
} else {
116116
link = fmt.Sprintf("gopher://%s:%s/h%s", host, port, path)
117117
}
118+
case "7":
119+
c.inputLinks = append(c.inputLinks, len(c.links))
118120
}
119121
c.links = append(c.links, link)
120122
gophertype := "(" + getGophertype(string(columns[0][0])) + ")"

0 commit comments

Comments
 (0)