mirror of
https://github.com/GothenburgBitFactory/taskshell.git
synced 2025-06-26 10:54:29 +02:00
Cleanup: Migrated ::getResponse into main.cpp
This commit is contained in:
parent
5eb8e6f28a
commit
b783adca92
2 changed files with 24 additions and 45 deletions
36
src/main.cpp
36
src/main.cpp
|
@ -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);
|
||||
|
||||
// Save history.
|
||||
if (*line_read)
|
||||
add_history (line_read);
|
||||
|
||||
std::string command (line_read);
|
||||
free (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 != "")
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue