Added way to get Console size, in ostd::Utils class
This commit is contained in:
parent
9ab0cad97f
commit
09a0cec35d
5 changed files with 76 additions and 18 deletions
|
|
@ -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 <unistd.h>
|
||||
#include <term.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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" } }
|
||||
};
|
||||
|
|
|
|||
|
|
@ -170,7 +170,11 @@ namespace ostd
|
|||
static std::vector<std::filesystem::path> 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;
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
1743
|
||||
1758
|
||||
|
|
|
|||
Loading…
Reference in a new issue