mirror of
https://github.com/Dushistov/sdcv.git
synced 2025-12-15 17:31:56 +00:00
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:
@@ -22,9 +22,11 @@
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#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());
|
||||
}
|
||||
int choise;
|
||||
std::auto_ptr<read_line> choice_readline(create_readline_object());
|
||||
for (;;) {
|
||||
string str_choise;
|
||||
printf(_("Your choice[-1 to abort]: "));
|
||||
|
||||
if(!stdio_getline(stdin, str_choise)){
|
||||
putchar('\n');
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
choice_readline->read(_("Your choice[-1 to abort]: "), str_choise);
|
||||
sscanf(str_choise.c_str(), "%d", &choise);
|
||||
if (choise>=0 && choise<int(res_list.size())) {
|
||||
sdcv_pager pager;
|
||||
print_search_result(pager.get_stream(), res_list[choise]);
|
||||
break;
|
||||
} else if (choise==-1)
|
||||
} else if (choise==-1){
|
||||
break;
|
||||
else
|
||||
} else
|
||||
printf(_("Invalid choice.\nIt must be from 0 to %zu or -1.\n"),
|
||||
res_list.size()-1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sdcv_pager pager(force);
|
||||
fprintf(pager.get_stream(), _("Found %zu items, similar to %s.\n"),
|
||||
|
||||
@@ -47,9 +47,11 @@ public:
|
||||
#else
|
||||
|
||||
class real_readline : public read_line {
|
||||
|
||||
public:
|
||||
real_readline()
|
||||
{
|
||||
rl_readline_name = "sdcv";
|
||||
using_history();
|
||||
string histname=(string(g_get_home_dir())+G_DIR_SEPARATOR+".sdcv_history");
|
||||
read_history(histname.c_str());;
|
||||
@@ -66,7 +68,7 @@ public:
|
||||
}
|
||||
bool read(const string &banner, string& line)
|
||||
{
|
||||
char *phrase=NULL;
|
||||
char *phrase=NULL;
|
||||
phrase=readline(banner.c_str());
|
||||
if (phrase) {
|
||||
line=phrase;
|
||||
|
||||
@@ -11,6 +11,6 @@ public:
|
||||
virtual void add_to_history(const std::string& phrase) {}
|
||||
};
|
||||
|
||||
extern string sdcv_readline;
|
||||
extern read_line *create_readline_object();
|
||||
|
||||
#endif//!_READLINE_HPP_
|
||||
|
||||
@@ -29,17 +29,6 @@
|
||||
|
||||
#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)
|
||||
{
|
||||
gsize bytes_read, bytes_written;
|
||||
|
||||
@@ -53,7 +53,6 @@ namespace glib {
|
||||
}
|
||||
|
||||
|
||||
extern bool stdio_getline(FILE *in, std::string &str);
|
||||
extern char *locale_to_utf8(const char *locstr);
|
||||
extern std::string utf8_to_locale_ign_err(const std::string& utf8_str);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user