foreseen

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

commit 0a8839083a0eeada68d394b799c5e9ff5e11617a
parent f4c8dda85a9ceccf0e875e6a0abc11504e235c08
Author: Andrew Laack <andrew@laack.co>
Date:   Thu,  1 Oct 2026 20:24:20 -0500

Updated tests, fixed debug warnings

Diffstat:
MTODO.txt | 14++++----------
Msrc/cache.cpp | 2+-
Msrc/main.cpp | 7++++++-
Mtests/browser-test.cpp | 2+-
Mtests/pure-test.cpp | 4++++
5 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/TODO.txt b/TODO.txt @@ -190,13 +190,7 @@ Bug: --- -- cli arguments with editable source code for defaults -- add phony file - - ---- - -- cli args: - --cache-pages - --prefetch-links - --search-engine +- detect if a file is not a normal text file + - source code, txt, md, gmi, stuff like that + - if not, give option to download site + - this seems involved, but useful. diff --git a/src/cache.cpp b/src/cache.cpp @@ -30,7 +30,7 @@ void Cache::addSite(std::string address, Site site) { cache.emplace(address, std::move(site)); evictionQueue.push_front(address); - if (evictionQueue.size() > CACHE_SIZE) { + if ((int)evictionQueue.size() > CACHE_SIZE) { cache.erase(evictionQueue.back()); evictionQueue.pop_back(); } diff --git a/src/main.cpp b/src/main.cpp @@ -41,7 +41,12 @@ int main(int argc, char** argv) { SITE_CACHE_LIMIT = program.get<int>("--prefetch-links"); CACHE_SIZE = program.get<int>("--cache-pages"); - DEFAULT_SEARCH_ENGINE = program.get<std::string>("--search-engine") + "?"; + DEFAULT_SEARCH_ENGINE = program.get<std::string>("--search-engine"); + + if(DEFAULT_SEARCH_ENGINE.substr(DEFAULT_SEARCH_ENGINE.size()-1) != "?") { + DEFAULT_SEARCH_ENGINE += "?"; + } + std::string destination = program.present<std::string>("destination").value_or(""); std::signal(SIGPIPE, SIG_IGN); // need this in case of swapping network connections bc that shouldn't kill the whole process. diff --git a/tests/browser-test.cpp b/tests/browser-test.cpp @@ -206,7 +206,7 @@ TEST_CASE("Never crash from weird user inputs") { } for(auto& str : ls) { - auto res = handleDestinationResolution(str, false); + auto res = handleDestinationResolution("?" + str, false); if(res.t == STRING_DESTINATION) { b.goToSite(res.destination); } else if (res.t == NUMBER_DESTINATION) { diff --git a/tests/pure-test.cpp b/tests/pure-test.cpp @@ -75,6 +75,10 @@ TEST_CASE("Inputs with spaces outside of the cli are always searched") { TEST_CASE("Test user input handling for destinations") { + if(DEFAULT_SEARCH_ENGINE.substr(DEFAULT_SEARCH_ENGINE.size()-1) != "?") { + DEFAULT_SEARCH_ENGINE += "?"; + } + SECTION("Convert numbers to link numbers") { for(int i = 0; i < 10000; ++i) { REQUIRE(handleDestinationResolution(std::to_string(i), false).linkNumber == i);