mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-09-09 00:30:36 +02:00
Putting Readline code inside #ifdefs
This commit is contained in:
parent
60a7d2128e
commit
a5f55bf2f4
6 changed files with 23 additions and 20 deletions
|
@ -121,12 +121,7 @@ configure_file (
|
||||||
add_subdirectory (src)
|
add_subdirectory (src)
|
||||||
add_subdirectory (src/commands)
|
add_subdirectory (src/commands)
|
||||||
add_subdirectory (src/columns)
|
add_subdirectory (src/columns)
|
||||||
|
|
||||||
# Doesn't make sense to build shell without Readline.
|
|
||||||
if (HAVE_READLINE)
|
|
||||||
add_subdirectory (src/shell)
|
add_subdirectory (src/shell)
|
||||||
endif (HAVE_READLINE)
|
|
||||||
|
|
||||||
add_subdirectory (doc)
|
add_subdirectory (doc)
|
||||||
add_subdirectory (i18n)
|
add_subdirectory (i18n)
|
||||||
add_subdirectory (scripts)
|
add_subdirectory (scripts)
|
||||||
|
|
|
@ -45,6 +45,9 @@ Override PACKAGE_LANGUAGE, then
|
||||||
/* Found the GnuTLS library */
|
/* Found the GnuTLS library */
|
||||||
#cmakedefine HAVE_LIBGNUTLS
|
#cmakedefine HAVE_LIBGNUTLS
|
||||||
|
|
||||||
|
/* Found the Readline library */
|
||||||
|
#cmakedefine HAVE_READLINE
|
||||||
|
|
||||||
/* Found the pthread library */
|
/* Found the pthread library */
|
||||||
#cmakedefine HAVE_LIBPTHREAD
|
#cmakedefine HAVE_LIBPTHREAD
|
||||||
|
|
||||||
|
|
|
@ -29,20 +29,37 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <cmake.h>
|
||||||
#include <Readline.h>
|
#include <Readline.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_READLINE
|
||||||
|
#include <readline/readline.h>
|
||||||
|
#include <readline/history.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
std::string Readline::gets (const std::string& prompt)
|
std::string Readline::gets (const std::string& prompt)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_READLINE
|
||||||
// Get a line from the user.
|
// Get a line from the user.
|
||||||
char *line_read = rl::readline (prompt.c_str ());
|
char *line_read = readline (prompt.c_str ());
|
||||||
|
#else
|
||||||
|
std::string line_read;
|
||||||
|
std::cout << prompt;
|
||||||
|
std::getline (std::cin, line_read);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_READLINE
|
||||||
// If the line has any text in it, save it on the history.
|
// If the line has any text in it, save it on the history.
|
||||||
if (line_read && *line_read)
|
if (line_read && *line_read)
|
||||||
rl::add_history (line_read);
|
add_history (line_read);
|
||||||
|
#endif
|
||||||
|
|
||||||
std::string ret (line_read);
|
std::string ret (line_read);
|
||||||
|
|
||||||
|
#ifdef HAVE_READLINE
|
||||||
free (line_read);
|
free (line_read);
|
||||||
|
#endif
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,17 +33,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <wordexp.h>
|
#include <wordexp.h>
|
||||||
|
|
||||||
namespace rl
|
|
||||||
{
|
|
||||||
// Wrapping readline.h in a namespace to
|
|
||||||
// avoid cluttering the global namespace.
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#include <readline/readline.h>
|
|
||||||
#include <readline/history.h>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Static class that offers a C++ API to readline C functions.
|
// Static class that offers a C++ API to readline C functions.
|
||||||
class Readline
|
class Readline
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,7 +42,6 @@
|
||||||
#include <i18n.h>
|
#include <i18n.h>
|
||||||
#include <Color.h>
|
#include <Color.h>
|
||||||
#include <Context.h>
|
#include <Context.h>
|
||||||
#include <cmake.h>
|
|
||||||
#include <Readline.h>
|
#include <Readline.h>
|
||||||
|
|
||||||
Context context;
|
Context context;
|
||||||
|
|
|
@ -42,7 +42,7 @@ if (open my $fh, '>', 'shell.rc')
|
||||||
}
|
}
|
||||||
|
|
||||||
# Test the prompt.
|
# Test the prompt.
|
||||||
my $output = qx{printf "rc:test.rc add foo\nquit" | ../src/shell/tasksh 2>&1};
|
my $output = qx{printf "rc:shell.rc add foo\nquit" | ../src/shell/tasksh 2>&1};
|
||||||
like ($output, qr/testprompt>/, 'custom prompt is being used');
|
like ($output, qr/testprompt>/, 'custom prompt is being used');
|
||||||
|
|
||||||
# Test a simple add, then info.
|
# Test a simple add, then info.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue