foreseen

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

commit fc9b339349b021cd87712027ebdcb83ec4928ab6
parent 08bb51102c7bce88613598a073957135dbdb9664
Author: Andrew Laack <andrew@laack.co>
Date:   Mon, 28 Sep 2026 00:04:14 -0500

Simple refactoring

Diffstat:
MTODO.txt | 12++++++++++--
Msrc/main.cpp | 33+++++----------------------------
2 files changed, 15 insertions(+), 30 deletions(-)

diff --git a/TODO.txt b/TODO.txt @@ -81,5 +81,13 @@ --- -- bookmarks: - - +- bookmarks + +--- + +- gotosite should return status code on failure to be shown to users + - this will aid in understanding: + - server unreachable + - request rejected + - cert issues + - ... diff --git a/src/main.cpp b/src/main.cpp @@ -3,7 +3,6 @@ #include <algorithm> #include <cassert> #include <chrono> -#include <cstddef> #include <cstdint> #include <ncurses.h> #include <locale.h> @@ -27,30 +26,6 @@ bool isValidUserInput(int uinput) { } return false; } - -// we do this because this is built against ncurses, would be nice to do away w/ this -// bc ppl use lots of emojis on gemini sites. - -void removeNonAscii(std::vector<std::pair<std::string, TextRender>>& strLs) { - for(std::size_t i = 0; i < strLs.size(); ++i) { - - std::string& s = strLs[i].first; - - std::string out; - for (int c: s) - if ((c >= 0x20 && c <= 0x7E) || (c == '\n')) { - out += c; - } else if (c == '\t') { - out += " "; // \t is a larger character and fucks with breaklines. - } - - strLs[i].first = out; - } - return; -} - - - void initColors() { if(has_colors()) { start_color(); @@ -121,6 +96,9 @@ void drawInputBox(std::string text, std::string userInput) { addstr(userTextToRender.c_str()); } +uint64_t getCurrentTime() { + return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count(); +} void draw(DrawState& ds) { @@ -143,7 +121,6 @@ void draw(DrawState& ds) { } else { current = ds.bPtr->renderSite(); - // removeNonAscii(current); current = breakLines(current,std::min(COLS, maxWidth), COLS); ds.prior = current; } @@ -205,7 +182,7 @@ void draw(DrawState& ds) { } if(ds.issueText != "") { - uint64_t now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count(); + uint64_t now = getCurrentTime(); if(ds.timeToClearIssueText <= now) { ds.issueText = ""; } else { @@ -339,7 +316,7 @@ void tryVisitSite(DrawState& ds , Browser& b, std::string site) { bool visitSuccess = b.goToSite(site); if(!visitSuccess) { ds.issueText = "Unable to access the requested site."; - ds.timeToClearIssueText = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count() + 1000; + ds.timeToClearIssueText = getCurrentTime() + 1000; } else { ds.y = 0; }