help: show defined action chains
This commit is contained in:
1
NEWS
1
NEWS
@@ -31,6 +31,7 @@ ncmpcpp-0.7 (????-??-??)
|
|||||||
* Value of 'visualizer_sync_interval' is now restricted to be greater than 9.
|
* Value of 'visualizer_sync_interval' is now restricted to be greater than 9.
|
||||||
* Output of the visualizer now scales automatically as long as 'visualizer_sample_multiplier' is set to 1.
|
* Output of the visualizer now scales automatically as long as 'visualizer_sample_multiplier' is set to 1.
|
||||||
* Command line switch that prints current song to the standard output is available once again.
|
* Command line switch that prints current song to the standard output is available once again.
|
||||||
|
* Defined action chains are now shown in help screen.
|
||||||
|
|
||||||
ncmpcpp-0.6.7 (2015-09-12)
|
ncmpcpp-0.6.7 (2015-09-12)
|
||||||
* Fetching artist info from last.fm was fixed.
|
* Fetching artist info from last.fm was fixed.
|
||||||
|
|||||||
@@ -88,9 +88,9 @@ extern size_t FooterStartY;
|
|||||||
|
|
||||||
struct BaseAction
|
struct BaseAction
|
||||||
{
|
{
|
||||||
BaseAction(Type type_, const char *name_): m_type(type_), m_name(name_) { }
|
BaseAction(Type type_, const char *name_): m_name(name_), m_type(type_) { }
|
||||||
|
|
||||||
const char *name() const { return m_name; }
|
const std::string &name() const { return m_name; }
|
||||||
Type type() const { return m_type; }
|
Type type() const { return m_type; }
|
||||||
|
|
||||||
virtual bool canBeRun() { return true; }
|
virtual bool canBeRun() { return true; }
|
||||||
@@ -104,12 +104,14 @@ struct BaseAction
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::string m_name;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void run() = 0;
|
virtual void run() = 0;
|
||||||
|
|
||||||
Type m_type;
|
Type m_type;
|
||||||
const char *m_name;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
BaseAction &get(Type at);
|
BaseAction &get(Type at);
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ struct Binding
|
|||||||
typedef std::vector<Actions::BaseAction *> ActionChain;
|
typedef std::vector<Actions::BaseAction *> ActionChain;
|
||||||
|
|
||||||
template <typename ArgT>
|
template <typename ArgT>
|
||||||
Binding(ArgT &&actions)
|
Binding(ArgT &&actions_)
|
||||||
: m_actions(std::forward<ArgT>(actions)) {
|
: m_actions(std::forward<ArgT>(actions_)) {
|
||||||
assert(!m_actions.empty());
|
assert(!m_actions.empty());
|
||||||
}
|
}
|
||||||
Binding(Actions::Type at)
|
Binding(Actions::Type at)
|
||||||
@@ -58,6 +58,10 @@ struct Binding
|
|||||||
return m_actions[0];
|
return m_actions[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ActionChain &actions() const {
|
||||||
|
return m_actions;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ActionChain m_actions;
|
ActionChain m_actions;
|
||||||
};
|
};
|
||||||
|
|||||||
50
src/help.cpp
50
src/help.cpp
@@ -25,6 +25,7 @@
|
|||||||
#include "help.h"
|
#include "help.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "status.h"
|
#include "status.h"
|
||||||
|
#include "utility/string.h"
|
||||||
#include "utility/wide_string.h"
|
#include "utility/wide_string.h"
|
||||||
#include "title.h"
|
#include "title.h"
|
||||||
#include "screen_switcher.h"
|
#include "screen_switcher.h"
|
||||||
@@ -36,6 +37,22 @@ Help *myHelp;
|
|||||||
|
|
||||||
namespace {
|
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::string display_keys(const Actions::Type at)
|
||||||
{
|
{
|
||||||
std::wstring result, skey;
|
std::wstring result, skey;
|
||||||
@@ -54,18 +71,7 @@ std::string display_keys(const Actions::Type at)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
size_t i = 0, len = 0;
|
return align_key_rep(std::move(result));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void section(NC::Scrollpad &w, const char *type_, const char *title_)
|
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';
|
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_)
|
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");
|
mouse(w, "Right click", "Toggle output");
|
||||||
# endif // ENABLE_OUTPUTS
|
# 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");
|
section(w, "", "List of available colors");
|
||||||
for (int i = 0; i < COLORS; ++i)
|
for (int i = 0; i < COLORS; ++i)
|
||||||
w << NC::Color(i, NC::Color::transparent) << i+1 << NC::Color::End << " ";
|
w << NC::Color(i, NC::Color::transparent) << i+1 << NC::Color::End << " ";
|
||||||
|
|||||||
@@ -18,31 +18,76 @@
|
|||||||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include "bindings.h"
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "macro_utilities.h"
|
#include "macro_utilities.h"
|
||||||
|
#include "utility/string.h"
|
||||||
|
#include "utility/wide_string.h"
|
||||||
|
|
||||||
namespace Actions {
|
namespace Actions {
|
||||||
|
|
||||||
|
PushCharacters::PushCharacters(NC::Window **w, std::vector<NC::Key::Type> &&queue)
|
||||||
|
: BaseAction(Type::MacroUtility, "push_characters")
|
||||||
|
, m_window(w)
|
||||||
|
, m_queue(queue)
|
||||||
|
{
|
||||||
|
assert(w != nullptr);
|
||||||
|
std::vector<std::string> keys;
|
||||||
|
for (const auto &key : queue)
|
||||||
|
keys.push_back(ToString(keyToWString(key)));
|
||||||
|
m_name += " \"";
|
||||||
|
m_name += join<std::string>(keys, ", ");
|
||||||
|
m_name += "\"";
|
||||||
|
}
|
||||||
|
|
||||||
void PushCharacters::run()
|
void PushCharacters::run()
|
||||||
{
|
{
|
||||||
for (auto it = m_queue.begin(); it != m_queue.end(); ++it)
|
for (auto it = m_queue.begin(); it != m_queue.end(); ++it)
|
||||||
(*m_window)->pushChar(*it);
|
(*m_window)->pushChar(*it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RequireRunnable::RequireRunnable(BaseAction *action)
|
||||||
|
: BaseAction(Type::MacroUtility, "require_runnable")
|
||||||
|
, m_action(action)
|
||||||
|
{
|
||||||
|
assert(m_action != nullptr);
|
||||||
|
m_name += " \"";
|
||||||
|
m_name += m_action->name();
|
||||||
|
m_name += "\"";
|
||||||
|
}
|
||||||
|
|
||||||
bool RequireRunnable::canBeRun()
|
bool RequireRunnable::canBeRun()
|
||||||
{
|
{
|
||||||
return m_action->canBeRun();
|
return m_action->canBeRun();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RequireScreen::RequireScreen(ScreenType screen_type)
|
||||||
|
: BaseAction(Type::MacroUtility, "require_screen")
|
||||||
|
, m_screen_type(screen_type)
|
||||||
|
{
|
||||||
|
m_name += " \"";
|
||||||
|
m_name += screenTypeToString(m_screen_type);
|
||||||
|
m_name += "\"";
|
||||||
|
}
|
||||||
|
|
||||||
bool RequireScreen::canBeRun()
|
bool RequireScreen::canBeRun()
|
||||||
{
|
{
|
||||||
return Global::myScreen->type() == m_screen_type;
|
return Global::myScreen->type() == m_screen_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RunExternalCommand::RunExternalCommand(std::string command)
|
||||||
|
: BaseAction(Type::MacroUtility, "run_external_command")
|
||||||
|
, m_command(std::move(command))
|
||||||
|
{
|
||||||
|
m_name += " \"";
|
||||||
|
m_name += m_command;
|
||||||
|
m_name += "\"";
|
||||||
|
}
|
||||||
|
|
||||||
void RunExternalCommand::run()
|
void RunExternalCommand::run()
|
||||||
{
|
{
|
||||||
GNUC_UNUSED int res;
|
GNUC_UNUSED int res;
|
||||||
res = std::system(m_command.c_str());
|
res = std::system(m_command.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,9 +29,8 @@ namespace Actions {
|
|||||||
|
|
||||||
struct PushCharacters: BaseAction
|
struct PushCharacters: BaseAction
|
||||||
{
|
{
|
||||||
PushCharacters(NC::Window **w, std::vector<NC::Key::Type> &&queue)
|
PushCharacters(NC::Window **w, std::vector<NC::Key::Type> &&queue);
|
||||||
: BaseAction(Type::MacroUtility, ""), m_window(w), m_queue(queue) { }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void run() OVERRIDE;
|
virtual void run() OVERRIDE;
|
||||||
|
|
||||||
@@ -41,8 +40,7 @@ private:
|
|||||||
|
|
||||||
struct RequireRunnable: BaseAction
|
struct RequireRunnable: BaseAction
|
||||||
{
|
{
|
||||||
RequireRunnable(BaseAction *action)
|
RequireRunnable(BaseAction *action);
|
||||||
: BaseAction(Type::MacroUtility, ""), m_action(action) { assert(action); }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool canBeRun() OVERRIDE;
|
virtual bool canBeRun() OVERRIDE;
|
||||||
@@ -53,8 +51,7 @@ private:
|
|||||||
|
|
||||||
struct RequireScreen: BaseAction
|
struct RequireScreen: BaseAction
|
||||||
{
|
{
|
||||||
RequireScreen(ScreenType screen_type)
|
RequireScreen(ScreenType screen_type);
|
||||||
: BaseAction(Type::MacroUtility, ""), m_screen_type(screen_type) { }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual bool canBeRun() OVERRIDE;
|
virtual bool canBeRun() OVERRIDE;
|
||||||
@@ -65,8 +62,7 @@ private:
|
|||||||
|
|
||||||
struct RunExternalCommand: BaseAction
|
struct RunExternalCommand: BaseAction
|
||||||
{
|
{
|
||||||
RunExternalCommand(std::string command)
|
RunExternalCommand(std::string command);
|
||||||
: BaseAction(Type::MacroUtility, ""), m_command(command) { }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void run() OVERRIDE;
|
virtual void run() OVERRIDE;
|
||||||
|
|||||||
@@ -39,6 +39,59 @@
|
|||||||
#include "tiny_tag_editor.h"
|
#include "tiny_tag_editor.h"
|
||||||
#include "visualizer.h"
|
#include "visualizer.h"
|
||||||
|
|
||||||
|
std::string screenTypeToString(ScreenType st)
|
||||||
|
{
|
||||||
|
switch (st)
|
||||||
|
{
|
||||||
|
case ScreenType::Browser:
|
||||||
|
return "browser";
|
||||||
|
#ifdef ENABLE_CLOCK
|
||||||
|
case ScreenType::Clock:
|
||||||
|
return "clock";
|
||||||
|
#endif // ENABLE_CLOCK
|
||||||
|
case ScreenType::Help:
|
||||||
|
return "help";
|
||||||
|
#ifdef HAVE_CURL_CURL_H
|
||||||
|
case ScreenType::Lastfm:
|
||||||
|
return "last_fm";
|
||||||
|
#endif // HAVE_CURL_CURL_H
|
||||||
|
case ScreenType::Lyrics:
|
||||||
|
return "lyrics";
|
||||||
|
case ScreenType::MediaLibrary:
|
||||||
|
return "media_library";
|
||||||
|
#ifdef ENABLE_OUTPUTS
|
||||||
|
case ScreenType::Outputs:
|
||||||
|
return "outputs";
|
||||||
|
#endif // ENABLE_OUTPUTS
|
||||||
|
case ScreenType::Playlist:
|
||||||
|
return "playlist";
|
||||||
|
case ScreenType::PlaylistEditor:
|
||||||
|
return "playlist_editor";
|
||||||
|
case ScreenType::SearchEngine:
|
||||||
|
return "search_engine";
|
||||||
|
case ScreenType::SelectedItemsAdder:
|
||||||
|
return "selected_items_adder";
|
||||||
|
case ScreenType::ServerInfo:
|
||||||
|
return "server_info";
|
||||||
|
case ScreenType::SongInfo:
|
||||||
|
return "song_info";
|
||||||
|
case ScreenType::SortPlaylistDialog:
|
||||||
|
return "sort_playlist_dialog";
|
||||||
|
#ifdef HAVE_TAGLIB_H
|
||||||
|
case ScreenType::TagEditor:
|
||||||
|
return "tag_editor";
|
||||||
|
case ScreenType::TinyTagEditor:
|
||||||
|
return "tiny_tag_editor";
|
||||||
|
#endif // HAVE_TAGLIB_H
|
||||||
|
case ScreenType::Unknown:
|
||||||
|
return "unknown";
|
||||||
|
#ifdef ENABLE_VISUALIZER
|
||||||
|
case ScreenType::Visualizer:
|
||||||
|
return "visualizer";
|
||||||
|
#endif // ENABLE_VISUALIZER
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ScreenType stringtoStartupScreenType(const std::string &s)
|
ScreenType stringtoStartupScreenType(const std::string &s)
|
||||||
{
|
{
|
||||||
ScreenType result = ScreenType::Unknown;
|
ScreenType result = ScreenType::Unknown;
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ enum class ScreenType {
|
|||||||
# endif // ENABLE_VISUALIZER
|
# endif // ENABLE_VISUALIZER
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::string screenTypeToString(ScreenType st);
|
||||||
|
|
||||||
ScreenType stringtoStartupScreenType(const std::string &s);
|
ScreenType stringtoStartupScreenType(const std::string &s);
|
||||||
ScreenType stringToScreenType(const std::string &s);
|
ScreenType stringToScreenType(const std::string &s);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user