52
54
std::vector<keymap_desc> descs;
53
55
v->get_keys()->get_keymap_descriptions(descs, v->get_keys()->get_flag_from_context(context));
57
std::string highlighted_searchphrase = utils::strprintf("<hl>%s</>", searchphrase.c_str());
58
std::vector<std::string> colors = utils::tokenize(v->get_cfg()->get_configvalue("search-highlight-colors"), " ");
59
f->set("highlight", make_colorstring(colors));
55
60
listformatter listfmt;
57
for (std::vector<keymap_desc>::iterator it=descs.begin();it!=descs.end();++it) {
58
if (context.length() > 0 && it->ctx != context)
60
if (!apply_search || strcasestr(it->key.c_str(), searchphrase.c_str())!=NULL ||
61
strcasestr(it->cmd.c_str(), searchphrase.c_str())!=NULL ||
62
strcasestr(it->desc.c_str(), searchphrase.c_str())!=NULL) {
63
unsigned int how_often = 3 - (it->cmd.length() / 8);
64
char tabs[] = "\t\t\t";
65
tabs[how_often] = '\0';
66
listfmt.add_line(utils::strprintf("%s\t%s%s%s", it->key.c_str(), it->cmd.c_str(), tabs, it->desc.c_str()));
62
unsigned int unbound_count = 0;
63
unsigned int syskey_count = 0;
65
for (unsigned int i=0;i<3;i++) {
66
for (std::vector<keymap_desc>::iterator it=descs.begin();it!=descs.end();++it) {
70
condition = (it->key.length() == 0 || it->flags & KM_SYSKEYS);
71
if (it->key.length() == 0)
73
if (it->flags & KM_SYSKEYS)
77
condition = !(it->flags & KM_SYSKEYS);
80
condition = (it->key.length() > 0 || it->flags & KM_SYSKEYS);
82
default: condition = true; break;
84
if (context.length() > 0 && (it->ctx != context || condition))
86
if (!apply_search || strcasestr(it->key.c_str(), searchphrase.c_str())!=NULL ||
87
strcasestr(it->cmd.c_str(), searchphrase.c_str())!=NULL ||
88
strcasestr(it->desc.c_str(), searchphrase.c_str())!=NULL) {
91
unsigned int how_often_1 = strlen(tabs_1) - it->key.length();
92
unsigned int how_often_2 = strlen(tabs_2) - it->cmd.length();
93
tabs_1[how_often_1] = '\0';
94
tabs_2[how_often_2] = '\0';
98
case 1: line = utils::strprintf("%s%s%s%s%s", it->key.c_str(), tabs_1, it->cmd.c_str(), tabs_2, it->desc.c_str()); break;
99
case 2: line = utils::strprintf("%s%s%s%s", it->cmd.c_str(), tabs_1, tabs_2, it->desc.c_str()); break;
101
LOG(LOG_DEBUG, "help_formaction::prepare: step 1 - line = %s", line.c_str());
102
line = utils::quote_for_stfl(line);
103
LOG(LOG_DEBUG, "help_formaction::prepare: step 2 - line = %s", line.c_str());
104
if (apply_search && searchphrase.length() > 0) {
105
line = utils::replace_all(line, searchphrase, highlighted_searchphrase);
106
LOG(LOG_DEBUG, "help_formaction::prepare: step 3 - line = %s", line.c_str());
108
listfmt.add_line(line);
113
if (syskey_count > 0) {
114
listfmt.add_line("");
115
listfmt.add_line(_("Generic bindings:"));
116
listfmt.add_line("");
120
if (unbound_count > 0) {
121
listfmt.add_line("");
122
listfmt.add_line(_("Unbound functions:"));
123
listfmt.add_line("");
169
std::string help_formaction::title() {
173
std::string help_formaction::make_colorstring(const std::vector<std::string>& colors) {
175
if (colors.size() > 0) {
176
if (colors[0] != "default") {
177
result.append("fg=");
178
result.append(colors[0]);
180
if (colors.size() > 1) {
181
if (colors[1] != "default") {
182
if (result.length() > 0)
184
result.append("bg=");
185
result.append(colors[1]);
188
for (unsigned int i=2;i<colors.size();i++) {
189
if (result.length() > 0)
191
result.append("attr=");
192
result.append(colors[i]);