From db69646dbdf5e4da84d32df95e033837e1273da7 Mon Sep 17 00:00:00 2001 From: makeworld Date: Sun, 21 Jun 2020 23:49:43 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Support=20all=20text/*=20documents?= =?UTF-8?q?=20-=20fixes=20#12?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + display/display.go | 4 +--- renderer/page.go | 15 +++++++-------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70a3e13..8ae2268 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Right margin for text (#1) - Desktop entry file - Option to continue anyway when cert doesn't match TOFU database +- Display all `text/*` documents, not just gemini and plain (#12) ### Changed - Connection timeout is 15 seconds (was 5s) diff --git a/display/display.go b/display/display.go index 2d6db0a..41b93fe 100644 --- a/display/display.go +++ b/display/display.go @@ -21,7 +21,6 @@ var tabMap = make(map[int]*structs.Page) // Map of tab number to page var tabViews = make(map[int]*cview.TextView) var termW int -var termH int // The user input and URL display bar at the bottom var bottomBar = cview.NewInputField(). @@ -80,9 +79,8 @@ var App = cview.NewApplication(). EnableMouse(false). SetRoot(layout, true). SetAfterResizeFunc(func(width int, height int) { - // Store width and height for calculations + // Store for calculations termW = width - termH = height // Shift new tabs created before app startup, when termW == 0 // XXX: This is hacky but works. The biggest issue is that there will sometimes be a tiny flash diff --git a/renderer/page.go b/renderer/page.go index 256d62c..6c6ffec 100644 --- a/renderer/page.go +++ b/renderer/page.go @@ -34,7 +34,7 @@ func CanDisplay(res *gemini.Response) bool { if err != nil { return false } - if mediatype != "text/gemini" && mediatype != "text/plain" { + if !strings.HasPrefix(mediatype, "text/") { // Amfora doesn't support other filetypes return false } @@ -75,13 +75,6 @@ func MakePage(url string, res *gemini.Response, width int) (*structs.Page, error } } - if mediatype == "text/plain" { - return &structs.Page{ - Url: url, - Content: utfText, - Links: []string{}, // Plaintext has no links - }, nil - } if mediatype == "text/gemini" { rendered, links := RenderGemini(utfText, width) return &structs.Page{ @@ -89,6 +82,12 @@ func MakePage(url string, res *gemini.Response, width int) (*structs.Page, error Content: rendered, Links: links, }, nil + } else if strings.HasPrefix(mediatype, "text/") { + return &structs.Page{ + Url: url, + Content: utfText, + Links: []string{}, // Non-gemini links are not supported + }, nil } return nil, errors.New("displayable mediatype is not handled in the code, implementation error")