From 3e17bfe4f2e5e64f9528c26b38d4241ca46f1082 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 19 Oct 2009 01:30:37 +0200 Subject: Client: Added support for paged output --- src/Client/UserListCommands.cpp | 75 +++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 36 deletions(-) (limited to 'src/Client/UserListCommands.cpp') diff --git a/src/Client/UserListCommands.cpp b/src/Client/UserListCommands.cpp index 1da2d38..7f2a26b 100644 --- a/src/Client/UserListCommands.cpp +++ b/src/Client/UserListCommands.cpp @@ -19,6 +19,7 @@ #include "UserListCommands.h" #include "Application.h" +#include "ConsoleUtil.h" #include "XLSReader.h" #include "XLSSheet.h" #include "Requests/UserLists/UserListListRequest.h" @@ -169,7 +170,7 @@ void UserListCommands::showListCommand(CommandParser *commandParser, const std:: std::cout << "User list '" << args[2]; if(userList->isEmpty()) { - std::cout << " is empty." << std::endl; + std::cout << " is empty." << std::endl << std::endl; } else { std::cout << "' contains " << userList->getLength() << " user"; @@ -179,8 +180,6 @@ void UserListCommands::showListCommand(CommandParser *commandParser, const std:: printUserList(*userList); } - - std::cout << std::endl; } else { std::cerr << args[0] << " " << args[1] << ": Too many arguments." << std::endl; @@ -351,6 +350,7 @@ void UserListCommands::importCommand(CommandParser *commandParser, const std::ve void UserListCommands::printUserList(const Common::UserLists::UserList &list) { + Core::String output; std::map lengths; static const Core::String USER_NAME = "User name"; @@ -381,50 +381,52 @@ void UserListCommands::printUserList(const Common::UserLists::UserList &list) { } } - std::cout << " "; - printPadded(USER_NAME, lengths.find(USER_NAME)->second); - std::cout << " "; - printPadded(GROUP_NAME, lengths.find(GROUP_NAME)->second); + output += " "; + output += makePaddedString(USER_NAME, lengths.find(USER_NAME)->second); + output += " "; + output += makePaddedString(GROUP_NAME, lengths.find(GROUP_NAME)->second); for(std::set::iterator detail = details.begin(); detail != details.end(); ++detail) { - std::cout << " "; - printPadded(*detail, lengths.find(*detail)->second); + output += " "; + output += makePaddedString(*detail, lengths.find(*detail)->second); } - std::cout << std::endl; + output += "\n"; - std::cout << "-"; - printDelimiter(lengths.find(USER_NAME)->second); - std::cout << "- -"; - printDelimiter(lengths.find(GROUP_NAME)->second); + output += "-"; + output += makeDelimiter(lengths.find(USER_NAME)->second); + output += "- -"; + output += makeDelimiter(lengths.find(GROUP_NAME)->second); for(std::set::iterator detail = details.begin(); detail != details.end(); ++detail) { - std::cout << "- -"; - printDelimiter(lengths.find(*detail)->second); + output += "- -"; + output += makeDelimiter(lengths.find(*detail)->second); } - std::cout << "-" << std::endl; + output += "-\n"; for(Common::UserLists::UserList::const_iterator user = list.begin(); user != list.end(); ++user) { static const Core::String UNSET(""); - std::cout << " "; + output += " "; if(!user->getName().isEmpty()) - printPadded(user->getName(), lengths.find(USER_NAME)->second); + output += makePaddedString(user->getName(), lengths.find(USER_NAME)->second); else - printPadded(UNSET, lengths.find(USER_NAME)->second); + output += makePaddedString(UNSET, lengths.find(USER_NAME)->second); - std::cout << " "; + output += " "; if(!user->getGroup().isEmpty()) - printPadded(user->getGroup(), lengths.find(GROUP_NAME)->second); + output += makePaddedString(user->getGroup(), lengths.find(GROUP_NAME)->second); else - printPadded(UNSET, lengths.find(GROUP_NAME)->second); + output += makePaddedString(UNSET, lengths.find(GROUP_NAME)->second); for(std::set::iterator detail = details.begin(); detail != details.end(); ++detail) { - std::cout << " "; - printPadded(user->getDetail(*detail), lengths.find(*detail)->second); + output += " "; + output += makePaddedString(user->getDetail(*detail), lengths.find(*detail)->second); } - std::cout << std::endl; + output += "\n"; } + + ConsoleUtil::printPaged(output); } void UserListCommands::printSheet(const XLSSheet &sheet, unsigned rowCount) { @@ -454,16 +456,16 @@ void UserListCommands::printSheet(const XLSSheet &sheet, unsigned rowCount) { std::cout << " "; if(!sheet.getColumnName(col).isEmpty()) - printPadded(sheet.getColumnName(col), lengths[col]); + std::cout << makePaddedString(sheet.getColumnName(col), lengths[col]); else - printPadded(DELETE, lengths[col]); + std::cout << makePaddedString(DELETE, lengths[col]); } std::cout << std::endl; std::cout << " "; for(unsigned col = 0; col < sheet.getColumnCount(); ++col) { std::cout << " -"; - printDelimiter(lengths[col]); + std::cout << makeDelimiter(lengths[col]); std::cout << "-"; } std::cout << std::endl; @@ -473,7 +475,7 @@ void UserListCommands::printSheet(const XLSSheet &sheet, unsigned rowCount) { for(unsigned col = 0; col < sheet.getColumnCount(); ++col) { std::cout << " "; - printPadded(row[col], lengths[col]); + std::cout << makePaddedString(row[col], lengths[col]); } std::cout << std::endl; @@ -482,21 +484,22 @@ void UserListCommands::printSheet(const XLSSheet &sheet, unsigned rowCount) { if(rowCount > 0 && rows.size() > rowCount) { for(unsigned col = 0; col < sheet.getColumnCount(); ++col) { std::cout << " "; - printPadded("...", lengths[col]); + std::cout << makePaddedString("...", lengths[col]); } std::cout << std::endl; } } -void UserListCommands::printPadded(const Core::String &str, boost::int32_t length) { - std::cout << str; +Core::String UserListCommands::makePaddedString(const Core::String &str, boost::int32_t length) { if(str.length() < length) - std::cout << std::string(length-str.length(), ' '); + return str + Core::String::fromString(std::string(length-str.length(), ' ')); + else + return str; } -void UserListCommands::printDelimiter(boost::int32_t length) { - printPadded(Core::String::fromString(std::string(length, '-')), length); +Core::String UserListCommands::makeDelimiter(boost::int32_t length) { + return Core::String::fromString(std::string(length, '-')); } -- cgit v1.2.3