diff --git a/src/ostd/Console.cpp b/src/ostd/Console.cpp index 75bc073..4ae197c 100644 --- a/src/ostd/Console.cpp +++ b/src/ostd/Console.cpp @@ -30,10 +30,20 @@ void Utils::clearConsole(void) SetConsoleCursorPosition( hStdOut, homeCoords ); } +void Utils::getConsoleSize(int32_t& outRows, int32_t& outColumns) +{ + CONSOLE_SCREEN_BUFFER_INFO csbi; + int columns, rows; + GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi); + outColumns = csbi.srWindow.Right - csbi.srWindow.Left + 1; + outRows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; +} + #elif defined (__LINUX__) || defined(__gnu_linux__) || defined(__linux__) #include #include +#include void Utils::clearConsole(void) { @@ -47,5 +57,28 @@ void Utils::clearConsole(void) putp(tigetstr( "clear" )); } +void Utils::getConsoleSize(int32_t& outRows, int32_t& outColumns) +{ + struct winsize w; + ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); + outRows = w.ws_row; + outColumns = w.ws_col; +} + #endif + +int32_t Utils::getConsoleWidth(void) +{ + int32_t rows = 0, cols = 0; + getConsoleSize(rows, cols); + return cols; +} + +int32_t Utils::getConsoleHeight(void) +{ + int32_t rows = 0, cols = 0; + getConsoleSize(rows, cols); + return rows; +} + } \ No newline at end of file diff --git a/src/ostd/TextStyleParser.cpp b/src/ostd/TextStyleParser.cpp index 46d7798..de6f5de 100644 --- a/src/ostd/TextStyleParser.cpp +++ b/src/ostd/TextStyleParser.cpp @@ -31,15 +31,21 @@ namespace ostd void TextStyleParser::tColor::convertToBackground(void) { StringEditor edit(consoleColor); - if (edit.startsWith("o-")) return; - consoleColor = "o-" + edit.str(); + if (edit.startsWith("o-") || edit.startsWith("ob-")) return; + if (edit.startsWith("b-")) + consoleColor = "o" + edit.str(); + else + consoleColor = "o-" + edit.str(); } void TextStyleParser::tColor::convertToForeground(void) { StringEditor edit(consoleColor); - if (!edit.startsWith("o-")) return; - consoleColor = edit.substr(2); + if (!edit.startsWith("o-") && !edit.startsWith("ob-")) return; + if (edit.startsWith("ob-")) + consoleColor = edit.substr(3); + else + consoleColor = edit.substr(2); } void TextStyleParser::tStyledString::add(const String& str, tColor background, tColor foreground) @@ -85,21 +91,25 @@ namespace ostd { if (insideBlock) return tStyledString(); //TODO: Error, no nested blocks allowed - insideBlock = true; - continue; + if (test_for_block(StringEditor(_styledString).substr(i))) + { + insideBlock = true; + continue; + } } if(c == ']') { - if (!insideBlock) - return tStyledString(); //TODO: Error, closing block without opeinng one - insideBlock = false; - validBlockStart = false; - countBlockStart = 0; - auto blockParseResult = parse_block(blockText, bgcol, fgcol); - if (blockParseResult == eBlockParserReturnValue::InvalidBlock) - return tStyledString(); //TODO: Error, Invalid block - blockText = ""; - continue; + if (insideBlock) + { + insideBlock = false; + validBlockStart = false; + countBlockStart = 0; + auto blockParseResult = parse_block(blockText, bgcol, fgcol); + if (blockParseResult == eBlockParserReturnValue::InvalidBlock) + return tStyledString(); //TODO: Error, Invalid block + blockText = ""; + continue; + } } if (!insideBlock) { @@ -128,6 +138,16 @@ namespace ostd return rstring; } + bool TextStyleParser::test_for_block(const String& block_part) + { + if (block_part.length() < 3) return false; + if (block_part.starts_with("[@@")) + { + return true; + } + return false; + } + TextStyleParser::eBlockParserReturnValue TextStyleParser::parse_block(const String& blockString, tColor& outBackgroundColor, tColor& outForegroundColor) { StringEditor blockEditor = blockString; diff --git a/src/ostd/TextStyleParser.hpp b/src/ostd/TextStyleParser.hpp index d80cac4..eeeead0 100644 --- a/src/ostd/TextStyleParser.hpp +++ b/src/ostd/TextStyleParser.hpp @@ -34,6 +34,7 @@ namespace ostd static tStyledString parse(const StringEditor& styledString, tColor defaultBackgorundColor, tColor defaultForegroundColor); private: + static bool test_for_block(const String& block_part); static eBlockParserReturnValue parse_block(const String& blockString, tColor& outBackgroundColor, tColor& outForegroundColor); static const tColor parse_color(const String& colorStr); @@ -58,7 +59,7 @@ namespace ostd { "yellow", { { 255, 255, 0, 255 }, "yellow" } }, { "brightyellow", { { 255, 255, 170, 255 }, "b-yellow" } }, { "black", { { 0, 0, 0, 255 }, "gray" } }, - { "Gray", { { 50, 50, 50, 255 }, "b-gray" } }, + { "gray", { { 50, 50, 50, 255 }, "b-gray" } }, { "brightgray", { { 150, 150, 150, 255 }, "lgray" } }, { "white", { { 255, 255, 255, 255 }, "white" } } }; diff --git a/src/ostd/Utils.hpp b/src/ostd/Utils.hpp index b85a034..c1ed251 100755 --- a/src/ostd/Utils.hpp +++ b/src/ostd/Utils.hpp @@ -170,7 +170,11 @@ namespace ostd static std::vector listDirectoryRecursive(const String& directoryPath); static int32_t solveIntegerExpression(const String& expr); + static void clearConsole(void); + static void getConsoleSize(int32_t& outRows, int32_t& outColumns); + static int32_t getConsoleWidth(void); + static int32_t getConsoleHeight(void); private: inline static uint64_t s_startTime_ms; diff --git a/tools/build.nr b/tools/build.nr index a41cbc3..11ad811 100755 --- a/tools/build.nr +++ b/tools/build.nr @@ -1 +1 @@ -1743 +1758