foreseen

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

commit 10c272096fba3c4e29385ec8c79f7f6909260784
parent eac81453ee1b936628cbb5082441fc545c0cfbe8
Author: Andrew Laack <andrew@laack.co>
Date:   Sun, 27 Sep 2026 12:39:33 -0500

Improved forward / backward navigation, particularly useful for sites that redirect back to where you were.

Diffstat:
Msrc/browser.cpp | 17++++++++++++-----
Msrc/gemini-client.cpp | 2+-
Msrc/main.cpp | 4++--
3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/src/browser.cpp b/src/browser.cpp @@ -327,22 +327,24 @@ void Browser::followLinkNumber(int linkToFollow) { void Browser::goBack() { int original = previousIdx; + std::string starting = getCurrentLink()->getLinkDestination().to_string(); previousIdx -= 1; if((int)siteHistory.size() > previousIdx && previousIdx >= 0) { int prSC = previousStatusCodes[siteHistory[previousIdx]->getLinkDestination().to_string()]; - while(!(prSC >= 20 && prSC <= 29)) { + std::string current = siteHistory[previousIdx]->getLinkDestination().to_string(); + while(!(prSC >= 20 && prSC <= 29) || starting == current) { previousIdx -= 1; if((int)siteHistory.size() > previousIdx && previousIdx >= 0) { prSC = previousStatusCodes[siteHistory[previousIdx]->getLinkDestination().to_string()]; + current = siteHistory[previousIdx]->getLinkDestination().to_string(); } else { previousIdx = original; - return; + return; // safely fail with rollback } } - goToSite(this->siteHistory[previousIdx]->getLinkDestination().to_string(), false); } else { @@ -353,17 +355,22 @@ void Browser::goBack() { void Browser::goForward() { int original = previousIdx; + std::string starting = getCurrentLink()->getLinkDestination().to_string(); previousIdx += 1; if((int)siteHistory.size() > previousIdx && previousIdx >= 0) { + int prSC = previousStatusCodes[siteHistory[previousIdx]->getLinkDestination().to_string()]; - while(!(prSC >= 20 && prSC <= 29)) { + std::string current = siteHistory[previousIdx]->getLinkDestination().to_string(); + + while(!(prSC >= 20 && prSC <= 29) || starting == current) { previousIdx += 1; if((int)siteHistory.size() > previousIdx && previousIdx >= 0) { prSC = previousStatusCodes[siteHistory[previousIdx]->getLinkDestination().to_string()]; + current = siteHistory[previousIdx]->getLinkDestination().to_string(); } else { - previousIdx = original; + previousIdx = original; // fail safely return; } } diff --git a/src/gemini-client.cpp b/src/gemini-client.cpp @@ -149,7 +149,7 @@ Site* GeminiClient::fetchSite(Link link, std::string crtPath, std::string keyPat } // TODO: how should I discern file types? return new Site {"20 text/gemini", fileStr}; - } else if(isPrefixed(destination, "about:")){ + } else if(isPrefixed(destination, "about://")){ return new Site {"20 text/gemini", getNewTab()}; } else { throw NotImplemented(); diff --git a/src/main.cpp b/src/main.cpp @@ -334,11 +334,11 @@ int main(int argc, char** argv) { initColors(); - b.goToSite("about:newtab",true); + b.goToSite("about://newtab",true); if(argc > 1) { // TODO: This should have tests. - + // This should also be factored into the default cli input handling stuff too, possibly. if(std::filesystem::exists(argv[1])) { std::string path = "file:///" + std::filesystem::current_path().string() + "/" + argv[1]; b.goToSite(path,true);