utils.hpp (1600B)
1 #pragma once 2 #include <cstdint> 3 #include <filesystem> 4 #include <optional> 5 #include <string> 6 #include <vector> 7 8 #include "../vendor/uri.hpp" 9 #include "line.hpp" 10 11 struct TextRender { 12 uint8_t color; 13 bool isBold : 1; 14 bool shouldFold : 1 = true; // preformatted text doesn't need to be folded. 15 }; 16 17 bool isPrefixed(std::string input, std::string prefix); 18 std::string readFileToString(std::string filePath); 19 bool isWhiteSpace(std::string& line, int idx); 20 std::vector<std::string> stringToList(std::string input); 21 Line* lineToLine(std::string input, std::optional<uri> prior, int linkCount, 22 bool isPreformatted); 23 std::string urlEncode(const std::string& value); 24 std::string getNewTab(); 25 void openUrl(const std::string& url); 26 std::vector<std::pair<std::string, TextRender>> breakLines( 27 std::vector<std::pair<std::string, TextRender>>& strLs, int width, 28 int cols); 29 std::string stripLeadingWhiteSpace(std::string& input); 30 31 // This will over-write the existing file, if relevant. This will not create 32 // directories for you. 33 void writeStringToFile(std::string toWrite, std::string filePath); 34 std::string encodeAsFilename(uri link); 35 std::filesystem::path getHome(); 36 37 enum ReturnType { NUMBER_DESTINATION, STRING_DESTINATION, NO_DESTINATION }; 38 39 struct Destination { 40 int linkNumber; 41 std::string destination; 42 ReturnType t; 43 }; 44 45 Destination handleDestinationResolution(std::string destination, bool isCli); 46 47 void sanitizeCharactersToDraw( 48 std::vector<std::pair<std::string, TextRender>>& strLs); 49 50 bool isSendableIfGeminiUrl(const uri& u); 51 std::string getEditor();