commit 45cd9a08ca226df7d1dc840917d44f6a1ff71301
parent 7a03ec5c4eeba0f470e83dfb21a11820e1200db3
Author: Andrew Laack <andrew@laack.co>
Date: Sat, 3 Oct 2026 23:48:29 -0500
Revert "Refactored code to return enum from gotosite."
This reverts commit 7a03ec5c4eeba0f470e83dfb21a11820e1200db3.
Diffstat:
6 files changed, 21 insertions(+), 38 deletions(-)
diff --git a/include/browser.hpp b/include/browser.hpp
@@ -11,13 +11,7 @@
#include "cache.hpp"
#include "link.hpp"
#include "utils.hpp"
-
-enum GoToSiteResult {
- SITE_LOADED,
- SITE_LOAD_FAILED,
- FETCHING_SITE_ASYNC
-};
-
+#include "shared.hpp"
class Browser {
private:
@@ -39,9 +33,7 @@ class Browser {
Browser();
void setLinksOfCurrentLines();
~Browser();
-
- // if background is set and the site is found in cache it will go there right away, returning successfully.
- GoToSiteResult goToSite(std::string url, bool addToHistory = true, bool refresh = false, bool background = false);
+ bool goToSite(std::string url, bool addToHistory = true, bool refresh = false);
void setDone(int threadIdx);
void refresh();
Site* getCurrentSite();
diff --git a/include/shared.hpp b/include/shared.hpp
@@ -6,7 +6,7 @@
extern std::string DEFAULT_SEARCH_ENGINE; // default search option when search is inferred
extern int SITE_CACHE_LIMIT; // number of links to prefetch per page
extern int THREAD_NUM; // thread count in thread pool for pre-fetching
-extern int MAX_WIDTH; // max text width
+extern int maxWidth; // max text width
extern int CACHE_SIZE; // max elements in history cache and max in prefetch cache
extern uint8_t COLOR_LINK; // color used for links
extern uint8_t COLOR_PREFORMATTED; // color used for preformatted text regions
diff --git a/src/browser.cpp b/src/browser.cpp
@@ -6,7 +6,6 @@
#include <thread>
#include <unistd.h>
#include "../include/site.hpp"
-#include "../include/shared.hpp"
#include "../include/errors.hpp"
#include "../include/gemini-client.hpp"
#include "../include/utils.hpp"
@@ -95,7 +94,7 @@ void Browser::refresh() {
goToSite(getPriorUri().value().to_string(), false, true);
}
-GoToSiteResult Browser::goToSite(std::string url, bool addToHistory, bool refresh, bool background) {
+bool Browser::goToSite(std::string url, bool addToHistory, bool refresh) {
Link* prior = nullptr;
@@ -125,7 +124,7 @@ GoToSiteResult Browser::goToSite(std::string url, bool addToHistory, bool refres
openThread = std::thread(openUrl, urlString);
delete destination;
- return SITE_LOADED;
+ return true;
}
@@ -152,14 +151,14 @@ GoToSiteResult Browser::goToSite(std::string url, bool addToHistory, bool refres
delete site;
}
delete destination;
- return SITE_LOAD_FAILED;
+ return false;
}
int sc = site->getStatusCode();
if (sc < 10 || sc >= 40) {
delete site;
delete destination;
- return SITE_LOAD_FAILED; // TODO: better handling, addl enum opt
+ return false;
}
if(addToHistory) {
@@ -196,7 +195,7 @@ GoToSiteResult Browser::goToSite(std::string url, bool addToHistory, bool refres
}
tryCacheTargets();
- return SITE_LOADED;
+ return true;
}
Identity Browser::getIdentity(uri uriInput) {
@@ -273,9 +272,8 @@ Browser::Browser() : threads(THREAD_NUM), done(THREAD_NUM){
}
// this ensures some nice invariants about the browser, like always having at least one valid page.
- GoToSiteResult start = goToSite("about://newtab");
-
- if(start != SITE_LOADED) {
+ bool start = goToSite("about://newtab");
+ if(!start) {
throw std::runtime_error("Browser unexpectedly failed to start.");
}
}
@@ -353,13 +351,8 @@ bool Browser::followLinkNumber(int linkToFollow) {
if(lines.size() > pos) {
Line* ptr = lines[pos];
Link* ptrLnk = dynamic_cast<Link*>(ptr);
- GoToSiteResult res = goToSite(ptrLnk->getLinkDestination().to_string(), true);
-
- if(res == SITE_LOADED) {
- return true;
- }
-
- return false;
+ bool res = goToSite(ptrLnk->getLinkDestination().to_string(), true);
+ return res;
}
}
return false;
@@ -395,7 +388,7 @@ void Browser::goBack() {
return; // safely fail with rollback
}
}
- if(goToSite(this->siteHistory[previousIdx]->getLinkDestination().to_string(), false) != SITE_LOADED) {
+ if(!goToSite(this->siteHistory[previousIdx]->getLinkDestination().to_string(), false)) {
previousIdx = original;
}
@@ -428,7 +421,7 @@ void Browser::goForward() {
}
}
- if(goToSite(this->siteHistory[previousIdx]->getLinkDestination().to_string(), false) != SITE_LOADED) {
+ if(!goToSite(this->siteHistory[previousIdx]->getLinkDestination().to_string(), false)) {
previousIdx = original;
}
} else {
diff --git a/src/main.cpp b/src/main.cpp
@@ -1,7 +1,6 @@
#include "../include/browser.hpp"
#include "../include/utils.hpp"
#include "../include/render.hpp"
-#include "../include/shared.hpp"
#include <cassert>
#include <csignal>
#include <ncurses.h>
diff --git a/src/render.cpp b/src/render.cpp
@@ -1,6 +1,5 @@
#include "../include/browser.hpp"
#include "../include/utils.hpp"
-#include "../include/shared.hpp"
#include "../include/render.hpp"
#include <algorithm>
#include <cassert>
@@ -120,7 +119,7 @@ void draw(DrawState& ds) {
}
if(ds.reBreak) {
- ds.broken = breakLines(ds.prior, std::min(ds.columns, MAX_WIDTH), ds.columns);
+ ds.broken = breakLines(ds.prior, std::min(ds.columns, maxWidth), ds.columns);
ds.reBreak = false;
}
if(ds.toLowest) {
@@ -272,15 +271,15 @@ void handleUserInput(DrawState& ds, Browser& b, int sel) {
}
void tryVisitSite(DrawState& ds , Browser& b, std::string site) {
- GoToSiteResult visitSuccess = b.goToSite(site);
-
- if(visitSuccess == SITE_LOADED) {
+ bool visitSuccess = b.goToSite(site);
+ if(visitSuccess) {
ds.mustReRender = true;
- ds.y = 0;
}
- else {
+ if(!visitSuccess) {
ds.issueText = "Unable to access the requested site.";
ds.timeToClearIssueText = getCurrentTime() + 1000;
+ } else {
+ ds.y = 0;
}
}
diff --git a/src/shared.cpp b/src/shared.cpp
@@ -3,7 +3,7 @@
std::string DEFAULT_SEARCH_ENGINE = "gemini://tlgs.one/search";
int SITE_CACHE_LIMIT = 10;
int THREAD_NUM = 4;
-int MAX_WIDTH = 80;
+int maxWidth = 80;
int CACHE_SIZE = 500;
uint8_t COLOR_LINK = 159;
uint8_t COLOR_PREFORMATTED = 201;