foreseen

A text-based gemini browser with prefetching.
git clone git://git.laack.co/foreseen.git
Log | Files | Refs | README | LICENSE

commit 2829246ef3d9e02e37aae58e6d24680ff883d0c4
parent 686b86fe4dd5ed85f1ad061d88fc908cbee6a2a5
Author: Andrew Laack <andrew@laack.co>
Date:   Fri, 25 Sep 2026 16:31:05 -0500

Don't wrap preformatted lines, even when they are too long.

Diffstat:
Minclude/utils.hpp | 1+
Msrc/browser.cpp | 10++++++++--
Msrc/format-switch.cpp | 2+-
Msrc/utils.cpp | 7+++++++
Atests/sites/fold.gmi | 5+++++
5 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/include/utils.hpp b/include/utils.hpp @@ -10,6 +10,7 @@ const int COLOR_LINK = 159; struct TextRender { int color; bool isBold; + bool shouldFold = true; // preformatted text doesn't need to be folded. }; bool isPrefixed(std::string input, std::string prefix); diff --git a/src/browser.cpp b/src/browser.cpp @@ -260,8 +260,14 @@ Site* Browser::getCurrentSite() { std::vector<std::pair<std::string, TextRender>> Browser::renderSite() { std::vector<std::pair<std::string, TextRender>> res{}; for(auto* line: lines) { - std::pair<std::string,TextRender> cp {line->textToDraw(), TextRender {line->getColor(), line->isBold()}}; - res.push_back(cp); + // TODO: Don't special case this; define an interface. + if(line->type() == PREFORMATTED) { + std::pair<std::string,TextRender> cp {line->textToDraw(), TextRender {line->getColor(), line->isBold(), false}}; + res.push_back(cp); + } else { + std::pair<std::string,TextRender> cp {line->textToDraw(), TextRender {line->getColor(), line->isBold()}}; + res.push_back(cp); + } } return res; } diff --git a/src/format-switch.cpp b/src/format-switch.cpp @@ -4,7 +4,7 @@ FormatSwitch::FormatSwitch(std::string input) : text(input) {} std::string FormatSwitch::textToDraw() { - return text + "\n"; + return ""; } int FormatSwitch::getColor() { diff --git a/src/utils.cpp b/src/utils.cpp @@ -184,6 +184,13 @@ std::vector<std::pair<std::string, TextRender>> breakLines(std::vector<std::pair for(std::size_t i = 0; i < strLs.size(); ++i) { std::string cstr = strLs[i].first; + + if(!strLs[i].second.shouldFold) { + cstr = cstr.substr(0,cols - leftPadAmount); // otherwise there's some funkiness at the end due to how ncurses renders stuff. + res.push_back(std::pair<std::string,TextRender> {leftPadStr + cstr, strLs[i].second}); + continue; + } + std::string current = ""; int lastSpace = -1; diff --git a/tests/sites/fold.gmi b/tests/sites/fold.gmi @@ -0,0 +1,5 @@ +# This is a test of folding behavior + +``` +aairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrirsetnoristnaorstienarsotienr +airsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienrairsetnoristnaorstienarsotienr