help: show defined action chains

This commit is contained in:
Andrzej Rybczak
2015-09-27 03:31:02 +02:00
parent 43a6b81820
commit 6ad3de7366
8 changed files with 157 additions and 28 deletions

View File

@@ -25,6 +25,7 @@
#include "help.h"
#include "settings.h"
#include "status.h"
#include "utility/string.h"
#include "utility/wide_string.h"
#include "title.h"
#include "screen_switcher.h"
@@ -36,6 +37,22 @@ Help *myHelp;
namespace {
std::string align_key_rep(std::wstring keys)
{
size_t i = 0, len = 0;
const size_t max_len = 20;
for (; i < keys.size(); ++i)
{
int width = std::max(1, wcwidth(keys[i]));
if (len+width > max_len)
break;
else
len += width;
}
keys.resize(i + max_len - len, ' ');
return ToString(keys);
}
std::string display_keys(const Actions::Type at)
{
std::wstring result, skey;
@@ -54,18 +71,7 @@ std::string display_keys(const Actions::Type at)
}
}
}
size_t i = 0, len = 0;
const size_t max_len = 20;
for (; i < result.size(); ++i)
{
int width = std::max(1, wcwidth(result[i]));
if (len+width > max_len)
break;
else
len += width;
}
result.resize(i + max_len - len, ' ');
return ToString(result);
return align_key_rep(std::move(result));
}
void section(NC::Scrollpad &w, const char *type_, const char *title_)
@@ -93,6 +99,11 @@ void key(NC::Scrollpad &w, const Actions::Type at, const boost::format &desc)
w << " " << display_keys(at) << " : " << desc.str() << '\n';
}
void key(NC::Scrollpad &w, NC::Key::Type k, const std::string &desc)
{
w << " " << align_key_rep(keyToWString(k)) << " : " << desc << '\n';
}
/**********************************************************************/
void mouse_section(NC::Scrollpad &w, const char *title_)
@@ -393,6 +404,21 @@ void write_bindings(NC::Scrollpad &w)
mouse(w, "Right click", "Toggle output");
# endif // ENABLE_OUTPUTS
section(w, "", "Action chains");
for (const auto &k : Bindings)
{
for (const auto &binding : k.second)
{
if (!binding.isSingle())
{
std::vector<std::string> commands;
for (const auto &action : binding.actions())
commands.push_back(action->name());
key(w, k.first, join<std::string>(commands, ", "));
}
}
}
section(w, "", "List of available colors");
for (int i = 0; i < COLORS; ++i)
w << NC::Color(i, NC::Color::transparent) << i+1 << NC::Color::End << " ";