mirror of
https://github.com/makew0rld/amfora.git
synced 2025-01-03 14:56:27 -05:00
Bring new master content in line with rendering updates
This commit is contained in:
parent
adb7b379cb
commit
08689a400f
@ -1,10 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/makeworld-the-better-one/amfora/bookmarks"
|
"github.com/makeworld-the-better-one/amfora/bookmarks"
|
||||||
"github.com/makeworld-the-better-one/amfora/client"
|
"github.com/makeworld-the-better-one/amfora/client"
|
||||||
@ -86,13 +86,12 @@ func isStdinEmpty() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func renderFromStdin() {
|
func renderFromStdin() {
|
||||||
stdinTextBuilder := new(strings.Builder)
|
var stdinTextBuilder bytes.Buffer
|
||||||
_, err := io.Copy(stdinTextBuilder, os.Stdin)
|
_, err := io.Copy(&stdinTextBuilder, os.Stdin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "error reading from standard input: %v\n", err)
|
fmt.Fprintf(os.Stderr, "error reading from standard input: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
stdinText := stdinTextBuilder.String()
|
display.RenderFromBytes(stdinTextBuilder.Bytes())
|
||||||
display.RenderFromString(stdinText)
|
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/gdamore/tcell/v2"
|
"github.com/gdamore/tcell/v2"
|
||||||
"github.com/makeworld-the-better-one/amfora/cache"
|
"github.com/makeworld-the-better-one/amfora/cache"
|
||||||
"github.com/makeworld-the-better-one/amfora/config"
|
"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/amfora/structs"
|
||||||
"github.com/makeworld-the-better-one/go-gemini"
|
"github.com/makeworld-the-better-one/go-gemini"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
@ -522,17 +523,17 @@ func URL(u string) {
|
|||||||
go t.goURL(fixUserURL(u))
|
go t.goURL(fixUserURL(u))
|
||||||
}
|
}
|
||||||
|
|
||||||
func RenderFromString(str string) {
|
func RenderFromBytes(b []byte) {
|
||||||
t := tabs[curTab]
|
t := tabs[curTab]
|
||||||
page, _ := renderPageFromString(str)
|
page, _ := renderPageFromBytes(b)
|
||||||
setPage(t, page)
|
t.setPage(page)
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderPageFromString(str string) (*structs.Page, bool) {
|
func renderPageFromBytes(b []byte) (*structs.Page, bool) {
|
||||||
rendered, links := renderer.RenderGemini(str, textWidth(), false)
|
rendered, links := render.RenderGemini(b, textWidth(), false)
|
||||||
page := &structs.Page{
|
page := &structs.Page{
|
||||||
Mediatype: structs.TextGemini,
|
Mediatype: structs.TextGemini,
|
||||||
Raw: str,
|
Raw: b,
|
||||||
Content: rendered,
|
Content: rendered,
|
||||||
Links: links,
|
Links: links,
|
||||||
TermWidth: termW,
|
TermWidth: termW,
|
||||||
|
@ -430,11 +430,11 @@ func (t *tab) applyAll() {
|
|||||||
|
|
||||||
// HighlightedURL returns the currently selected URL
|
// HighlightedURL returns the currently selected URL
|
||||||
func (t *tab) HighlightedURL() string {
|
func (t *tab) HighlightedURL() string {
|
||||||
currentSelection := tabs[curTab].view.GetHighlights()
|
currentSelection := t.view.GetHighlights()
|
||||||
|
|
||||||
if len(currentSelection) > 0 {
|
if len(currentSelection) > 0 {
|
||||||
linkN, _ := strconv.Atoi(currentSelection[0])
|
linkN, _ := strconv.Atoi(currentSelection[0])
|
||||||
selectedURL := tabs[curTab].page.Links[linkN]
|
selectedURL := t.page.Links[linkN]
|
||||||
return selectedURL
|
return selectedURL
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
|
Loading…
Reference in New Issue
Block a user