diff --git a/src/query/console.cpp b/src/query/console.cpp index e30278134..92838a52d 100644 --- a/src/query/console.cpp +++ b/src/query/console.cpp @@ -3,7 +3,9 @@ // Created by Florijan Stamenkovic on 23.03.17. // +#include #include +#include #include #include "console.hpp" @@ -23,10 +25,12 @@ * Possibly empty. */ std::string ReadLine(const char *prompt) { - char *line_read = readline(prompt); - if (line_read && *line_read) add_history(line_read); - std::string r_val(line_read); - if (line_read) free(line_read); + char *line = readline(prompt); + if (!line) return ""; + + if (*line) add_history(line); + std::string r_val(line); + free(line); return r_val; } @@ -96,8 +100,8 @@ std::string TypedValueToString(const TypedValue &value) { void PrintResults(ResultStreamFaker results) { const std::vector &header = results.GetHeader(); std::vector column_widths(header.size()); - for (int col_ind = 0; col_ind < header.size(); ++col_ind) - column_widths[col_ind] = (int)header[col_ind].size(); + std::transform(header.begin(), header.end(), column_widths.begin(), + [](const auto &s) { return s.size(); }); // convert all the results into strings, and track max column width auto &results_data = results.GetResults(); @@ -147,8 +151,10 @@ void PrintResults(ResultStreamFaker results) { std::cout << "}" << std::endl; } -void query::Console(Dbms &dbms) { - std::cout << "Welcome to *Awesome* Memgraph Console (AMC)" << std::endl; +void query::Repl(Dbms &dbms) { + std::cout + << "Welcome to *Awesome* Memgraph Read Evaluate Print Loop (AM-REPL)" + << std::endl; while (true) { std::string command = ReadLine(">"); if (command.size() == 0) continue; diff --git a/src/query/console.hpp b/src/query/console.hpp index 3a216e318..8b545429b 100644 --- a/src/query/console.hpp +++ b/src/query/console.hpp @@ -13,10 +13,11 @@ namespace query { /** - * Console for interacting with a database + * Read Evaluate Print Loop, + * for interacting with a database * (the active database in the given DBMS). * Immediately starts the user-input loop * and interprets the entered queries. */ -void Console(Dbms &dbms); +void Repl(Dbms &dbms); } diff --git a/tests/manual/console_test.cpp b/tests/manual/console_test.cpp index bd244e753..80647879d 100644 --- a/tests/manual/console_test.cpp +++ b/tests/manual/console_test.cpp @@ -64,6 +64,6 @@ int main(int argc, char *argv[]) { Dbms dbms; fill_db(dbms); - query::Console(dbms); + query::Repl(dbms); return 0; }