commit e357bcbbb0cc23129c1719ae38819fb4a46c0c1e
parent f7460d25aca1fc80918e79f833667105631b9447
Author: Andrew Laack <andrew@laack.co>
Date: Wed, 30 Sep 2026 13:32:54 -0500
Refactor passing lines / cols
Diffstat:
5 files changed, 282 insertions(+), 164 deletions(-)
diff --git a/TODO.txt b/TODO.txt
@@ -141,3 +141,18 @@
---
- refactoring so that everything can be changed via function inputs (no macros / globals / limit env)
+- be able to edit the url
+- better testing environment
+ - setup my own stuff
+ - faux search engine
+ - status code checkers, stuff like that
+
+---
+
+- benchmark scrolling on large sites
+ - gemini://rawtext.club/~/samhunter/folklore/esr_jargon_file.txt
+ - very slow.
+
+---
+
+- benchmarking
diff --git a/include/render.hpp b/include/render.hpp
@@ -25,8 +25,10 @@ struct DrawState {
std::string userInput;
std::string metaLine;
bool toLowest = false;
+ int columns;
+ int lines;
};
-bool mainLoop(DrawState& ds, Browser& b, int input);
+bool mainLoop(DrawState& ds, Browser& b, int input, int cols, int lines);
void tryVisitSite(DrawState& ds , Browser& b, std::string site);
void initColors();
diff --git a/src/main.cpp b/src/main.cpp
@@ -50,7 +50,7 @@ int main(int argc, char** argv) {
int input = 0;
while(true) {
- bool continueExecution = mainLoop(ds,b,input);
+ bool continueExecution = mainLoop(ds,b,input, COLS,LINES);
if(!continueExecution) {
break;
}
diff --git a/src/render.cpp b/src/render.cpp
@@ -28,8 +28,8 @@
-int lowestPos(std::vector<std::pair<std::string, TextRender>>& strLs) {
- return (strLs.size() - (LINES - 2)) + 1; // this gives us two new lines at the end because the last line should contain a \n.
+int lowestPos(std::vector<std::pair<std::string, TextRender>>& strLs, DrawState& ds) {
+ return (strLs.size() - (ds.lines - 2)) + 1; // this gives us two new lines at the end because the last line should contain a \n.
}
bool isValidUserInput(int uinput) {
@@ -48,23 +48,23 @@ void initColors() {
}
}
-void drawInputBox(std::string text, std::string userInput) {
+void drawInputBox(std::string text, std::string userInput, DrawState& ds) {
- move(LINES/2-1, COLS/4);
+ move(ds.lines/2-1, ds.columns/4);
attron(COLOR_PAIR(COLOR_CYAN+1));
- for(int i = 0; i < COLS/2; ++i) {
+ for(int i = 0; i < ds.columns/2; ++i) {
addstr("-");
}
- move(LINES/2 + 1, COLS/4);
- for(int i = 0; i < COLS/2; ++i) {
+ move(ds.lines/2 + 1, ds.columns/4);
+ for(int i = 0; i < ds.columns/2; ++i) {
addstr("-");
}
attroff(COLOR_PAIR(COLOR_CYAN+1));
int userInputSize = userInput.size();
- int width = COLS/2;
+ int width = ds.columns/2;
if((int)text.size() >= width) {
text = text.substr(0,width-6) + "...: ";
@@ -87,7 +87,7 @@ void drawInputBox(std::string text, std::string userInput) {
}
}
- move(LINES/2, COLS/4);
+ move(ds.lines/2, ds.columns/4);
addstr(text.c_str());
addstr(userTextToRender.c_str());
@@ -97,12 +97,12 @@ uint64_t getCurrentTime() {
}
void draw(DrawState& ds) {
- if(COLS < 20) {
+ if(ds.columns < 20) {
erase();
addstr("Screen width too small.");
return;
}
- if(LINES < 3) {
+ if(ds.lines < 3) {
erase();
addstr("Screen height too small.");
return;
@@ -114,31 +114,31 @@ void draw(DrawState& ds) {
ds.prior = ds.bPtr->renderSite();
}
- auto current = breakLines(ds.prior, std::min(COLS, maxWidth), COLS);
+ auto current = breakLines(ds.prior, std::min(ds.columns, maxWidth), ds.columns);
sanitizeCharactersToDraw(current);
if(ds.toLowest) {
- ds.y = lowestPos(current);
+ ds.y = lowestPos(current, ds);
ds.toLowest = false;
}
- ds.y = std::max(0,std::min(ds.y,lowestPos(current)));
+ ds.y = std::max(0,std::min(ds.y,lowestPos(current,ds)));
erase();
- move(0,(COLS / 2) - ((int)ds.header.size() / 2) );
+ move(0,(ds.columns / 2) - ((int)ds.header.size() / 2) );
attron(A_BOLD);
- if((int)ds.header.size() < COLS) {
+ if((int)ds.header.size() < ds.columns) {
addstr(ds.header.c_str());
} else {
- addstr((ds.header.substr(0,COLS-3) + "...").c_str());
+ addstr((ds.header.substr(0,ds.columns-3) + "...").c_str());
}
attroff(A_BOLD);
- addstr(std::string(COLS, ' ').c_str());
+ addstr(std::string(ds.columns, ' ').c_str());
- for(int i = ds.y; i - ds.y < LINES - 2 && i < (int)current.size(); ++i) {
+ for(int i = ds.y; i - ds.y < ds.lines - 2 && i < (int)current.size(); ++i) {
move(i - ds.y + 2, 0);
attron(COLOR_PAIR(current[i].second.color + 1));
@@ -155,20 +155,20 @@ void draw(DrawState& ds) {
if (ds.handleRedirect) {
std::string toShow = "Redirect to \"" + ds.metaLine + "\" (y/n): ";
- drawInputBox(toShow, ds.redirInput);
+ drawInputBox(toShow, ds.redirInput, ds);
}
if(ds.handleInput) {
if(ds.metaLine != "") {
- drawInputBox(ds.metaLine + ": ", ds.userInput);
+ drawInputBox(ds.metaLine + ": ", ds.userInput, ds);
} else {
- drawInputBox("Input: ", ds.userInput);
+ drawInputBox("Input: ", ds.userInput, ds);
}
}
if (ds.handleOpenOther) {
- drawInputBox("Destination / Link Number: ", ds.openOtherInput);
+ drawInputBox("Destination / Link Number: ", ds.openOtherInput, ds);
}
if(ds.issueText != "") {
@@ -280,7 +280,10 @@ void tryVisitSite(DrawState& ds , Browser& b, std::string site) {
}
}
-bool mainLoop(DrawState& ds, Browser& b, int input) {
+bool mainLoop(DrawState& ds, Browser& b, int input, int cols, int lines) {
+
+ ds.lines = lines;
+ ds.columns = cols;
if(ds.handleOpenOther) {
openPageHandler(ds,input);
@@ -304,7 +307,7 @@ bool mainLoop(DrawState& ds, Browser& b, int input) {
}
ds.openOtherInput = "";
}
- mainLoop(ds, b, KEY_RESIZE);
+ mainLoop(ds, b, KEY_RESIZE, ds.columns, ds.lines);
} else {
auto* clk = b.getCurrentLink();
ds.header = clk->getLinkDestination().to_string();
@@ -318,13 +321,13 @@ bool mainLoop(DrawState& ds, Browser& b, int input) {
} else if (ds.handleRedirect) {
handleRedir(ds, input, b);
if(!ds.handleRedirect) {
- mainLoop(ds, b, KEY_RESIZE);
+ mainLoop(ds, b, KEY_RESIZE, ds.columns, ds.lines);
}
return true;
} else if (ds.handleInput) {
handleUserInput(ds, b, input);
if(!ds.handleInput) {
- mainLoop(ds, b, KEY_RESIZE);
+ mainLoop(ds, b, KEY_RESIZE, ds.columns, ds.lines);
}
return true;
}
@@ -343,9 +346,9 @@ bool mainLoop(DrawState& ds, Browser& b, int input) {
} else if (input == 'G'){
ds.toLowest = true;
} else if (input == CTRL('d')){
- ds.y += LINES / 2;
+ ds.y += ds.lines / 2;
} else if (input == CTRL('u')) {
- ds.y -= LINES / 2;
+ ds.y -= ds.lines / 2;
} else if (input == 'r' || input == CTRL('r')){
b.refresh();
} else if(input == 'f') {
@@ -359,7 +362,7 @@ bool mainLoop(DrawState& ds, Browser& b, int input) {
ds.y = 0; // todo: make this part of state somewhere.
} else if(input == 'o') {
ds.handleOpenOther = true;
- mainLoop(ds, b, KEY_RESIZE);
+ mainLoop(ds, b, KEY_RESIZE,ds.columns, ds.lines);
} else if (input == 'e'){
std::string editor = getEditor();
std::string dl = b.tryDownloadPage(OUT_LOCATION);
@@ -385,7 +388,7 @@ bool mainLoop(DrawState& ds, Browser& b, int input) {
ds.handleInput = true;
ds.userInput = "";
- mainLoop(ds, b, KEY_RESIZE);
+ mainLoop(ds, b, KEY_RESIZE, ds.columns, ds.lines);
} else if (b.getCurrentSite()->getStatusCode() >= 30 && b.getCurrentSite()->getStatusCode() <= 39 && !ds.handleRedirect){
auto* st = b.getCurrentSite();
@@ -395,7 +398,7 @@ bool mainLoop(DrawState& ds, Browser& b, int input) {
ds.redirInput = "";
ds.handleRedirect = true;
- mainLoop(ds, b, KEY_RESIZE);
+ mainLoop(ds, b, KEY_RESIZE, ds.columns, ds.lines);
}
}
diff --git a/tests/puppet-test.cpp b/tests/puppet-test.cpp
@@ -41,153 +41,183 @@ std::string genAlNumNlSp(const int len) {
// Puppet entire browser
TEST_CASE("q quits session immediately") {
- Browser b {};
+ Browser* bPtr = new Browser {};
+ Browser& b = *bPtr;
DrawState ds {};
- REQUIRE_FALSE(mainLoop(ds, b, 'q'));
+ ds.bPtr = bPtr;
+ REQUIRE_FALSE(mainLoop(ds, b, 'q',0,0));
+ delete bPtr;
}
TEST_CASE("RESIZE falls through and returns") {
- Browser b {};
+ Browser* bPtr = new Browser {};
+ Browser& b = *bPtr;
DrawState ds {};
- REQUIRE(mainLoop(ds, b, KEY_RESIZE));
+ ds.bPtr = bPtr;
+ REQUIRE(mainLoop(ds, b, KEY_RESIZE,0,0));
+ delete bPtr;
}
TEST_CASE("Open page handler returns") {
- Browser b {};
+ Browser* bPtr = new Browser {};
+ Browser& b = *bPtr;
DrawState ds {};
- REQUIRE(mainLoop(ds, b, 'o'));
+ ds.bPtr = bPtr;
+ REQUIRE(mainLoop(ds, b, 'o',0,0));
+ delete bPtr;
}
TEST_CASE("Open page and navigate to site") {
- Browser b {};
+
+ Browser* bPtr = new Browser {};
+ Browser& b = *bPtr;
DrawState ds {};
- REQUIRE(mainLoop(ds, b, 'o'));
- REQUIRE(mainLoop(ds, b, 'l'));
- REQUIRE(mainLoop(ds, b, 'a'));
- REQUIRE(mainLoop(ds, b, 'a'));
- REQUIRE(mainLoop(ds, b, 'c'));
- REQUIRE(mainLoop(ds, b, 'k'));
- REQUIRE(mainLoop(ds, b, '.'));
- REQUIRE(mainLoop(ds, b, 'c'));
- REQUIRE(mainLoop(ds, b, 'o'));
- REQUIRE(mainLoop(ds, b, '\n'));
+ ds.bPtr = bPtr;
+ REQUIRE(mainLoop(ds, b, 'o',0,0));
+ REQUIRE(mainLoop(ds, b, 'l',0,0));
+ REQUIRE(mainLoop(ds, b, 'a',0,0));
+ REQUIRE(mainLoop(ds, b, 'a',0,0));
+ REQUIRE(mainLoop(ds, b, 'c',0,0));
+ REQUIRE(mainLoop(ds, b, 'k',0,0));
+ REQUIRE(mainLoop(ds, b, '.',0,0));
+ REQUIRE(mainLoop(ds, b, 'c',0,0));
+ REQUIRE(mainLoop(ds, b, 'o',0,0));
+ REQUIRE(mainLoop(ds, b, '\n',0,0));
REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://laack.co");
+ delete bPtr;
}
TEST_CASE("Open page and search the web") {
- Browser b {};
+ Browser* bPtr = new Browser {};
+ Browser& b = *bPtr;
DrawState ds {};
- REQUIRE(mainLoop(ds, b, 'o'));
+ ds.bPtr = bPtr;
+ REQUIRE(mainLoop(ds, b, 'o',0,0));
std::string rnd = genRandom(10);
INFO(rnd);
for(auto& ch : rnd) {
- REQUIRE(mainLoop(ds, b, ch));
+ REQUIRE(mainLoop(ds, b, ch,0,0));
}
- REQUIRE(mainLoop(ds, b, '\n'));
+ REQUIRE(mainLoop(ds, b, '\n',0,0));
REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://tlgs.one/search?" + urlEncode(rnd));
+ delete bPtr;
}
TEST_CASE("Open page after backspacing character") {
- Browser b {};
+ Browser* bPtr = new Browser {};
+ Browser& b = *bPtr;
DrawState ds {};
- REQUIRE(mainLoop(ds, b, 'o'));
- REQUIRE(mainLoop(ds, b, 'l'));
- REQUIRE(mainLoop(ds, b, 'a'));
- REQUIRE(mainLoop(ds, b, 'a'));
- REQUIRE(mainLoop(ds, b, 'a'));
- REQUIRE(mainLoop(ds, b, KEY_BACKSPACE));
- REQUIRE(mainLoop(ds, b, 'c'));
- REQUIRE(mainLoop(ds, b, 'k'));
- REQUIRE(mainLoop(ds, b, '.'));
- REQUIRE(mainLoop(ds, b, 'c'));
- REQUIRE(mainLoop(ds, b, 'o'));
- REQUIRE(mainLoop(ds, b, '\n'));
+ ds.bPtr = bPtr;
+ REQUIRE(mainLoop(ds, b, 'o',0,0));
+ REQUIRE(mainLoop(ds, b, 'l',0,0));
+ REQUIRE(mainLoop(ds, b, 'a',0,0));
+ REQUIRE(mainLoop(ds, b, 'a',0,0));
+ REQUIRE(mainLoop(ds, b, 'a',0,0));
+ REQUIRE(mainLoop(ds, b, KEY_BACKSPACE,0,0));
+ REQUIRE(mainLoop(ds, b, 'c',0,0));
+ REQUIRE(mainLoop(ds, b, 'k',0,0));
+ REQUIRE(mainLoop(ds, b, '.',0,0));
+ REQUIRE(mainLoop(ds, b, 'c',0,0));
+ REQUIRE(mainLoop(ds, b, 'o',0,0));
+ REQUIRE(mainLoop(ds, b, '\n',0,0));
REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://laack.co");
+ delete bPtr;
}
TEST_CASE("Cancel 'o' menu by pressing escape") {
- Browser b {};
+ Browser* bPtr = new Browser {};
+ Browser& b = *bPtr;
DrawState ds {};
- REQUIRE(mainLoop(ds, b, 'o'));
- REQUIRE(mainLoop(ds, b, 'l'));
- REQUIRE(mainLoop(ds, b, 'a'));
- REQUIRE(mainLoop(ds, b, 'a'));
- REQUIRE(mainLoop(ds, b, 'a'));
- REQUIRE(mainLoop(ds, b, KEY_BACKSPACE));
- REQUIRE(mainLoop(ds, b, 'c'));
- REQUIRE(mainLoop(ds, b, 'k'));
- REQUIRE(mainLoop(ds, b, '.'));
- REQUIRE(mainLoop(ds, b, 'c'));
- REQUIRE(mainLoop(ds, b, 'o'));
- REQUIRE(mainLoop(ds, b, 27)); // escape
+ ds.bPtr = bPtr;
+ REQUIRE(mainLoop(ds, b, 'o',0,0));
+ REQUIRE(mainLoop(ds, b, 'l',0,0));
+ REQUIRE(mainLoop(ds, b, 'a',0,0));
+ REQUIRE(mainLoop(ds, b, 'a',0,0));
+ REQUIRE(mainLoop(ds, b, 'a',0,0));
+ REQUIRE(mainLoop(ds, b, KEY_BACKSPACE,0,0));
+ REQUIRE(mainLoop(ds, b, 'c',0,0));
+ REQUIRE(mainLoop(ds, b, 'k',0,0));
+ REQUIRE(mainLoop(ds, b, '.',0,0));
+ REQUIRE(mainLoop(ds, b, 'c',0,0));
+ REQUIRE(mainLoop(ds, b, 'o',0,0));
+ REQUIRE(mainLoop(ds, b, 27,0,0)); // escape
REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "about://newtab");
+ delete bPtr;
}
TEST_CASE("Handle redirects") {
- Browser b {};
+ Browser* bPtr = new Browser {};
+ Browser& b = *bPtr;
DrawState ds {};
- REQUIRE(mainLoop(ds, b, 'o'));
- REQUIRE(mainLoop(ds, b, 'c'));
- REQUIRE(mainLoop(ds, b, 'o'));
- REQUIRE(mainLoop(ds, b, 'n'));
- REQUIRE(mainLoop(ds, b, 'm'));
- REQUIRE(mainLoop(ds, b, 'a'));
- REQUIRE(mainLoop(ds, b, 'n'));
- REQUIRE(mainLoop(ds, b, '.'));
- REQUIRE(mainLoop(ds, b, 'o'));
- REQUIRE(mainLoop(ds, b, 'r'));
- REQUIRE(mainLoop(ds, b, 'g'));
- REQUIRE(mainLoop(ds, b, '\n'));
+ ds.bPtr = bPtr;
+ REQUIRE(mainLoop(ds, b, 'o',0,0));
+ REQUIRE(mainLoop(ds, b, 'c',0,0));
+ REQUIRE(mainLoop(ds, b, 'o',0,0));
+ REQUIRE(mainLoop(ds, b, 'n',0,0));
+ REQUIRE(mainLoop(ds, b, 'm',0,0));
+ REQUIRE(mainLoop(ds, b, 'a',0,0));
+ REQUIRE(mainLoop(ds, b, 'n',0,0));
+ REQUIRE(mainLoop(ds, b, '.',0,0));
+ REQUIRE(mainLoop(ds, b, 'o',0,0));
+ REQUIRE(mainLoop(ds, b, 'r',0,0));
+ REQUIRE(mainLoop(ds, b, 'g',0,0));
+ REQUIRE(mainLoop(ds, b, '\n',0,0));
REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://conman.org");
- REQUIRE(mainLoop(ds, b, 'y')); // follow redirect
+ REQUIRE(mainLoop(ds, b, 'y',0,0)); // follow redirect
REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://gemini.conman.org/");
+ delete bPtr;
}
TEST_CASE("Handle redirect rejection") {
- Browser b {};
+ Browser* bPtr = new Browser {};
+ Browser& b = *bPtr;
DrawState ds {};
- REQUIRE(mainLoop(ds, b, 'o'));
- REQUIRE(mainLoop(ds, b, 'c'));
- REQUIRE(mainLoop(ds, b, 'o'));
- REQUIRE(mainLoop(ds, b, 'n'));
- REQUIRE(mainLoop(ds, b, 'm'));
- REQUIRE(mainLoop(ds, b, 'a'));
- REQUIRE(mainLoop(ds, b, 'n'));
- REQUIRE(mainLoop(ds, b, '.'));
- REQUIRE(mainLoop(ds, b, 'o'));
- REQUIRE(mainLoop(ds, b, 'r'));
- REQUIRE(mainLoop(ds, b, 'g'));
- REQUIRE(mainLoop(ds, b, '\n'));
+ ds.bPtr = bPtr;
+ REQUIRE(mainLoop(ds, b, 'o',0,0));
+ REQUIRE(mainLoop(ds, b, 'c',0,0));
+ REQUIRE(mainLoop(ds, b, 'o',0,0));
+ REQUIRE(mainLoop(ds, b, 'n',0,0));
+ REQUIRE(mainLoop(ds, b, 'm',0,0));
+ REQUIRE(mainLoop(ds, b, 'a',0,0));
+ REQUIRE(mainLoop(ds, b, 'n',0,0));
+ REQUIRE(mainLoop(ds, b, '.',0,0));
+ REQUIRE(mainLoop(ds, b, 'o',0,0));
+ REQUIRE(mainLoop(ds, b, 'r',0,0));
+ REQUIRE(mainLoop(ds, b, 'g',0,0));
+ REQUIRE(mainLoop(ds, b, '\n',0,0));
REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://conman.org");
- REQUIRE(mainLoop(ds, b, 'n')); // follow redirect
+ REQUIRE(mainLoop(ds, b, 'n',0,0)); // follow redirect
REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "about://newtab");
+ delete bPtr;
}
TEST_CASE("Enter an input") {
- Browser b {};
+ Browser* bPtr = new Browser {};
+ Browser& b = *bPtr;
DrawState ds {};
-
- REQUIRE(mainLoop(ds, b, 'o'));
- REQUIRE(mainLoop(ds, b, 't'));
- REQUIRE(mainLoop(ds, b, 'l'));
- REQUIRE(mainLoop(ds, b, 'g'));
- REQUIRE(mainLoop(ds, b, 's'));
- REQUIRE(mainLoop(ds, b, '.'));
- REQUIRE(mainLoop(ds, b, 'o'));
- REQUIRE(mainLoop(ds, b, 'n'));
- REQUIRE(mainLoop(ds, b, 'e'));
- REQUIRE(mainLoop(ds, b, '\n'));
+ ds.bPtr = bPtr;
+
+ REQUIRE(mainLoop(ds, b, 'o',0,0));
+ REQUIRE(mainLoop(ds, b, 't',0,0));
+ REQUIRE(mainLoop(ds, b, 'l',0,0));
+ REQUIRE(mainLoop(ds, b, 'g',0,0));
+ REQUIRE(mainLoop(ds, b, 's',0,0));
+ REQUIRE(mainLoop(ds, b, '.',0,0));
+ REQUIRE(mainLoop(ds, b, 'o',0,0));
+ REQUIRE(mainLoop(ds, b, 'n',0,0));
+ REQUIRE(mainLoop(ds, b, 'e',0,0));
+ REQUIRE(mainLoop(ds, b, '\n',0,0));
REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://tlgs.one");
- REQUIRE(mainLoop(ds,b,'o'));
- REQUIRE(mainLoop(ds,b,'2'));
- REQUIRE(mainLoop(ds, b, '\n'));
+ REQUIRE(mainLoop(ds,b,'o',0,0));
+ REQUIRE(mainLoop(ds,b,'2',0,0));
+ REQUIRE(mainLoop(ds, b, '\n',0,0));
REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://tlgs.one/search");
@@ -196,34 +226,37 @@ TEST_CASE("Enter an input") {
INFO(rnd);
for(auto& ch : rnd) {
- REQUIRE(mainLoop(ds, b, ch));
+ REQUIRE(mainLoop(ds, b, ch,0,0));
}
- REQUIRE(mainLoop(ds, b, '\n'));
+ REQUIRE(mainLoop(ds, b, '\n',0,0));
REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://tlgs.one/search?" + urlEncode(rnd));
+ delete bPtr;
}
TEST_CASE("Enter an input and then cancel") {
- Browser b {};
+ Browser* bPtr = new Browser {};
+ Browser& b = *bPtr;
DrawState ds {};
-
- REQUIRE(mainLoop(ds, b, 'o'));
- REQUIRE(mainLoop(ds, b, 't'));
- REQUIRE(mainLoop(ds, b, 'l'));
- REQUIRE(mainLoop(ds, b, 'g'));
- REQUIRE(mainLoop(ds, b, 's'));
- REQUIRE(mainLoop(ds, b, '.'));
- REQUIRE(mainLoop(ds, b, 'o'));
- REQUIRE(mainLoop(ds, b, 'n'));
- REQUIRE(mainLoop(ds, b, 'e'));
- REQUIRE(mainLoop(ds, b, '\n'));
+ ds.bPtr = bPtr;
+
+ REQUIRE(mainLoop(ds, b, 'o',0,0));
+ REQUIRE(mainLoop(ds, b, 't',0,0));
+ REQUIRE(mainLoop(ds, b, 'l',0,0));
+ REQUIRE(mainLoop(ds, b, 'g',0,0));
+ REQUIRE(mainLoop(ds, b, 's',0,0));
+ REQUIRE(mainLoop(ds, b, '.',0,0));
+ REQUIRE(mainLoop(ds, b, 'o',0,0));
+ REQUIRE(mainLoop(ds, b, 'n',0,0));
+ REQUIRE(mainLoop(ds, b, 'e',0,0));
+ REQUIRE(mainLoop(ds, b, '\n',0,0));
REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://tlgs.one");
- REQUIRE(mainLoop(ds,b,'o'));
- REQUIRE(mainLoop(ds,b,'2'));
- REQUIRE(mainLoop(ds, b, '\n'));
+ REQUIRE(mainLoop(ds,b,'o',0,0));
+ REQUIRE(mainLoop(ds,b,'2',0,0));
+ REQUIRE(mainLoop(ds, b, '\n',0,0));
REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://tlgs.one/search");
@@ -232,12 +265,13 @@ TEST_CASE("Enter an input and then cancel") {
INFO(rnd);
for(auto& ch : rnd) {
- REQUIRE(mainLoop(ds, b, ch));
+ REQUIRE(mainLoop(ds, b, ch,0,0));
}
- REQUIRE(mainLoop(ds, b, 27)); // escape
+ REQUIRE(mainLoop(ds, b, 27,0,0)); // escape
REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://tlgs.one");
+ delete bPtr;
}
@@ -245,20 +279,23 @@ TEST_CASE("Only return false on 'q' entry when not using input boxes, never cras
setenv("EDITOR", "test" , 1);
rc::check("Never return false / fail except with input 'q'", [] (std::string st) {
- Browser b {};
+ Browser* bPtr = new Browser {};
+ Browser& b = *bPtr;
DrawState ds {};
+ ds.bPtr = bPtr;
RC_LOG(st);
for(auto& cur : st) {
if(cur == 'q') {
if(!ds.handleInput && !ds.handleOpenOther && !ds.handleRedirect) {
- REQUIRE_FALSE(mainLoop(ds,b,cur));
+ REQUIRE_FALSE(mainLoop(ds,b,cur,0,0));
} else {
- REQUIRE(mainLoop(ds,b,cur));
+ REQUIRE(mainLoop(ds,b,cur,0,0));
}
} else {
- REQUIRE(mainLoop(ds,b,cur));
+ REQUIRE(mainLoop(ds,b,cur,0,0));
}
}
+ delete bPtr;
});
}
@@ -266,21 +303,26 @@ TEST_CASE("Only return false on 'q' entry when not using input boxes, alphanumer
setenv("EDITOR", "test" , 1);
for(int i = 0; i < 10; ++i) {
- Browser b {};
+ Browser* bPtr = new Browser {};
+ Browser& b = *bPtr;
+
DrawState ds {};
+ ds.bPtr = bPtr;
std::string st = genAlNumNlSp(rand()%100);
INFO(st);
for(auto& cur : st) {
if(cur == 'q') {
if(!ds.handleInput && !ds.handleOpenOther && !ds.handleRedirect) {
- REQUIRE_FALSE(mainLoop(ds,b,cur));
+ REQUIRE_FALSE(mainLoop(ds,b,cur,0,0));
} else {
- REQUIRE(mainLoop(ds,b,cur));
+ REQUIRE(mainLoop(ds,b,cur,0,0));
}
} else {
- REQUIRE(mainLoop(ds,b,cur));
+ REQUIRE(mainLoop(ds,b,cur,0,0));
}
}
+ delete bPtr;
+
}
}
@@ -291,27 +333,83 @@ TEST_CASE("Open file in editor creates file") {
std::filesystem::remove("/tmp/foreseen/laack.co");
- Browser b {};
- DrawState ds {};
+ Browser* bPtr = new Browser {};
+ Browser& b = *bPtr;
- REQUIRE(mainLoop(ds, b, 'o'));
- REQUIRE(mainLoop(ds, b, 'l'));
- REQUIRE(mainLoop(ds, b, 'a'));
- REQUIRE(mainLoop(ds, b, 'a'));
- REQUIRE(mainLoop(ds, b, 'c'));
- REQUIRE(mainLoop(ds, b, 'k'));
- REQUIRE(mainLoop(ds, b, '.'));
- REQUIRE(mainLoop(ds, b, 'c'));
- REQUIRE(mainLoop(ds, b, 'o'));
- REQUIRE(mainLoop(ds, b, '\n'));
+ DrawState ds {};
+ ds.bPtr = bPtr;
+
+ REQUIRE(mainLoop(ds, b, 'o',0,0));
+ REQUIRE(mainLoop(ds, b, 'l',0,0));
+ REQUIRE(mainLoop(ds, b, 'a',0,0));
+ REQUIRE(mainLoop(ds, b, 'a',0,0));
+ REQUIRE(mainLoop(ds, b, 'c',0,0));
+ REQUIRE(mainLoop(ds, b, 'k',0,0));
+ REQUIRE(mainLoop(ds, b, '.',0,0));
+ REQUIRE(mainLoop(ds, b, 'c',0,0));
+ REQUIRE(mainLoop(ds, b, 'o',0,0));
+ REQUIRE(mainLoop(ds, b, '\n',0,0));
REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://laack.co");
- REQUIRE(mainLoop(ds,b,'e'));
+ REQUIRE(mainLoop(ds,b,'e',0,0));
REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://laack.co");
REQUIRE(std::filesystem::exists("/tmp/foreseen/laack.co"));
REQUIRE(std::filesystem::remove("/tmp/foreseen/laack.co"));
+ delete bPtr;
+
+}
+
+TEST_CASE("Basic usage with specified line and col count") {
+
+ setenv("EDITOR", "test" , 1);
+
+ Browser* bPtr = new Browser {};
+ Browser& b = *bPtr;
+
+ DrawState ds {};
+ ds.bPtr = bPtr;
+
+ REQUIRE(mainLoop(ds, b, 'o',100,100));
+ REQUIRE(mainLoop(ds, b, 'l',100,100));
+ REQUIRE(mainLoop(ds, b, 'a',100,100));
+ REQUIRE(mainLoop(ds, b, 'a',100,100));
+ REQUIRE(mainLoop(ds, b, 'c',100,100));
+ REQUIRE(mainLoop(ds, b, 'k',100,100));
+ REQUIRE(mainLoop(ds, b, '.',100,100));
+ REQUIRE(mainLoop(ds, b, 'c',100,100));
+ REQUIRE(mainLoop(ds, b, 'o',100,100));
+ REQUIRE(mainLoop(ds, b, '\n',100,100));
+ REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "gemini://laack.co");
+ delete bPtr;
+}
+
+TEST_CASE("Basic usage with small screen sizes") {
+
+ setenv("EDITOR", "test" , 1);
+
+ for(int i = 0; i < 10; ++i) {
+ int x = rand() % 25;
+ int y = rand() % 10;
+ Browser* bPtr = new Browser {};
+ Browser& b = *bPtr;
+ DrawState ds {};
+ ds.bPtr = bPtr;
+ std::string st = "file:///home/andrew/gitRepos/gemini-browser/tests/sites/all_line_types.gmi";
+
+
+ REQUIRE(mainLoop(ds, b, 'o',x,y));
+
+ for(auto& ch: st) {
+ REQUIRE(mainLoop(ds, b, ch,x,y));
+ }
+
+ REQUIRE(mainLoop(ds, b, '\n',x,y));
+
+ REQUIRE(b.getCurrentLink()->getLinkDestination().to_string() == "file:///home/andrew/gitRepos/gemini-browser/tests/sites/all_line_types.gmi");
+ delete bPtr;
+ }
}