From 291ecb302cc7281c254542543a065aec3ba13bb9 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 29 May 2022 08:44:02 +0300 Subject: Autocommit at 29.05.2022 @ 08:44 --- src/Generic/ConsoleInterface/Toolbox.cpp | 6 +++--- src/Generic/ConsoleInterface/Toolbox.hpp | 2 +- src/Models/Table.cpp | 7 +++++++ src/UserInterface/UserInterface.cpp | 2 +- src/main.cpp | 1 + 5 files changed, 13 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Generic/ConsoleInterface/Toolbox.cpp b/src/Generic/ConsoleInterface/Toolbox.cpp index dd88762..af336fe 100644 --- a/src/Generic/ConsoleInterface/Toolbox.cpp +++ b/src/Generic/ConsoleInterface/Toolbox.cpp @@ -46,11 +46,11 @@ void __printTableLine(unsigned columns) { } void __printPadded(const String& str, unsigned width) { - while (str.get_length() - width > 0) { + while (width - str.get_length() > 0) { width--; print(" "); } - print(str.get_cstr()); + std::cout << str.get_cstr(); } /*! \param startNumber The number by which column and row enumeration begins @@ -63,7 +63,7 @@ void __printPadded(const String& str, unsigned width) { * Table is printed until a terminating zero is encountered. * The rows are "calculated" from the columns count and the items length. */ -void table(const List& items, unsigned columns) { +void printTable(const List& items, unsigned columns) { unsigned *colWidths = new unsigned[columns]; for (unsigned i = 0; i < items.get_count(); i++) { if (colWidths[i % columns] < items[i].get_length()) diff --git a/src/Generic/ConsoleInterface/Toolbox.hpp b/src/Generic/ConsoleInterface/Toolbox.hpp index 66d414b..4b59626 100644 --- a/src/Generic/ConsoleInterface/Toolbox.hpp +++ b/src/Generic/ConsoleInterface/Toolbox.hpp @@ -19,7 +19,7 @@ void inputLineBox(char* output, unsigned maxWidth, bool ignore = true); //! Prints a string list as a table -void table(const List& items, unsigned columns); +void printTable(const List& items, unsigned columns); //! Reads user input and stores it template diff --git a/src/Models/Table.cpp b/src/Models/Table.cpp index 70579b4..0d3264e 100644 --- a/src/Models/Table.cpp +++ b/src/Models/Table.cpp @@ -6,11 +6,18 @@ #include Table::Table(unsigned rows, unsigned cols) { + if (rows == 0 || cols == 0) + return; + cells = List>(rows); for (unsigned i = 0; i < rows; i++) cells[i] = List(cols); } +unsigned Table::get_cols() const { + return cells[0].get_count(); +} + bool containsNumber(const char*& str) { while (*str == ' ') str++; return ((*str == '+' || *str == '-') && (*(str + 1) >= '0' && *(str + 1) <= '9')) || diff --git a/src/UserInterface/UserInterface.cpp b/src/UserInterface/UserInterface.cpp index f216afa..b456e97 100644 --- a/src/UserInterface/UserInterface.cpp +++ b/src/UserInterface/UserInterface.cpp @@ -10,7 +10,7 @@ Table* UserInterface::table = nullptr; void UserInterface::com_print(const char* params) { List cells = table->getAllCells(); - table(cells, table.get_cols()); + printTable(cells, table->get_cols()); } void UserInterface::com_edit(const char* params) { diff --git a/src/main.cpp b/src/main.cpp index d620889..a5d47a3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,7 @@ int main() { Table table(5, 5); + table.putCell(0, 0, "Test"); UserInterface ui(&table); ui.run(); } -- cgit v1.3.1-26-gb76a