foreseen

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

commit e50ecd0b2da400225c84585f8b81cf4f647f81f4
parent 4ec45f38831837ba3a6bd86f9b45b0a17924edd5
Author: Andrew Laack <andrew@laack.co>
Date:   Mon, 12 Oct 2026 16:56:17 -0500

Factoring shared.cpp + fmt

Diffstat:
Mdocs/TODO | 4++++
Minclude/shared.hpp | 8+-------
Msrc/main.cpp | 2+-
Msrc/render.cpp | 4+---
Msrc/shared.cpp | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
5 files changed, 66 insertions(+), 17 deletions(-)

diff --git a/docs/TODO b/docs/TODO @@ -14,3 +14,7 @@ - refactor non-runtime configurable values to be set in hpp file - inject these into about://newtab - make sure keybings screen is consistent + +--- + +- fix todos in shared.cpp diff --git a/include/shared.hpp b/include/shared.hpp @@ -26,10 +26,4 @@ extern uint8_t COLOR_PLAINTEXT; // color used for plaintext lines // additional bytes extern int RESPONSE_SIZE_LIMIT_MB; -// since the xdg-open stuff is in a seperate process nothing will go to stdout -// even in the echo case. -#ifdef DEBUG_MODE -const char openUnknownScheme[] = "echo"; -#else -const char openUnknownScheme[] = "xdg-open"; -#endif +extern char openUnknownScheme[]; diff --git a/src/main.cpp b/src/main.cpp @@ -84,7 +84,7 @@ int main(int argc, char** argv) { setlocale(LC_CTYPE, ""); // emojis and such - if(!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO)) { + if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO)) { std::cout << "This program must be executed interactively" << std::endl; return 1; } diff --git a/src/render.cpp b/src/render.cpp @@ -206,7 +206,6 @@ void draw(DrawState& ds) { if (ds.timeToClearBottomText <= now) { ds.bottomText = ""; } else { - std::string tr = ds.bottomText; std::string truncated; @@ -218,8 +217,7 @@ void draw(DrawState& ds) { truncated = truncated.substr(0, ds.columns - 3) + "..."; } - move(ds.lines - 1, - (ds.columns / 2) - ((int)truncated.size() / 2)); + move(ds.lines - 1, (ds.columns / 2) - ((int)truncated.size() / 2)); attron(A_BOLD); addstr(truncated.c_str()); diff --git a/src/shared.cpp b/src/shared.cpp @@ -1,21 +1,74 @@ #include "../include/shared.hpp" +// ============================================================================= +// CLI OPTIONS +// ============================================================================= + +// These are the defaults for CLI options. When options are specified from the +// CLI they will supersede these values. + +// When using the 'o' search menu, this will be infered as the base url of the +// search. + +// TODO: Must this be url encoded? std::string DEFAULT_SEARCH_ENGINE = "gemini://tlgs.one/search"; + +// This is the maximum number of links to prefetch per page. + int SITE_CACHE_LIMIT = 10; -int THREAD_NUM = 4; -int MAX_WIDTH = 80; + +// The prefetch cache and history cache may both have CACHE_SIZE sites within +// their respective caches at any given time. + +// TODO: given this definition; check to make sure eviction happens prior to +// insertion to maintain size invariant at all times. + int CACHE_SIZE = 50; +// ============================================================================= +// COLORS +// ============================================================================= + +// Colors vary by $TERM. See ncurses and terminfo docs for details. The default +// constants assume a 256-color terminal. + uint8_t COLOR_LINK = 159; uint8_t COLOR_PREFORMATTED = 201; uint8_t COLOR_QUOTE = 5; +uint8_t COLOR_LIST_ITEM = 15; +uint8_t COLOR_FORMAT_SWITCH = 7; +uint8_t COLOR_PLAINTEXT = 15; + uint8_t COLOR_H3 = 6; uint8_t COLOR_H2 = 2; uint8_t COLOR_H1 = 1; -uint8_t COLOR_LIST_ITEM = 15; -uint8_t COLOR_FORMAT_SWITCH = 7; -uint8_t COLOR_PLAINTEXT = 15; +// ============================================================================= +// OTHER +// ============================================================================= + +// This limits the size of gemini protocol responses to at most +// RESPONSE_SIZE_LIMIT_MB + 4kb, and at least RESPONSE_SIZE_LIMIT_MB. + +int RESPONSE_SIZE_LIMIT_MB = 5; -int RESPONSE_SIZE_LIMIT_MB = 5; // This will truncate at the specified size. +// This specifies the base command to execute to handle unknown schemes (e.g. +// http). The command will be executed along with the uri being followed as the +// first positional argument. + +#ifdef DEBUG_MODE +char openUnknownScheme[] = "echo"; +#else +char openUnknownScheme[] = "xdg-open"; +#endif + +// This is the thread pool size for prefetching. Each thread is given at most +// SITE_CACHE_LIMIT links to fetch when visiting a site. If all threads are in +// use and a site is visited, prefetching is skipped. + +int THREAD_NUM = 4; + +// This is the maximum width text may be before it is forcibly wrapped. + +int MAX_WIDTH = 80;