foreseen

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

commit 6863281879c8e5d176dbed0c10675ec23776a9dc
parent a5edbd389086aeac78854d068ebff46b0925edf0
Author: Andrew Laack <andrew@laack.co>
Date:   Mon, 21 Sep 2026 22:19:55 -0500

Basic ncurses navigation

Diffstat:
MMakefile | 2+-
Minclude/utils.hpp | 2++
Msrc/main.cpp | 60+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Msrc/utils.cpp | 22++++++++++++++++++++++
4 files changed, 84 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,5 +1,5 @@ build: - g++ src/main.cpp src/link.cpp src/site.cpp src/utils.cpp src/gemini-client.cpp src/browser.cpp -lssl -lcrypto -o browser.out + g++ src/main.cpp src/link.cpp src/site.cpp src/utils.cpp src/gemini-client.cpp src/browser.cpp -lssl -lcrypto -lncurses -o browser.out install: echo "Not implemented" diff --git a/include/utils.hpp b/include/utils.hpp @@ -1,7 +1,9 @@ #pragma once #include <string> +#include <vector> bool isPrefixed(std::string input, std::string prefix); std::string readFileToString(std::string filePath); bool isWhiteSpace(std::string& line, int idx); std::string truncateAfter(std::string input, char truncate); +std::vector<std::string> stringToList(std::string input); diff --git a/src/main.cpp b/src/main.cpp @@ -1,9 +1,67 @@ #include "../include/browser.hpp" #include "../include/site.hpp" #include "../include/link.hpp" +#include "../include/utils.hpp" +#include <algorithm> #include <iostream> +#include <ncurses.h> + +void draw(int y, std::vector<std::string>& strLs) { + move(0,0); + for(int i = y;i-y+1 < LINES && i < strLs.size(); ++i) { + addstr((strLs[i] + '\n').c_str()); + move(i-y+1,0); + } +} + +int lowestPos(std::vector<std::string>& strLs) { + return strLs.size() - LINES; +} int main() { + Browser b{}; - b.goToSite("gemini://laack.co"); + + initscr(); + noecho(); // don't echo user inputs + cbreak(); // make C-c and C-z work + curs_set(0); // hide cursor + keypad(stdscr,TRUE); + + b.goToSite("gemini://tlgs.one/known-hosts"); + auto current = b.getCurrentSite()->getBody(); + auto strLs = stringToList(current); + + int input; + int y = 0; + int x = 0; + bool first = true; + + while( input != 'q') { + if(input == KEY_DOWN) { + y += 1; + } else if (input == KEY_UP){ + y -= 1; + } else if (input == 'g'){ + y = 0; + } else if (input == 'G'){ + y = lowestPos(strLs); + } else if (input == 0x04){ + y += LINES / 2; + } else if (input == 0x15) { + y -= LINES / 2; + } + + + y = std::max(0,y); + y = std::min(y,lowestPos(strLs)); + + draw(y, strLs); + + + refresh(); + input = getch(); + } + + endwin(); } diff --git a/src/utils.cpp b/src/utils.cpp @@ -6,6 +6,7 @@ #include <iostream> #include <sstream> #include <string> +#include <vector> bool isPrefixed(std::string input, std::string prefix) { return std::string(input).find(prefix) == 0; @@ -33,3 +34,24 @@ std::string truncateAfter(std::string input, char truncate) { } return input; } + +std::vector<std::string> stringToList(std::string input) +{ + std::vector<std::string> res; + if (!input.empty()) { + int start = 0; + do { + int idx = input.find('\n', start); + if (idx == std::string::npos) { + break; + } + int length = idx - start; + res.push_back(input.substr(start, length)); + start += (length + 1); + + } while (true); + res.push_back(input.substr(start)); + } + + return res; +}