commit f7e99b30c1439e5d57628873f6ee7b0745a0aebf
parent e378f90fd8b7cfab10326d52750aafd13d6b1511
Author: Andrew Laack <andrew@laack.co>
Date: Mon, 21 Sep 2026 23:30:52 -0500
Handle broken links, don't render non-ascii
Diffstat:
4 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,5 +1,5 @@
build:
- g++ src/main.cpp src/link.cpp src/plaintext.cpp src/site.cpp src/utils.cpp src/gemini-client.cpp src/browser.cpp -lssl -lcrypto -lncurses -o browser.out
+ g++ src/main.cpp src/link.cpp src/plaintext.cpp src/site.cpp src/utils.cpp src/gemini-client.cpp src/browser.cpp -lssl -lcrypto -lncursesw -o browser.out
install:
echo "Not implemented"
diff --git a/include/link.hpp b/include/link.hpp
@@ -9,6 +9,7 @@ class Link : public Line {
private:
uri linkDestination = uri("gemini://example.com");
std::optional<std::string> linkText;
+ bool invalid;
uri parseDestination(std::string destination, std::optional<uri> prior);
public:
Link(std::string text, std::optional<uri> prior = std::nullopt);
diff --git a/src/link.cpp b/src/link.cpp
@@ -47,12 +47,19 @@ uri Link::parseDestination(std::string destination, std::optional<uri> prior) {
if(prior != std::nullopt) {
// TODO: Handle port
std::string truncated = truncateAfter(prior->get_scheme() + "://" + prior->get_host() + "/" + prior->get_path(), '/');
+
destination = truncated + destination;
- } else {
+ }
+ else {
destination = "file://" + destination;
}
}
+ try {
return uri{destination};
+ } catch(...) {
+ invalid = true;
+ return uri{"gemini://broken-link.com"}; // TODO: Handle this better
+ }
}
uri Link::getLinkDestination() {
diff --git a/src/main.cpp b/src/main.cpp
@@ -4,6 +4,17 @@
#include <iostream>
#include <ncurses.h>
+// we do this because this is buiult against ncurses, would be nice to do away w/ this
+// bc ppl use lots of emojis on gemini sites.
+std::string removeNonAscii(const std::string& s) {
+ std::string out;
+ for (int c: s)
+ if ((c >= 0x20 && c < 0x7E) || (c == '\t' || c == '\n')) {
+ out += c;
+ }
+ return out;
+}
+
void draw(int y, std::vector<std::string>& strLs) {
move(0,0);
for(int i = y;i-y+1 < LINES && i < strLs.size(); ++i) {
@@ -26,19 +37,14 @@ int main() {
curs_set(0); // hide cursor
keypad(stdscr,TRUE);
- endwin();
- b.goToSite("gemini://tlgs.one");
+ b.goToSite("gemini://tlgs.one/");
auto current = b.renderSite();
- std::cout << b.getCurrentSite()->getBody() << std::endl;
- std::cout << "OTHER OTHER" << std::endl;
- std::cout << current << std::endl;
- return 0;
+ current = removeNonAscii(current);
auto strLs = stringToList(current);
int input;
int y = 0;
int x = 0;
- bool first = true;
while( input != 'q') {
if(input == KEY_DOWN) {
@@ -57,7 +63,7 @@ int main() {
y = std::max(0,y);
- y = std::min(y,lowestPos(strLs));
+ y = std::max(0,std::min(y,lowestPos(strLs)));
draw(y, strLs);