Cleanup: Migrated ::getResponse into main.cpp

This commit is contained in:
Paul Beckingham 2015-05-25 13:09:07 -04:00
parent 5eb8e6f28a
commit b783adca92
2 changed files with 24 additions and 45 deletions

View file

@ -50,10 +50,9 @@ std::string promptCompose ();
std::string findTaskwarrior ();
////////////////////////////////////////////////////////////////////////////////
static int commandLoop ()
const std::string getResponse (const std::string& prompt)
{
// Compose the prompt.
std::string prompt = promptCompose ();
std::string response {""};
// Display prompt, get input.
#ifdef HAVE_READLINE
@ -61,26 +60,37 @@ static int commandLoop ()
if (! line_read)
{
std::cout << "\n";
return -1;
}
else
{
// Save history.
if (*line_read)
add_history (line_read);
std::string command (line_read);
response = std::string (line_read);
free (line_read);
}
#else
std::cout << prompt;
std::string command;
std::getline (std::cin, command);
std::getline (std::cin, response);
if (std::cin.eof () == 1)
{
std::cout << "\n";
return -1;
}
#endif
return response;
}
////////////////////////////////////////////////////////////////////////////////
static int commandLoop ()
{
// Compose the prompt.
std::string prompt = promptCompose ();
// Display prompt, get input.
std::string command = getResponse (prompt);
int status = 0;
if (command != "")
{

View file

@ -38,38 +38,7 @@
#include <util.h>
#include <i18n.h>
////////////////////////////////////////////////////////////////////////////////
static const std::string getResponse (const std::string& prompt)
{
std::string response {""};
// Display prompt, get input.
#ifdef HAVE_READLINE
char *line_read = readline (prompt.c_str ());
if (! line_read)
{
std::cout << "\n";
}
else
{
// Save history.
if (*line_read)
add_history (line_read);
response = std::string (line_read);
free (line_read);
}
#else
std::cout << prompt;
std::getline (std::cin, response);
if (std::cin.eof () == 1)
{
std::cout << "\n";
}
#endif
return response;
}
std::string getResponse (const std::string&);
////////////////////////////////////////////////////////////////////////////////
static void editTask (const std::string& uuid)