commit 063be45cf07e14e76fd9f24a4ddd887bfd973d68
parent 8ff82482b62d9bb24c16da6000a9bf27cfe8b489
Author: Andrew Laack <andrew@laack.co>
Date: Wed, 23 Sep 2026 17:03:36 -0500
basic support for all types (not rigorous
Diffstat:
10 files changed, 198 insertions(+), 68 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,5 +1,5 @@
build:
- g++ -g src/main.cpp src/preformatted.cpp src/format-switch.cpp src/cache.cpp src/link.cpp src/plaintext.cpp src/site.cpp src/utils.cpp src/gemini-client.cpp src/browser.cpp src/heading.cpp -lssl -lcrypto -lncursesw -o browser.out
+ g++ -g src/main.cpp src/quote.cpp src/list-item.cpp src/preformatted.cpp src/format-switch.cpp src/cache.cpp src/link.cpp src/plaintext.cpp src/site.cpp src/utils.cpp src/gemini-client.cpp src/browser.cpp src/heading.cpp -lssl -lcrypto -lncursesw -o browser.out
install:
echo "Not implemented"
@@ -8,13 +8,19 @@ clean:
echo "Not implemented"
browser-test:
- g++ tests/browser-test.cpp src/preformatted.cpp src/format-switch.cpp src/heading.cpp src/cache.cpp src/plaintext.cpp src/browser.cpp src/link.cpp src/site.cpp src/utils.cpp src/gemini-client.cpp -lCatch2Main -lCatch2 -lssl -lcrypto -o test.out
+ g++ tests/browser-test.cpp src/quote.cpp src/list-item.cpp src/preformatted.cpp src/format-switch.cpp src/heading.cpp src/cache.cpp src/plaintext.cpp src/browser.cpp src/link.cpp src/site.cpp src/utils.cpp src/gemini-client.cpp -lCatch2Main -lCatch2 -lssl -lcrypto -o test.out
./test.out
rm test.out
fetch-test:
- g++ tests/fetch-test.cpp src/link.cpp src/preformatted.cpp src/format-switch.cpp src/heading.cpp src/cache.cpp src/site.cpp src/plaintext.cpp src/utils.cpp src/gemini-client.cpp -lCatch2Main -lCatch2 -lssl -lcrypto -o test.out
+ g++ tests/fetch-test.cpp src/quote.cpp src/list-item.cpp src/link.cpp src/preformatted.cpp src/format-switch.cpp src/heading.cpp src/cache.cpp src/site.cpp src/plaintext.cpp src/utils.cpp src/gemini-client.cpp -lCatch2Main -lCatch2 -lssl -lcrypto -o test.out
./test.out
rm test.out
-test: browser-test fetch-test
+pure-test:
+ g++ tests/pure-test.cpp src/quote.cpp src/list-item.cpp src/link.cpp src/preformatted.cpp src/format-switch.cpp src/heading.cpp src/cache.cpp src/site.cpp src/plaintext.cpp src/utils.cpp src/gemini-client.cpp -lCatch2Main -lCatch2 -lssl -lcrypto -o test.out
+ ./test.out
+ rm test.out
+
+
+test: pure-test browser-test fetch-test
diff --git a/include/line.hpp b/include/line.hpp
@@ -10,7 +10,9 @@ enum LineType {
H2,
H3,
FORMAT_SWITCH,
- PREFORMATTED
+ PREFORMATTED,
+ QUOTE,
+ LIST_ITEM
};
class Line {
diff --git a/include/list-item.hpp b/include/list-item.hpp
@@ -0,0 +1,13 @@
+#pragma once
+#include "line.hpp"
+
+class ListItem : public Line {
+ private:
+ std::string text = "";
+ public:
+ ListItem(std::string text);
+ std::string textToDraw() override;
+ int getColor() override;
+ LineType type() override;
+ bool isBold() override;
+};
diff --git a/include/quote.hpp b/include/quote.hpp
@@ -0,0 +1,13 @@
+#pragma once
+#include "line.hpp"
+
+class Quote : public Line {
+ private:
+ std::string text = "";
+ public:
+ Quote(std::string text);
+ std::string textToDraw() override;
+ int getColor() override;
+ LineType type() override;
+ bool isBold() override;
+};
diff --git a/src/list-item.cpp b/src/list-item.cpp
@@ -0,0 +1,21 @@
+#include "../include/list-item.hpp"
+
+ListItem::ListItem(std::string input) {
+ text = input;
+}
+
+std::string ListItem::textToDraw() {
+ return text + "\n";
+}
+
+int ListItem::getColor() {
+ return 15;
+}
+
+LineType ListItem::type() {
+ return LIST_ITEM;
+}
+
+bool ListItem::isBold() {
+ return false;
+}
diff --git a/src/preformatted.cpp b/src/preformatted.cpp
@@ -14,7 +14,7 @@ int Preformatted::getColor() {
}
LineType Preformatted::type() {
- return PLAINTEXT;
+ return PREFORMATTED;
}
bool Preformatted::isBold() {
diff --git a/src/quote.cpp b/src/quote.cpp
@@ -0,0 +1,22 @@
+#include "../include/quote.hpp"
+#include <ncurses.h>
+
+Quote::Quote(std::string input) {
+ text = input;
+}
+
+std::string Quote::textToDraw() {
+ return text + "\n";
+}
+
+int Quote::getColor() {
+ return COLOR_MAGENTA;
+}
+
+LineType Quote::type() {
+ return QUOTE;
+}
+
+bool Quote::isBold() {
+ return false;
+}
diff --git a/src/utils.cpp b/src/utils.cpp
@@ -1,4 +1,6 @@
#include "../include/utils.hpp"
+#include "../include/list-item.hpp"
+#include "../include/quote.hpp"
#include "../include/heading.hpp"
#include "../include/link.hpp"
#include "../include/format-switch.hpp"
@@ -93,8 +95,19 @@ Line* lineToLine(std::string input, std::optional<uri> prior, int linkCount, boo
if(input.substr(0,1) == "#") {
Heading* hd = new Heading{input};
return hd;
- return new Plaintext{input};
}
+
+ if(input.substr(0,1) == ">") {
+ Quote* qt= new Quote{input};
+ return qt;
+ }
+ if(input.substr(0,1) == "*") {
+ ListItem* li= new ListItem{input};
+ return li;
+ }
+
+
+ return new Plaintext{input};
} else {
return new Preformatted{input};
}
diff --git a/tests/browser-test.cpp b/tests/browser-test.cpp
@@ -8,7 +8,6 @@
TEST_CASE( "Basic navigation" ) {
-
Browser b{};
b.goToSite("file:///home/andrew/gitRepos/gemini-browser/tests/sites/basic.gmi", true);
REQUIRE(b.getCurrentSite()->getBody() == readFileToString("tests/sites/basic.gmi"));
@@ -26,63 +25,3 @@ TEST_CASE( "Local filesystem relative navigation" ) {
REQUIRE(b.getCurrentSite()->getBody() == readFileToString("tests/sites/basic_2.gmi"));
}
-
-TEST_CASE("Test trivial line breaking") {
- std::vector<std::pair<std::string, TextRender>> strLs {};
- for(int i = 0; i < 10; ++i) {
- std::pair<std::string, TextRender> current {"this is a simple test line", TextRender{10,false}};
- strLs.push_back(current);
- }
- auto result = breakLines(strLs, 10);
- REQUIRE(result.size() == 30);
-}
-
-static std::string charset = "abc defghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
-
-TEST_CASE("Test width invariant") {
-
- std::vector<std::pair<std::string, TextRender>> strLs {};
-
- srand(std::time(NULL));
-
- for(int i = 0; i < 10000; ++i) {
- std::string strRnd;
- int ub = rand() % 10000;
- for(int x = 0; x < ub; ++x) {
- strRnd += charset[rand() % charset.length()];
- }
- std::pair<std::string, TextRender> current {strRnd, TextRender{10, false}};
- strLs.push_back(current);
- }
-
- auto result = breakLines(strLs, 80);
-
- for(auto& res: result) {
- REQUIRE(res.first.size() <= 80);
- }
-
-}
-
-TEST_CASE("Test lots of spaces") {
-
- std::vector<std::pair<std::string, TextRender>> strLs {};
-
- srand(std::time(NULL));
-
- for(int i = 0; i < 10; ++i) {
- std::string strRnd;
- int ub = rand() % 10000;
- for(int x = 0; x < ub; ++x) {
- strRnd += ' ';
- }
- std::pair<std::string, TextRender> current {strRnd, TextRender{10, false}};
- strLs.push_back(current);
- }
-
- auto result = breakLines(strLs, 80);
-
- for(auto& res: result) {
- REQUIRE(res.first.size() <= 80);
- }
-
-}
diff --git a/tests/pure-test.cpp b/tests/pure-test.cpp
@@ -0,0 +1,101 @@
+// Testing pure functions
+#include <catch2/catch_test_macros.hpp>
+#include <cstdlib>
+#include <ctime>
+#include <iostream>
+#include <optional>
+#include <utility>
+#include "../include/browser.hpp"
+#include "../include/utils.hpp"
+
+
+TEST_CASE("Test trivial line breaking") {
+ std::vector<std::pair<std::string, TextRender>> strLs {};
+ for(int i = 0; i < 10; ++i) {
+ std::pair<std::string, TextRender> current {"this is a simple test line", TextRender{10,false}};
+ strLs.push_back(current);
+ }
+ auto result = breakLines(strLs, 10);
+ REQUIRE(result.size() == 30);
+}
+
+static std::string charset = "abc defghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
+
+TEST_CASE("Test width invariant") {
+
+ std::vector<std::pair<std::string, TextRender>> strLs {};
+
+ srand(std::time(NULL));
+
+ for(int i = 0; i < 10000; ++i) {
+ std::string strRnd;
+ int ub = rand() % 10000;
+ for(int x = 0; x < ub; ++x) {
+ strRnd += charset[rand() % charset.length()];
+ }
+ std::pair<std::string, TextRender> current {strRnd, TextRender{10, false}};
+ strLs.push_back(current);
+ }
+
+ auto result = breakLines(strLs, 80);
+
+ for(auto& res: result) {
+ REQUIRE(res.first.size() <= 80);
+ }
+
+}
+
+TEST_CASE("Test lots of spaces") {
+
+ std::vector<std::pair<std::string, TextRender>> strLs {};
+
+ srand(std::time(NULL));
+
+ for(int i = 0; i < 10; ++i) {
+ std::string strRnd;
+ int ub = rand() % 10000;
+ for(int x = 0; x < ub; ++x) {
+ strRnd += ' ';
+ }
+ std::pair<std::string, TextRender> current {strRnd, TextRender{10, false}};
+ strLs.push_back(current);
+ }
+
+ auto result = breakLines(strLs, 80);
+
+ for(auto& res: result) {
+ REQUIRE(res.first.size() <= 80);
+ }
+
+}
+
+TEST_CASE("Test normal line classification") {
+ auto res1 = lineToLine("", std::nullopt, -1, false);
+ REQUIRE(res1->type() == PLAINTEXT);
+
+ auto res2 = lineToLine("", std::nullopt, -1, true);
+ REQUIRE(res2->type() == PREFORMATTED);
+
+ auto res3 = lineToLine("=> gemini://laack.co", std::nullopt, 1, false);
+ REQUIRE(res3->type() == LINK);
+
+ auto res4 = lineToLine("```", std::nullopt, 1, false);
+ REQUIRE(res4->type() == FORMAT_SWITCH);
+
+ auto res5 = lineToLine("# H1 Heading", std::nullopt, 1, false);
+ REQUIRE(res5->type() == H1);
+
+ auto res6 = lineToLine("## H2 Heading", std::nullopt, 1, false);
+ REQUIRE(res6->type() == H2);
+
+ auto res7 = lineToLine("### H3 Heading", std::nullopt, 1, false);
+ REQUIRE(res7->type() == H3);
+
+ auto res8 = lineToLine("> test quote", std::nullopt, 1, false);
+ REQUIRE(res8->type() == QUOTE);
+
+ auto res9 = lineToLine("* test li", std::nullopt, 1, false);
+ REQUIRE(res9->type() == LIST_ITEM);
+
+
+}