foreseen

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

commit 3059dbcdbaca5b46fc57faf2471a71ce2155dc0d
parent 6c58936f31db9d8f2817e3107838574e27d6dada
Author: Andrew Laack <andrew@laack.co>
Date:   Sun, 27 Sep 2026 14:24:52 -0500

incremental changes towards unified resolution

Diffstat:
Minclude/utils.hpp | 2+-
Msrc/main.cpp | 2+-
Msrc/utils.cpp | 46++++++++++++++++++++++++----------------------
Mtests/pure-test.cpp | 2+-
4 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/include/utils.hpp b/include/utils.hpp @@ -27,4 +27,4 @@ std::vector<std::pair<std::string, TextRender>> breakLines(std::vector<std::pair void writeStringToFile(std::string toWrite, std::string filePath); std::string encodeAsFilename(uri link); std::filesystem::path getHome(); -std::optional<std::string> handleCLIDestination(std::string destination); +std::optional<std::string> handleDestinationResolution(std::string destination, bool isCli); diff --git a/src/main.cpp b/src/main.cpp @@ -343,7 +343,7 @@ int main(int argc, char** argv) { destination = argv[1]; } - std::optional<std::string> cliDestination = handleCLIDestination(destination); + std::optional<std::string> cliDestination = handleDestinationResolution(destination, true); if(cliDestination != std::nullopt) { b.goToSite(cliDestination.value()); diff --git a/src/utils.cpp b/src/utils.cpp @@ -265,32 +265,34 @@ std::filesystem::path getHome() return home; } -std::optional<std::string> handleCLIDestination(std::string destination) { - if(destination != "") { - // TODO: This should have tests. - // This should also be factored into the default cli input handling stuff too, possibly. - if(std::filesystem::exists(destination)) { - std::string path = "file://" + std::filesystem::current_path().string() + "/" + destination; - - if(destination.find('/') == std::size_t(0)) { - path = "file://" + destination; - } +std::optional<std::string> handleDestinationResolution(std::string destination, bool isCli) { - return path; + if(isCli) { + if(destination != "") { + if(std::filesystem::exists(destination)) { + std::string path = "file://" + std::filesystem::current_path().string() + "/" + destination; - } else { - std::string inputString = destination; - if(inputString.find("gemini://") == 0) { - return destination; - } else if (inputString.find(':') == std::string::npos){ - return std::string {"gemini://"} + destination; - } else { - return destination; + if(destination.find('/') == std::size_t(0)) { + path = "file://" + destination; + } + + return path; + + } else { + std::string inputString = destination; + if(inputString.find("gemini://") == 0) { + return destination; + } else if (inputString.find(':') == std::string::npos){ + return std::string {"gemini://"} + destination; + } else { + return destination; + } } - } + } else { + return std::nullopt; + } } else { - return std::nullopt; + throw NotImplemented(); } - } diff --git a/tests/pure-test.cpp b/tests/pure-test.cpp @@ -34,7 +34,7 @@ TEST_CASE("Test cli input handling") { expectations["blog.laack.co/pygame-vs-raylib.gmi"] = "gemini://blog.laack.co/pygame-vs-raylib.gmi"; for(auto& expect : expectations) { - REQUIRE(handleCLIDestination(expect.first) == expect.second); + REQUIRE(handleDestinationResolution(expect.first, true) == expect.second); } }