Import patch from Roman Imankulov:

"sdcv" does not set up `rl_readline_name' variable which can be extremely useful for the writing the .inputrc file. Additionally sdcv does not use readline in the "Your choice [-1 to abort]" dialog. This patch fix both these issues, readline_name is set up to "sdcv".
This trick allows me to add into the .inputrc
$if sdcv
"\e\e": "-1\n"
$endif
and type double-escape in the "Your choice" dialog instead of pretty annoying "-1".
This commit is contained in:
Evgeniy Dushistov
2013-07-06 13:40:11 +00:00
parent 0aa0a8aea7
commit d2327e2a0f
5 changed files with 12 additions and 24 deletions

View File

@@ -22,9 +22,11 @@
# include "config.h" # include "config.h"
#endif #endif
#include <glib/gi18n.h>
#include <cstring> #include <cstring>
#include <map> #include <map>
#include <memory>
#include <glib/gi18n.h>
#include "utils.hpp" #include "utils.hpp"
@@ -348,25 +350,21 @@ bool Library::process_phrase(const char *loc_str, read_line &io, bool force)
utf8_output ? res_list[i].def.c_str() : loc_def.c_str()); utf8_output ? res_list[i].def.c_str() : loc_def.c_str());
} }
int choise; int choise;
std::auto_ptr<read_line> choice_readline(create_readline_object());
for (;;) { for (;;) {
string str_choise; string str_choise;
printf(_("Your choice[-1 to abort]: ")); choice_readline->read(_("Your choice[-1 to abort]: "), str_choise);
if(!stdio_getline(stdin, str_choise)){
putchar('\n');
exit(EXIT_SUCCESS);
}
sscanf(str_choise.c_str(), "%d", &choise); sscanf(str_choise.c_str(), "%d", &choise);
if (choise>=0 && choise<int(res_list.size())) { if (choise>=0 && choise<int(res_list.size())) {
sdcv_pager pager; sdcv_pager pager;
print_search_result(pager.get_stream(), res_list[choise]); print_search_result(pager.get_stream(), res_list[choise]);
break; break;
} else if (choise==-1) } else if (choise==-1){
break; break;
else } else
printf(_("Invalid choice.\nIt must be from 0 to %zu or -1.\n"), printf(_("Invalid choice.\nIt must be from 0 to %zu or -1.\n"),
res_list.size()-1); res_list.size()-1);
} }
} else { } else {
sdcv_pager pager(force); sdcv_pager pager(force);
fprintf(pager.get_stream(), _("Found %zu items, similar to %s.\n"), fprintf(pager.get_stream(), _("Found %zu items, similar to %s.\n"),

View File

@@ -47,9 +47,11 @@ public:
#else #else
class real_readline : public read_line { class real_readline : public read_line {
public: public:
real_readline() real_readline()
{ {
rl_readline_name = "sdcv";
using_history(); using_history();
string histname=(string(g_get_home_dir())+G_DIR_SEPARATOR+".sdcv_history"); string histname=(string(g_get_home_dir())+G_DIR_SEPARATOR+".sdcv_history");
read_history(histname.c_str());; read_history(histname.c_str());;
@@ -66,7 +68,7 @@ public:
} }
bool read(const string &banner, string& line) bool read(const string &banner, string& line)
{ {
char *phrase=NULL; char *phrase=NULL;
phrase=readline(banner.c_str()); phrase=readline(banner.c_str());
if (phrase) { if (phrase) {
line=phrase; line=phrase;

View File

@@ -11,6 +11,6 @@ public:
virtual void add_to_history(const std::string& phrase) {} virtual void add_to_history(const std::string& phrase) {}
}; };
extern string sdcv_readline;
extern read_line *create_readline_object(); extern read_line *create_readline_object();
#endif//!_READLINE_HPP_ #endif//!_READLINE_HPP_

View File

@@ -29,17 +29,6 @@
#include "utils.hpp" #include "utils.hpp"
bool stdio_getline(FILE *in, std::string & str)
{
str.clear();
int ch;
while((ch=fgetc(in))!=EOF && ch!='\n')
str+=ch;
if(EOF==ch)
return false;
return true;
}
std::string utf8_to_locale_ign_err(const std::string& utf8_str) std::string utf8_to_locale_ign_err(const std::string& utf8_str)
{ {
gsize bytes_read, bytes_written; gsize bytes_read, bytes_written;

View File

@@ -53,7 +53,6 @@ namespace glib {
} }
extern bool stdio_getline(FILE *in, std::string &str);
extern char *locale_to_utf8(const char *locstr); extern char *locale_to_utf8(const char *locstr);
extern std::string utf8_to_locale_ign_err(const std::string& utf8_str); extern std::string utf8_to_locale_ign_err(const std::string& utf8_str);