1
0
mirror of https://github.com/makew0rld/amfora.git synced 2024-12-04 14:46:29 -05:00

renderer -> render

This commit is contained in:
makeworld 2021-03-01 15:35:47 -05:00
parent 00ab2f4542
commit 8f216f569b
9 changed files with 27 additions and 27 deletions

View File

@ -3,7 +3,7 @@ package display
import (
"fmt"
"github.com/makeworld-the-better-one/amfora/renderer"
"github.com/makeworld-the-better-one/amfora/render"
"github.com/makeworld-the-better-one/amfora/structs"
)
@ -34,7 +34,7 @@ func aboutInit(version, commit, builtBy string) {
}
func createAboutPage(url string, content string) structs.Page {
renderContent, links := renderer.RenderGemini(content, textWidth(), false)
renderContent, links := render.RenderGemini(content, textWidth(), false)
return structs.Page{
Raw: content,
Content: renderContent,

View File

@ -6,7 +6,7 @@ import (
"github.com/gdamore/tcell/v2"
"github.com/makeworld-the-better-one/amfora/bookmarks"
"github.com/makeworld-the-better-one/amfora/config"
"github.com/makeworld-the-better-one/amfora/renderer"
"github.com/makeworld-the-better-one/amfora/render"
"github.com/makeworld-the-better-one/amfora/structs"
"github.com/spf13/viper"
"gitlab.com/tslocum/cview"
@ -132,7 +132,7 @@ func Bookmarks(t *tab) {
bkmkPageRaw += fmt.Sprintf("=> %s %s\r\n", keys[i], m[keys[i]])
}
// Render and display
content, links := renderer.RenderGemini(bkmkPageRaw, textWidth(), false)
content, links := render.RenderGemini(bkmkPageRaw, textWidth(), false)
page := structs.Page{
Raw: bkmkPageRaw,
Content: content,

View File

@ -11,7 +11,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/renderer"
"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"
@ -249,7 +249,7 @@ func Init(version, commit, builtBy string) {
// Render the default new tab content ONCE and store it for later
// This code is repeated in Reload()
newTabContent := getNewTabContent()
renderedNewTabContent, newTabLinks := renderer.RenderGemini(newTabContent, textWidth(), false)
renderedNewTabContent, newTabLinks := render.RenderGemini(newTabContent, textWidth(), false)
newTabPage = structs.Page{
Raw: newTabContent,
Content: renderedNewTabContent,
@ -531,7 +531,7 @@ func Reload() {
// Re-render new tab, similar to Init()
newTabContent := getNewTabContent()
tmpTermW := termW
renderedNewTabContent, newTabLinks := renderer.RenderGemini(newTabContent, textWidth(), false)
renderedNewTabContent, newTabLinks := render.RenderGemini(newTabContent, textWidth(), false)
newTabPage = structs.Page{
Raw: newTabContent,
Content: renderedNewTabContent,

View File

@ -9,7 +9,7 @@ import (
"path/filepath"
"strings"
"github.com/makeworld-the-better-one/amfora/renderer"
"github.com/makeworld-the-better-one/amfora/render"
"github.com/makeworld-the-better-one/amfora/structs"
"github.com/spf13/viper"
)
@ -59,7 +59,7 @@ func handleFile(u string) (*structs.Page, bool) {
}
if mimetype == "text/gemini" {
rendered, links := renderer.RenderGemini(string(content), textWidth(), false)
rendered, links := render.RenderGemini(string(content), textWidth(), false)
page = &structs.Page{
Mediatype: structs.TextGemini,
URL: u,
@ -73,7 +73,7 @@ func handleFile(u string) (*structs.Page, bool) {
Mediatype: structs.TextPlain,
URL: u,
Raw: string(content),
Content: renderer.RenderPlainText(string(content)),
Content: render.RenderPlainText(string(content)),
Links: []string{},
TermWidth: termW,
}
@ -107,7 +107,7 @@ func createDirectoryListing(u string) (*structs.Page, bool) {
content += fmt.Sprintf("=> %s%s %s%s\n", f.Name(), separator, f.Name(), separator)
}
rendered, links := renderer.RenderGemini(content, textWidth(), false)
rendered, links := render.RenderGemini(content, textWidth(), false)
page = &structs.Page{
Mediatype: structs.TextGemini,
URL: u,

View File

@ -12,7 +12,7 @@ import (
"github.com/makeworld-the-better-one/amfora/cache"
"github.com/makeworld-the-better-one/amfora/client"
"github.com/makeworld-the-better-one/amfora/config"
"github.com/makeworld-the-better-one/amfora/renderer"
"github.com/makeworld-the-better-one/amfora/render"
"github.com/makeworld-the-better-one/amfora/rr"
"github.com/makeworld-the-better-one/amfora/structs"
"github.com/makeworld-the-better-one/amfora/subscriptions"
@ -309,14 +309,14 @@ func handleURL(t *tab, u string, numRedirects int) (string, bool) {
// Fetch happened successfully, use RestartReader to buffer read data
res.Body = rr.NewRestartReader(res.Body)
if renderer.CanDisplay(res) {
page, err := renderer.MakePage(u, res, textWidth(), usingProxy)
if render.CanDisplay(res) {
page, err := render.MakePage(u, res, textWidth(), usingProxy)
// Rendering may have taken a while, make sure tab is still valid
if !isValidTab(t) {
return ret("", false)
}
if errors.Is(err, renderer.ErrTooLarge) {
if errors.Is(err, render.ErrTooLarge) {
// Downloading now
// Disable read timeout and go back to start
res.SetReadTimeout(0) //nolint: errcheck
@ -324,7 +324,7 @@ func handleURL(t *tab, u string, numRedirects int) (string, bool) {
go dlChoice("That page is too large. What would you like to do?", u, res)
return ret("", false)
}
if errors.Is(err, renderer.ErrTimedOut) {
if errors.Is(err, render.ErrTimedOut) {
// Downloading now
// Disable read timeout and go back to start
res.SetReadTimeout(0) //nolint: errcheck

View File

@ -5,7 +5,7 @@ import (
"strconv"
"strings"
"github.com/makeworld-the-better-one/amfora/renderer"
"github.com/makeworld-the-better-one/amfora/render"
"github.com/makeworld-the-better-one/amfora/structs"
)
@ -52,7 +52,7 @@ func reformatPage(p *structs.Page) {
return
}
// TODO: Setup a renderer.RenderFromMediatype func so this isn't needed
// TODO: Setup a render.RenderFromMediatype func so this isn't needed
var rendered string
switch p.Mediatype {
@ -64,11 +64,11 @@ func reformatPage(p *structs.Page) {
strings.HasPrefix(p.URL, "file") {
proxied = false
}
rendered, _ = renderer.RenderGemini(p.Raw, textWidth(), proxied)
rendered, _ = render.RenderGemini(p.Raw, textWidth(), proxied)
case structs.TextPlain:
rendered = renderer.RenderPlainText(p.Raw)
rendered = render.RenderPlainText(p.Raw)
case structs.TextAnsi:
rendered = renderer.RenderANSI(p.Raw)
rendered = render.RenderANSI(p.Raw)
default:
// Rendering this type is not implemented
return

View File

@ -12,7 +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/renderer"
"github.com/makeworld-the-better-one/amfora/render"
"github.com/makeworld-the-better-one/amfora/structs"
"github.com/makeworld-the-better-one/amfora/subscriptions"
"github.com/makeworld-the-better-one/go-gemini"
@ -149,7 +149,7 @@ func Subscriptions(t *tab, u string) string {
}
}
content, links := renderer.RenderGemini(rawPage, textWidth(), false)
content, links := render.RenderGemini(rawPage, textWidth(), false)
page := structs.Page{
Raw: rawPage,
Content: content,
@ -191,7 +191,7 @@ func ManageSubscriptions(t *tab, u string) {
)
}
content, links := renderer.RenderGemini(rawPage, textWidth(), false)
content, links := render.RenderGemini(rawPage, textWidth(), false)
page := structs.Page{
Raw: rawPage,
Content: content,

View File

@ -1,4 +1,4 @@
package renderer
package render
import (
"bytes"

View File

@ -1,8 +1,8 @@
// Package renderer provides functions to convert various data into a cview primitive.
// Package render provides functions to convert various data into a cview primitive.
// Example objects include a Gemini response, and an error.
//
// Rendered lines always end with \r\n, in an effort to be Window compatible.
package renderer
package render
import (
"fmt"