mirror of
https://github.com/makew0rld/amfora.git
synced 2024-12-04 14:46:29 -05:00
renderer -> render
This commit is contained in:
parent
00ab2f4542
commit
8f216f569b
@ -3,7 +3,7 @@ package display
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"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"
|
"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 {
|
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{
|
return structs.Page{
|
||||||
Raw: content,
|
Raw: content,
|
||||||
Content: renderContent,
|
Content: renderContent,
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/gdamore/tcell/v2"
|
"github.com/gdamore/tcell/v2"
|
||||||
"github.com/makeworld-the-better-one/amfora/bookmarks"
|
"github.com/makeworld-the-better-one/amfora/bookmarks"
|
||||||
"github.com/makeworld-the-better-one/amfora/config"
|
"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/structs"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"gitlab.com/tslocum/cview"
|
"gitlab.com/tslocum/cview"
|
||||||
@ -132,7 +132,7 @@ func Bookmarks(t *tab) {
|
|||||||
bkmkPageRaw += fmt.Sprintf("=> %s %s\r\n", keys[i], m[keys[i]])
|
bkmkPageRaw += fmt.Sprintf("=> %s %s\r\n", keys[i], m[keys[i]])
|
||||||
}
|
}
|
||||||
// Render and display
|
// Render and display
|
||||||
content, links := renderer.RenderGemini(bkmkPageRaw, textWidth(), false)
|
content, links := render.RenderGemini(bkmkPageRaw, textWidth(), false)
|
||||||
page := structs.Page{
|
page := structs.Page{
|
||||||
Raw: bkmkPageRaw,
|
Raw: bkmkPageRaw,
|
||||||
Content: content,
|
Content: content,
|
||||||
|
@ -11,7 +11,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/renderer"
|
"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"
|
||||||
@ -249,7 +249,7 @@ func Init(version, commit, builtBy string) {
|
|||||||
// Render the default new tab content ONCE and store it for later
|
// Render the default new tab content ONCE and store it for later
|
||||||
// This code is repeated in Reload()
|
// This code is repeated in Reload()
|
||||||
newTabContent := getNewTabContent()
|
newTabContent := getNewTabContent()
|
||||||
renderedNewTabContent, newTabLinks := renderer.RenderGemini(newTabContent, textWidth(), false)
|
renderedNewTabContent, newTabLinks := render.RenderGemini(newTabContent, textWidth(), false)
|
||||||
newTabPage = structs.Page{
|
newTabPage = structs.Page{
|
||||||
Raw: newTabContent,
|
Raw: newTabContent,
|
||||||
Content: renderedNewTabContent,
|
Content: renderedNewTabContent,
|
||||||
@ -531,7 +531,7 @@ func Reload() {
|
|||||||
// Re-render new tab, similar to Init()
|
// Re-render new tab, similar to Init()
|
||||||
newTabContent := getNewTabContent()
|
newTabContent := getNewTabContent()
|
||||||
tmpTermW := termW
|
tmpTermW := termW
|
||||||
renderedNewTabContent, newTabLinks := renderer.RenderGemini(newTabContent, textWidth(), false)
|
renderedNewTabContent, newTabLinks := render.RenderGemini(newTabContent, textWidth(), false)
|
||||||
newTabPage = structs.Page{
|
newTabPage = structs.Page{
|
||||||
Raw: newTabContent,
|
Raw: newTabContent,
|
||||||
Content: renderedNewTabContent,
|
Content: renderedNewTabContent,
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"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/makeworld-the-better-one/amfora/structs"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
@ -59,7 +59,7 @@ func handleFile(u string) (*structs.Page, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if mimetype == "text/gemini" {
|
if mimetype == "text/gemini" {
|
||||||
rendered, links := renderer.RenderGemini(string(content), textWidth(), false)
|
rendered, links := render.RenderGemini(string(content), textWidth(), false)
|
||||||
page = &structs.Page{
|
page = &structs.Page{
|
||||||
Mediatype: structs.TextGemini,
|
Mediatype: structs.TextGemini,
|
||||||
URL: u,
|
URL: u,
|
||||||
@ -73,7 +73,7 @@ func handleFile(u string) (*structs.Page, bool) {
|
|||||||
Mediatype: structs.TextPlain,
|
Mediatype: structs.TextPlain,
|
||||||
URL: u,
|
URL: u,
|
||||||
Raw: string(content),
|
Raw: string(content),
|
||||||
Content: renderer.RenderPlainText(string(content)),
|
Content: render.RenderPlainText(string(content)),
|
||||||
Links: []string{},
|
Links: []string{},
|
||||||
TermWidth: termW,
|
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)
|
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{
|
page = &structs.Page{
|
||||||
Mediatype: structs.TextGemini,
|
Mediatype: structs.TextGemini,
|
||||||
URL: u,
|
URL: u,
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
"github.com/makeworld-the-better-one/amfora/cache"
|
"github.com/makeworld-the-better-one/amfora/cache"
|
||||||
"github.com/makeworld-the-better-one/amfora/client"
|
"github.com/makeworld-the-better-one/amfora/client"
|
||||||
"github.com/makeworld-the-better-one/amfora/config"
|
"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/rr"
|
||||||
"github.com/makeworld-the-better-one/amfora/structs"
|
"github.com/makeworld-the-better-one/amfora/structs"
|
||||||
"github.com/makeworld-the-better-one/amfora/subscriptions"
|
"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
|
// Fetch happened successfully, use RestartReader to buffer read data
|
||||||
res.Body = rr.NewRestartReader(res.Body)
|
res.Body = rr.NewRestartReader(res.Body)
|
||||||
|
|
||||||
if renderer.CanDisplay(res) {
|
if render.CanDisplay(res) {
|
||||||
page, err := renderer.MakePage(u, res, textWidth(), usingProxy)
|
page, err := render.MakePage(u, res, textWidth(), usingProxy)
|
||||||
// Rendering may have taken a while, make sure tab is still valid
|
// Rendering may have taken a while, make sure tab is still valid
|
||||||
if !isValidTab(t) {
|
if !isValidTab(t) {
|
||||||
return ret("", false)
|
return ret("", false)
|
||||||
}
|
}
|
||||||
|
|
||||||
if errors.Is(err, renderer.ErrTooLarge) {
|
if errors.Is(err, render.ErrTooLarge) {
|
||||||
// Downloading now
|
// Downloading now
|
||||||
// Disable read timeout and go back to start
|
// Disable read timeout and go back to start
|
||||||
res.SetReadTimeout(0) //nolint: errcheck
|
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)
|
go dlChoice("That page is too large. What would you like to do?", u, res)
|
||||||
return ret("", false)
|
return ret("", false)
|
||||||
}
|
}
|
||||||
if errors.Is(err, renderer.ErrTimedOut) {
|
if errors.Is(err, render.ErrTimedOut) {
|
||||||
// Downloading now
|
// Downloading now
|
||||||
// Disable read timeout and go back to start
|
// Disable read timeout and go back to start
|
||||||
res.SetReadTimeout(0) //nolint: errcheck
|
res.SetReadTimeout(0) //nolint: errcheck
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"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/makeworld-the-better-one/amfora/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ func reformatPage(p *structs.Page) {
|
|||||||
return
|
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
|
var rendered string
|
||||||
switch p.Mediatype {
|
switch p.Mediatype {
|
||||||
@ -64,11 +64,11 @@ func reformatPage(p *structs.Page) {
|
|||||||
strings.HasPrefix(p.URL, "file") {
|
strings.HasPrefix(p.URL, "file") {
|
||||||
proxied = false
|
proxied = false
|
||||||
}
|
}
|
||||||
rendered, _ = renderer.RenderGemini(p.Raw, textWidth(), proxied)
|
rendered, _ = render.RenderGemini(p.Raw, textWidth(), proxied)
|
||||||
case structs.TextPlain:
|
case structs.TextPlain:
|
||||||
rendered = renderer.RenderPlainText(p.Raw)
|
rendered = render.RenderPlainText(p.Raw)
|
||||||
case structs.TextAnsi:
|
case structs.TextAnsi:
|
||||||
rendered = renderer.RenderANSI(p.Raw)
|
rendered = render.RenderANSI(p.Raw)
|
||||||
default:
|
default:
|
||||||
// Rendering this type is not implemented
|
// Rendering this type is not implemented
|
||||||
return
|
return
|
||||||
|
@ -12,7 +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/renderer"
|
"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/amfora/subscriptions"
|
"github.com/makeworld-the-better-one/amfora/subscriptions"
|
||||||
"github.com/makeworld-the-better-one/go-gemini"
|
"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{
|
page := structs.Page{
|
||||||
Raw: rawPage,
|
Raw: rawPage,
|
||||||
Content: content,
|
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{
|
page := structs.Page{
|
||||||
Raw: rawPage,
|
Raw: rawPage,
|
||||||
Content: content,
|
Content: content,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package renderer
|
package render
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
@ -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.
|
// Example objects include a Gemini response, and an error.
|
||||||
//
|
//
|
||||||
// Rendered lines always end with \r\n, in an effort to be Window compatible.
|
// Rendered lines always end with \r\n, in an effort to be Window compatible.
|
||||||
package renderer
|
package render
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
Loading…
Reference in New Issue
Block a user