foreseen

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

commit c2e8dca0dfd4df581f71678ecbe4569f8cc271fc
parent 3bf784d60b4ad9f7cf65f0ff838a0a09029644d4
Author: Andrew Laack <andrew@laack.co>
Date:   Wed, 23 Sep 2026 15:26:00 -0500

Added bolding

Diffstat:
Minclude/browser.hpp | 3++-
Minclude/format-switch.hpp | 1+
Minclude/heading.hpp | 1+
Minclude/line.hpp | 1+
Minclude/link.hpp | 1+
Minclude/plaintext.hpp | 1+
Minclude/preformatted.hpp | 1+
Minclude/utils.hpp | 8+++++++-
Msrc/browser.cpp | 6+++---
Msrc/format-switch.cpp | 4++++
Msrc/heading.cpp | 3+++
Msrc/link.cpp | 5+++++
Msrc/main.cpp | 25++++++++++++++++++-------
Msrc/plaintext.cpp | 3+++
Msrc/preformatted.cpp | 4++++
Msrc/utils.cpp | 8++++----
16 files changed, 59 insertions(+), 16 deletions(-)

diff --git a/include/browser.hpp b/include/browser.hpp @@ -7,6 +7,7 @@ #include "site.hpp" #include "cache.hpp" #include "link.hpp" +#include "utils.hpp" class Browser { private: @@ -28,7 +29,7 @@ class Browser { Site* getCurrentSite(); Link* getCurrentLink(); std::optional<uri> getPriorUri(); - std::vector<std::pair<std::string, int>> renderSite(); + std::vector<std::pair<std::string, TextRender>> renderSite(); std::vector<Line*> toLines(Site* site); void followLinkNumber(int linkToFollow); std::vector<Link> getLinkLines(); diff --git a/include/format-switch.hpp b/include/format-switch.hpp @@ -9,4 +9,5 @@ class FormatSwitch : public Line { std::string textToDraw() override; int getColor() override; LineType type() override; + bool isBold() override; }; diff --git a/include/heading.hpp b/include/heading.hpp @@ -13,4 +13,5 @@ class Heading : public Line { std::string textToDraw() override; int getColor() override; LineType type() override; + bool isBold() override; }; diff --git a/include/line.hpp b/include/line.hpp @@ -19,4 +19,5 @@ class Line { virtual int getColor() = 0; virtual LineType type() = 0; virtual ~Line() = default; + virtual bool isBold() = 0; }; diff --git a/include/link.hpp b/include/link.hpp @@ -18,5 +18,6 @@ class Link : public Line { std::optional<std::string> getLinkText(); std::string textToDraw() override; int getColor() override; + bool isBold() override; LineType type() override; }; diff --git a/include/plaintext.hpp b/include/plaintext.hpp @@ -9,4 +9,5 @@ class Plaintext : public Line { std::string textToDraw() override; int getColor() override; LineType type() override; + bool isBold() override; }; diff --git a/include/preformatted.hpp b/include/preformatted.hpp @@ -9,4 +9,5 @@ class Preformatted : public Line { std::string textToDraw() override; int getColor() override; LineType type() override; + bool isBold() override; }; diff --git a/include/utils.hpp b/include/utils.hpp @@ -5,6 +5,12 @@ #include "line.hpp" #include "../vendor/uri.hpp" + +struct TextRender { + int color; + bool isBold; +}; + bool isPrefixed(std::string input, std::string prefix); std::string readFileToString(std::string filePath); bool isWhiteSpace(std::string& line, int idx); @@ -14,4 +20,4 @@ Line* lineToLine(std::string input, std::optional<uri> prior, int linkCount, boo std::string urlEncode(const std::string& value); std::string getNewTab(); void openUrl(const std::string& url); -std::vector<std::pair<std::string, int>> breakLines(std::vector<std::pair<std::string, int>>& strLs, int width); +std::vector<std::pair<std::string, TextRender>> breakLines(std::vector<std::pair<std::string, TextRender>>& strLs, int width); diff --git a/src/browser.cpp b/src/browser.cpp @@ -194,10 +194,10 @@ Site* Browser::getCurrentSite() { return currentSite; } -std::vector<std::pair<std::string, int>> Browser::renderSite() { - std::vector<std::pair<std::string, int>> res{}; +std::vector<std::pair<std::string, TextRender>> Browser::renderSite() { + std::vector<std::pair<std::string, TextRender>> res{}; for(auto* line: lines) { - std::pair<std::string,int> cp {line->textToDraw(), line->getColor()}; + std::pair<std::string,TextRender> cp {line->textToDraw(), TextRender {line->getColor(), line->isBold()}}; res.push_back(cp); } return res; diff --git a/src/format-switch.cpp b/src/format-switch.cpp @@ -17,3 +17,7 @@ LineType FormatSwitch::type() { return FORMAT_SWITCH; } +bool FormatSwitch::isBold() { + return false; +} + diff --git a/src/heading.cpp b/src/heading.cpp @@ -49,3 +49,6 @@ LineType Heading::type() { throw NotImplemented(); } } +bool Heading::isBold() { + return true; +} diff --git a/src/link.cpp b/src/link.cpp @@ -101,3 +101,8 @@ int Link::getColor() { LineType Link::type() { return LINK; } + +bool Link::isBold() { + return false; +} + diff --git a/src/main.cpp b/src/main.cpp @@ -30,7 +30,7 @@ void aggressiveCaching(Browser* bPtr, std::vector<Link> targets, int threadIdx) done[threadIdx] = true; } -void removeNonAscii(std::vector<std::pair<std::string, int>>& strLs) { +void removeNonAscii(std::vector<std::pair<std::string, TextRender>>& strLs) { for(std::size_t i = 0; i < strLs.size(); ++i) { @@ -53,11 +53,10 @@ void initColors() { init_pair(c + 1, c, -1); } } - struct DrawState { std::string header; int y; - std::vector<std::pair<std::string, int>> strLs; + std::vector<std::pair<std::string, TextRender>> strLs; bool handleInput; bool handleOpenOther; bool handleRedirect; @@ -111,13 +110,25 @@ void draw(DrawState ds) { clear(); move(0,(COLS / 2) - (ds.header.size() / 2) ); + + attron(A_BOLD); addstr(ds.header.c_str()); + attroff(A_BOLD); for(int i = ds.y;i-ds.y+1 < LINES && i < ds.strLs.size(); ++i) { move(i - ds.y + 1, 0); - attron(COLOR_PAIR(ds.strLs[i].second + 1)); - addstr(ds.strLs[i].first.c_str()); - attroff(COLOR_PAIR(ds.strLs[i].second + 1)); + + attron(COLOR_PAIR(ds.strLs[i].second.color + 1)); + if(ds.strLs[i].second.isBold) { + attron(A_BOLD); + addstr(ds.strLs[i].first.c_str()); + attroff(A_BOLD); + } + else { + addstr(ds.strLs[i].first.c_str()); + } + attroff(COLOR_PAIR(ds.strLs[i].second.color + 1)); + } if (ds.handleRedirect) { @@ -136,7 +147,7 @@ void draw(DrawState ds) { } -int lowestPos(std::vector<std::pair<std::string, int>>& strLs) { +int lowestPos(std::vector<std::pair<std::string, TextRender>>& strLs) { return strLs.size() - LINES; } diff --git a/src/plaintext.cpp b/src/plaintext.cpp @@ -16,3 +16,6 @@ LineType Plaintext::type() { return PLAINTEXT; } +bool Plaintext::isBold() { + return false; +} diff --git a/src/preformatted.cpp b/src/preformatted.cpp @@ -17,3 +17,7 @@ LineType Preformatted::type() { return PLAINTEXT; } +bool Preformatted::isBold() { + return false; +} + diff --git a/src/utils.cpp b/src/utils.cpp @@ -140,9 +140,9 @@ std::string getNewTab() { } // WIDTH IS INCLUSIVE -std::vector<std::pair<std::string, int>> breakLines(std::vector<std::pair<std::string, int>>& strLs, int width) { +std::vector<std::pair<std::string, TextRender>> breakLines(std::vector<std::pair<std::string, TextRender>>& strLs, int width) { - std::vector<std::pair<std::string, int>> res {}; + std::vector<std::pair<std::string, TextRender>> res {}; for(std::size_t i = 0; i < strLs.size(); ++i) { @@ -169,12 +169,12 @@ std::vector<std::pair<std::string, int>> breakLines(std::vector<std::pair<std::s current.push_back(cstr[x]); } - res.push_back(std::pair<std::string,int> {toPush,strLs[i].second}); + res.push_back(std::pair<std::string,TextRender> {toPush,strLs[i].second}); lastSpace = (cstr[x] == ' ') ? current.size() - 1 : -1; } } if(current.size() > 0) { - res.push_back(std::pair<std::string,int> {current,strLs[i].second}); + res.push_back(std::pair<std::string,TextRender> {current,strLs[i].second}); current = ""; } }