diff --git a/amfora.go b/amfora.go index 2f5f0ec..ab9fbe1 100644 --- a/amfora.go +++ b/amfora.go @@ -1,10 +1,10 @@ package main import ( + "bytes" "fmt" "io" "os" - "strings" "github.com/makeworld-the-better-one/amfora/bookmarks" "github.com/makeworld-the-better-one/amfora/client" @@ -86,13 +86,12 @@ func isStdinEmpty() bool { } func renderFromStdin() { - stdinTextBuilder := new(strings.Builder) - _, err := io.Copy(stdinTextBuilder, os.Stdin) + var stdinTextBuilder bytes.Buffer + _, err := io.Copy(&stdinTextBuilder, os.Stdin) if err != nil { fmt.Fprintf(os.Stderr, "error reading from standard input: %v\n", err) os.Exit(1) } - stdinText := stdinTextBuilder.String() - display.RenderFromString(stdinText) + display.RenderFromBytes(stdinTextBuilder.Bytes()) } diff --git a/display/display.go b/display/display.go index 25f7d3e..32dd13a 100644 --- a/display/display.go +++ b/display/display.go @@ -12,6 +12,7 @@ import ( "github.com/gdamore/tcell/v2" "github.com/makeworld-the-better-one/amfora/cache" "github.com/makeworld-the-better-one/amfora/config" + "github.com/makeworld-the-better-one/amfora/render" "github.com/makeworld-the-better-one/amfora/structs" "github.com/makeworld-the-better-one/go-gemini" "github.com/spf13/viper" @@ -522,17 +523,17 @@ func URL(u string) { go t.goURL(fixUserURL(u)) } -func RenderFromString(str string) { +func RenderFromBytes(b []byte) { t := tabs[curTab] - page, _ := renderPageFromString(str) - setPage(t, page) + page, _ := renderPageFromBytes(b) + t.setPage(page) } -func renderPageFromString(str string) (*structs.Page, bool) { - rendered, links := renderer.RenderGemini(str, textWidth(), false) +func renderPageFromBytes(b []byte) (*structs.Page, bool) { + rendered, links := render.RenderGemini(b, textWidth(), false) page := &structs.Page{ Mediatype: structs.TextGemini, - Raw: str, + Raw: b, Content: rendered, Links: links, TermWidth: termW, diff --git a/display/tab.go b/display/tab.go index 7253846..fb26bfb 100644 --- a/display/tab.go +++ b/display/tab.go @@ -430,11 +430,11 @@ func (t *tab) applyAll() { // HighlightedURL returns the currently selected URL func (t *tab) HighlightedURL() string { - currentSelection := tabs[curTab].view.GetHighlights() + currentSelection := t.view.GetHighlights() if len(currentSelection) > 0 { linkN, _ := strconv.Atoi(currentSelection[0]) - selectedURL := tabs[curTab].page.Links[linkN] + selectedURL := t.page.Links[linkN] return selectedURL } return ""