add support for binding actions to multibyte characters

This commit is contained in:
Andrzej Rybczak
2012-08-25 01:32:12 +02:00
parent 3750533026
commit 6829a8e05c
10 changed files with 289 additions and 213 deletions

View File

@@ -58,6 +58,35 @@ size_t Action::FooterHeight;
size_t Action::FooterStartY; size_t Action::FooterStartY;
std::map<ActionType, Action *> Action::Actions; std::map<ActionType, Action *> Action::Actions;
Action::Key Action::NoOp = Action::Key(ERR, ctNCurses);
Action::Key Action::ReadKey(Window &w)
{
std::string tmp;
int input;
while (true)
{
w.ReadKey(input);
if (input == ERR)
return NoOp;
if (input > 255)
return Key(input, ctNCurses);
else
{
wchar_t wc;
tmp += input;
size_t conv_res = mbrtowc(&wc, tmp.c_str(), MB_CUR_MAX, 0);
if (conv_res == size_t(-1)) // incomplete multibyte character
continue;
else if (conv_res == size_t(-2)) // garbage character sequence
return NoOp;
else // character complete
return Key(wc, ctStandard);
}
}
// not reachable
assert(false);
}
void Action::ValidateScreenSize() void Action::ValidateScreenSize()
{ {
@@ -215,7 +244,6 @@ void Action::Seek()
LockProgressbar(); LockProgressbar();
LockStatusbar(); LockStatusbar();
int input;
int songpos = Mpd.GetElapsedTime(); int songpos = Mpd.GetElapsedTime();
time_t t = time(0); time_t t = time(0);
@@ -227,11 +255,11 @@ void Action::Seek()
{ {
TraceMpdStatus(); TraceMpdStatus();
myPlaylist->UpdateTimer(); myPlaylist->UpdateTimer();
wFooter->ReadKey(input);
int howmuch = Config.incremental_seeking ? (myPlaylist->Timer()-t)/2+Config.seek_time : Config.seek_time; int howmuch = Config.incremental_seeking ? (myPlaylist->Timer()-t)/2+Config.seek_time : Config.seek_time;
NcmpcppKeys::Binding k = Key.Bindings.equal_range(input); Key input = ReadKey(*wFooter);
KeyConfiguration::Binding k = Keys.Bindings.equal_range(input);
// no action? // no action?
if (k.first == k.second) if (k.first == k.second)
break; break;

View File

@@ -49,8 +49,41 @@ enum ActionType
aShowVisualizer, aShowClock, aShowServerInfo aShowVisualizer, aShowClock, aShowServerInfo
}; };
enum CharType { ctStandard, ctNCurses };
struct Action struct Action
{ {
/// Key for binding actions to it. Supports non-ascii characters.
struct Key
{
Key(wchar_t ch, CharType ct) : Char(ch), Type(ct) { }
wchar_t getChar() const { return Char; }
CharType getType() const { return Type; }
# define INEQUALITY_OPERATOR(CMP) \
bool operator CMP (const Key &k) const \
{ \
if (Char CMP k.Char) \
return true; \
if (Char != k.Char) \
return false; \
return Type CMP k.Type; \
}
INEQUALITY_OPERATOR(<);
INEQUALITY_OPERATOR(<=);
INEQUALITY_OPERATOR(>);
INEQUALITY_OPERATOR(>=);
# undef INEQUALITY_OPERATOR
bool operator==(const Key &k) const { return Char == k.Char && Type == k.Type; }
bool operator!=(const Key &k) const { return !(*this == k); }
private:
wchar_t Char;
CharType Type;
};
enum FindDirection { fdForward, fdBackward }; enum FindDirection { fdForward, fdBackward };
Action(ActionType type, const char *name) : itsType(type), itsName(name) { } Action(ActionType type, const char *name) : itsType(type), itsName(name) { }
@@ -68,6 +101,8 @@ struct Action
return false; return false;
} }
static Key ReadKey(Window &w);
static void ValidateScreenSize(); static void ValidateScreenSize();
static void SetResizeFlags(); static void SetResizeFlags();
static void ResizeScreen(); static void ResizeScreen();
@@ -87,6 +122,8 @@ struct Action
static size_t FooterHeight; static size_t FooterHeight;
static size_t FooterStartY; static size_t FooterStartY;
static Key NoOp;
protected: protected:
virtual bool canBeRun() const { return true; } virtual bool canBeRun() const { return true; }
virtual void Run() = 0; virtual void Run() = 0;

View File

@@ -97,6 +97,62 @@ std::string IntoStr(NCurses::Color color)
return result; return result;
} }
std::string IntoStr(const Action::Key &key, bool *print_backspace)
{
std::string result;
if (key == Action::Key(KEY_UP, ctNCurses))
result += "Up";
else if (key == Action::Key(KEY_DOWN, ctNCurses))
result += "Down";
else if (key == Action::Key(KEY_PPAGE, ctNCurses))
result += "PageUp";
else if (key == Action::Key(KEY_NPAGE, ctNCurses))
result += "PageDown";
else if (key == Action::Key(KEY_HOME, ctNCurses))
result += "Home";
else if (key == Action::Key(KEY_END, ctNCurses))
result += "End";
else if (key == Action::Key(KEY_SPACE, ctStandard))
result += "Space";
else if (key == Action::Key(KEY_ENTER, ctStandard))
result += "Enter";
else if (key == Action::Key(KEY_DC, ctNCurses))
result += "Delete";
else if (key == Action::Key(KEY_RIGHT, ctNCurses))
result += "Right";
else if (key == Action::Key(KEY_LEFT, ctNCurses))
result += "Left";
else if (key == Action::Key(KEY_TAB, ctStandard))
result += "Tab";
else if (key == Action::Key(KEY_SHIFT_TAB, ctNCurses))
result += "Shift-Tab";
else if (key >= Action::Key(KEY_CTRL_A, ctStandard) && key <= Action::Key(KEY_CTRL_Z, ctStandard))
{
result += "Ctrl-";
result += key.getChar()+64;
}
else if (key >= Action::Key(KEY_F1, ctNCurses) && key <= Action::Key(KEY_F12, ctNCurses))
{
result += "F";
result += IntoStr(key.getChar()-264);
}
else if ((key == Action::Key(KEY_BACKSPACE, ctNCurses) || key == Action::Key(KEY_BACKSPACE_2, ctStandard)))
{
// since some terminals interpret KEY_BACKSPACE as backspace and other need KEY_BACKSPACE_2,
// actions have to be bound to either of them, but we want to display "Backspace" only once,
// hance this 'print_backspace' switch.
if (!print_backspace || *print_backspace)
{
result += "Backspace";
if (print_backspace)
*print_backspace = false;
}
}
else
result += ToString(std::wstring(1, key.getChar()));
return result;
}
NCurses::Color IntoColor(const std::string &color) NCurses::Color IntoColor(const std::string &color)
{ {
NCurses::Color result = NCurses::clDefault; NCurses::Color result = NCurses::clDefault;

View File

@@ -24,6 +24,7 @@
#include <cstring> #include <cstring>
#include <string> #include <string>
#include "actions.h"
#include "window.h" #include "window.h"
#include "song.h" #include "song.h"
@@ -43,10 +44,9 @@ int StrToInt(const std::string &);
long StrToLong(const std::string &); long StrToLong(const std::string &);
std::string IntoStr(int); std::string IntoStr(int);
std::string IntoStr(mpd_tag_type); std::string IntoStr(mpd_tag_type);
std::string IntoStr(NCurses::Color); std::string IntoStr(NCurses::Color);
std::string IntoStr(const Action::Key &key, bool *print_backspace = 0);
NCurses::Color IntoColor(const std::string &); NCurses::Color IntoColor(const std::string &);

View File

@@ -78,58 +78,13 @@ std::basic_string<my_char_t> Help::Title()
std::string Help::DisplayKeys(const ActionType at) std::string Help::DisplayKeys(const ActionType at)
{ {
bool backspace = true; bool print_backspace = true;
std::string result; std::string result;
for (std::multimap<int, Action *>::const_iterator it = Key.Bindings.begin(); it != Key.Bindings.end(); ++it) for (std::multimap<Action::Key, Action *>::const_iterator it = Keys.Bindings.begin(); it != Keys.Bindings.end(); ++it)
{ {
if (it->second->Type() == at) if (it->second->Type() == at)
{ {
int key = it->first; result += IntoStr(it->first, &print_backspace);
if (key == 259)
result += "Up";
else if (key == 258)
result += "Down";
else if (key == 339)
result += "PageUp";
else if (key == 338)
result += "PageDown";
else if (key == 262)
result += "Home";
else if (key == 360)
result += "End";
else if (key == 32)
result += "Space";
else if (key == 10)
result += "Enter";
else if (key == 330)
result += "Delete";
else if (key == 261)
result += "Right";
else if (key == 260)
result += "Left";
else if (key == 9)
result += "Tab";
else if (key == 353)
result += "Shift-Tab";
else if (key >= 1 && key <= 26)
{
result += "Ctrl-";
result += key+64;
}
else if (key >= 265 && key <= 276)
{
result += "F";
result += IntoStr(key-264);
}
else if ((key == 263 || key == 127) && !backspace);
else if ((key == 263 || key == 127) && backspace)
{
result += "Backspace";
backspace = false;
}
else if (isprint(key))
result += key;
result += " "; result += " ";
} }
} }

View File

@@ -262,7 +262,7 @@ void ParseArgv(int argc, char **argv)
} }
else if (!strcmp(argv[i], "-c") || !strcmp(argv[i], "--config")) else if (!strcmp(argv[i], "-c") || !strcmp(argv[i], "--config"))
{ {
// this is used in NcmpcppConfig::CheckForCommandLineConfigFilePath, ignoring here. // this is used in Configuration::CheckForCommandLineConfigFilePath, ignoring here.
++i; ++i;
} }
else else

View File

@@ -103,7 +103,7 @@ int main(int argc, char **argv)
Config.Read(); Config.Read();
Config.GenerateColumns(); Config.GenerateColumns();
Key.GenerateKeybindings(); Keys.GenerateBindings();
if (getenv("MPD_HOST")) if (getenv("MPD_HOST"))
Mpd.SetHostname(getenv("MPD_HOST")); Mpd.SetHostname(getenv("MPD_HOST"));
@@ -175,8 +175,7 @@ int main(int argc, char **argv)
Mpd.SetErrorHandler(NcmpcppErrorCallback, 0); Mpd.SetErrorHandler(NcmpcppErrorCallback, 0);
// local variables // local variables
int input = 0; Action::Key input(Action::NoOp);
timeval past = { 0, 0 }; timeval past = { 0, 0 };
// local variables end // local variables end
@@ -263,14 +262,14 @@ int main(int argc, char **argv)
} }
// header stuff end // header stuff end
if (input != ERR) if (input != Action::NoOp)
myScreen->RefreshWindow(); myScreen->RefreshWindow();
wFooter->ReadKey(input); input = Action::ReadKey(*wFooter);
if (input == ERR) if (input == Action::NoOp)
continue; continue;
NcmpcppKeys::Binding k = Key.Bindings.equal_range(input); KeyConfiguration::Binding k = Keys.Bindings.equal_range(input);
for (; k.first != k.second; ++k.first) for (; k.first != k.second; ++k.first)
if (k.first->second->Execute()) if (k.first->second->Execute())
break; break;

View File

@@ -51,8 +51,8 @@
# include <langinfo.h> # include <langinfo.h>
#endif #endif
NcmpcppConfig Config; Configuration Config;
NcmpcppKeys Key; KeyConfiguration Keys;
namespace namespace
{ {
@@ -131,147 +131,147 @@ void CreateDir(const std::string &dir)
); );
} }
void NcmpcppKeys::GenerateKeybindings() void KeyConfiguration::GenerateBindings()
{ {
# define BIND(key, action) Bindings.insert(std::make_pair(key, Action::Get(action))) # define BIND(key, type, action) Bindings.insert(std::make_pair(Action::Key(key, type), Action::Get(action)))
BIND(KEY_MOUSE, aMouseEvent); BIND(KEY_MOUSE, ctNCurses, aMouseEvent);
BIND(KEY_UP, aScrollUp); BIND(KEY_UP, ctNCurses, aScrollUp);
BIND(KEY_DOWN, aScrollDown); BIND(KEY_DOWN, ctNCurses, aScrollDown);
BIND('[', aScrollUpAlbum); BIND('[', ctStandard, aScrollUpAlbum);
BIND(']', aScrollDownAlbum); BIND(']', ctStandard, aScrollDownAlbum);
BIND('{', aScrollUpArtist); BIND('{', ctStandard, aScrollUpArtist);
BIND('}', aScrollDownArtist); BIND('}', ctStandard, aScrollDownArtist);
BIND(KEY_PPAGE, aPageUp); BIND(KEY_PPAGE, ctNCurses, aPageUp);
BIND(KEY_NPAGE, aPageDown); BIND(KEY_NPAGE, ctNCurses, aPageDown);
BIND(KEY_HOME, aMoveHome); BIND(KEY_HOME, ctNCurses, aMoveHome);
BIND(KEY_END, aMoveEnd); BIND(KEY_END, ctNCurses, aMoveEnd);
BIND(' ', aPressSpace); BIND(KEY_SPACE, ctStandard, aPressSpace);
BIND(KEY_ENTER, aPressEnter); BIND(KEY_ENTER, ctStandard, aPressEnter);
BIND(KEY_DC, aDelete); BIND(KEY_DC, ctNCurses, aDelete);
BIND(KEY_RIGHT, aNextColumn); BIND(KEY_RIGHT, ctNCurses, aNextColumn);
BIND(KEY_RIGHT, aSlaveScreen); BIND(KEY_RIGHT, ctNCurses, aSlaveScreen);
BIND(KEY_RIGHT, aVolumeUp); BIND(KEY_RIGHT, ctNCurses, aVolumeUp);
BIND(KEY_LEFT, aPreviousColumn); BIND(KEY_LEFT, ctNCurses, aPreviousColumn);
BIND(KEY_LEFT, aMasterScreen); BIND(KEY_LEFT, ctNCurses, aMasterScreen);
BIND(KEY_LEFT, aVolumeDown); BIND(KEY_LEFT, ctNCurses, aVolumeDown);
BIND(KEY_TAB, aNextScreen); BIND(KEY_TAB, ctStandard, aNextScreen);
BIND(KEY_SHIFT_TAB, aPreviousScreen); BIND(KEY_SHIFT_TAB, ctNCurses, aPreviousScreen);
BIND('1', aShowHelp); BIND('1', ctStandard, aShowHelp);
BIND('2', aShowPlaylist); BIND('2', ctStandard, aShowPlaylist);
BIND('3', aShowBrowser); BIND('3', ctStandard, aShowBrowser);
BIND('4', aShowSearchEngine); BIND('4', ctStandard, aShowSearchEngine);
BIND('5', aShowMediaLibrary); BIND('5', ctStandard, aShowMediaLibrary);
BIND('6', aShowPlaylistEditor); BIND('6', ctStandard, aShowPlaylistEditor);
BIND('7', aShowTagEditor); BIND('7', ctStandard, aShowTagEditor);
BIND('8', aShowOutputs); BIND('8', ctStandard, aShowOutputs);
BIND('9', aShowVisualizer); BIND('9', ctStandard, aShowVisualizer);
BIND('0', aShowClock); BIND('0', ctStandard, aShowClock);
BIND('@', aShowServerInfo); BIND('@', ctStandard, aShowServerInfo);
BIND('s', aStop); BIND('s', ctStandard, aStop);
BIND('P', aPause); BIND('P', ctStandard, aPause);
BIND('>', aNextSong); BIND('>', ctStandard, aNextSong);
BIND('<', aPreviousSong); BIND('<', ctStandard, aPreviousSong);
BIND(KEY_CTRL_H, aJumpToParentDir); BIND(KEY_CTRL_H, ctStandard, aJumpToParentDir);
BIND(KEY_CTRL_H, aReplaySong); BIND(KEY_CTRL_H, ctStandard, aReplaySong);
BIND(KEY_BACKSPACE, aJumpToParentDir); BIND(KEY_BACKSPACE, ctNCurses, aJumpToParentDir);
BIND(KEY_BACKSPACE, aReplaySong); BIND(KEY_BACKSPACE, ctNCurses, aReplaySong);
BIND(KEY_BACKSPACE_2, aJumpToParentDir); BIND(KEY_BACKSPACE_2, ctStandard, aJumpToParentDir);
BIND(KEY_BACKSPACE_2, aReplaySong); BIND(KEY_BACKSPACE_2, ctStandard, aReplaySong);
BIND('f', aSeekForward); BIND('f', ctStandard, aSeekForward);
BIND('b', aSeekBackward); BIND('b', ctStandard, aSeekBackward);
BIND('r', aToggleRepeat); BIND('r', ctStandard, aToggleRepeat);
BIND('z', aToggleRandom); BIND('z', ctStandard, aToggleRandom);
BIND('y', aSaveTagChanges); BIND('y', ctStandard, aSaveTagChanges);
BIND('y', aStartSearching); BIND('y', ctStandard, aStartSearching);
BIND('y', aToggleSingle); BIND('y', ctStandard, aToggleSingle);
BIND('R', aToggleConsume); BIND('R', ctStandard, aToggleConsume);
BIND('Y', aToggleReplayGainMode); BIND('Y', ctStandard, aToggleReplayGainMode);
BIND('t', aToggleSpaceMode); BIND('t', ctStandard, aToggleSpaceMode);
BIND('T', aToggleAddMode); BIND('T', ctStandard, aToggleAddMode);
BIND('|', aToggleMouse); BIND('|', ctStandard, aToggleMouse);
BIND('#', aToggleBitrateVisibility); BIND('#', ctStandard, aToggleBitrateVisibility);
BIND('Z', aShuffle); BIND('Z', ctStandard, aShuffle);
BIND('x', aToggleCrossfade); BIND('x', ctStandard, aToggleCrossfade);
BIND('X', aSetCrossfade); BIND('X', ctStandard, aSetCrossfade);
BIND('u', aUpdateDatabase); BIND('u', ctStandard, aUpdateDatabase);
BIND(KEY_CTRL_V, aSortPlaylist); BIND(KEY_CTRL_V, ctStandard, aSortPlaylist);
BIND(KEY_CTRL_R, aReversePlaylist); BIND(KEY_CTRL_R, ctStandard, aReversePlaylist);
BIND(KEY_CTRL_F, aApplyFilter); BIND(KEY_CTRL_F, ctStandard, aApplyFilter);
BIND(KEY_CTRL_G, aDisableFilter); BIND(KEY_CTRL_G, ctStandard, aDisableFilter);
BIND('/', aFind); BIND('/', ctStandard, aFind);
BIND('/', aFindItemForward); BIND('/', ctStandard, aFindItemForward);
BIND('?', aFind); BIND('?', ctStandard, aFind);
BIND('?', aFindItemBackward); BIND('?', ctStandard, aFindItemBackward);
BIND('.', aNextFoundItem); BIND('.', ctStandard, aNextFoundItem);
BIND(',', aPreviousFoundItem); BIND(',', ctStandard, aPreviousFoundItem);
BIND('w', aToggleFindMode); BIND('w', ctStandard, aToggleFindMode);
BIND('e', aEditSong); BIND('e', ctStandard, aEditSong);
BIND('e', aEditLibraryTag); BIND('e', ctStandard, aEditLibraryTag);
BIND('e', aEditLibraryAlbum); BIND('e', ctStandard, aEditLibraryAlbum);
BIND('e', aEditDirectoryName); BIND('e', ctStandard, aEditDirectoryName);
BIND('e', aEditPlaylistName); BIND('e', ctStandard, aEditPlaylistName);
BIND('e', aEditLyrics); BIND('e', ctStandard, aEditLyrics);
BIND('i', aShowSongInfo); BIND('i', ctStandard, aShowSongInfo);
BIND('I', aShowArtistInfo); BIND('I', ctStandard, aShowArtistInfo);
BIND('g', aJumpToPositionInSong); BIND('g', ctStandard, aJumpToPositionInSong);
BIND('l', aShowLyrics); BIND('l', ctStandard, aShowLyrics);
BIND('v', aReverseSelection); BIND('v', ctStandard, aReverseSelection);
BIND('V', aDeselectItems); BIND('V', ctStandard, aDeselectItems);
BIND('B', aSelectAlbum); BIND('B', ctStandard, aSelectAlbum);
BIND('a', aAddSelectedItems); BIND('a', ctStandard, aAddSelectedItems);
BIND('c', aClearPlaylist); BIND('c', ctStandard, aClearPlaylist);
BIND('c', aClearMainPlaylist); BIND('c', ctStandard, aClearMainPlaylist);
BIND('C', aCropPlaylist); BIND('C', ctStandard, aCropPlaylist);
BIND('C', aCropMainPlaylist); BIND('C', ctStandard, aCropMainPlaylist);
BIND('m', aMoveSortOrderUp); BIND('m', ctStandard, aMoveSortOrderUp);
BIND('m', aMoveSelectedItemsUp); BIND('m', ctStandard, aMoveSelectedItemsUp);
BIND('n', aMoveSortOrderDown); BIND('n', ctStandard, aMoveSortOrderDown);
BIND('n', aMoveSelectedItemsDown); BIND('n', ctStandard, aMoveSelectedItemsDown);
BIND('M', aMoveSelectedItemsTo); BIND('M', ctStandard, aMoveSelectedItemsTo);
BIND('A', aAdd); BIND('A', ctStandard, aAdd);
BIND('S', aSavePlaylist); BIND('S', ctStandard, aSavePlaylist);
BIND('o', aJumpToPlayingSong); BIND('o', ctStandard, aJumpToPlayingSong);
BIND('G', aJumpToBrowser); BIND('G', ctStandard, aJumpToBrowser);
BIND('G', aJumpToPlaylistEditor); BIND('G', ctStandard, aJumpToPlaylistEditor);
BIND('~', aJumpToMediaLibrary); BIND('~', ctStandard, aJumpToMediaLibrary);
BIND('E', aJumpToTagEditor); BIND('E', ctStandard, aJumpToTagEditor);
BIND('U', aToggleAutoCenter); BIND('U', ctStandard, aToggleAutoCenter);
BIND('p', aToggleDisplayMode); BIND('p', ctStandard, aToggleDisplayMode);
BIND('\\', aToggleInterface); BIND('\\', ctStandard, aToggleInterface);
BIND('!', aToggleSeparatorsInPlaylist); BIND('!', ctStandard, aToggleSeparatorsInPlaylist);
BIND('L', aToggleLyricsFetcher); BIND('L', ctStandard, aToggleLyricsFetcher);
BIND('F', aToggleFetchingLyricsInBackground); BIND('F', ctStandard, aToggleFetchingLyricsInBackground);
BIND(KEY_CTRL_L, aToggleScreenLock); BIND(KEY_CTRL_L, ctStandard, aToggleScreenLock);
BIND('`', aToggleBrowserSortMode); BIND('`', ctStandard, aToggleBrowserSortMode);
BIND('`', aToggleLibraryTagType); BIND('`', ctStandard, aToggleLibraryTagType);
BIND('`', aRefetchLyrics); BIND('`', ctStandard, aRefetchLyrics);
BIND('`', aRefetchArtistInfo); BIND('`', ctStandard, aRefetchArtistInfo);
BIND('`', aAddRandomItems); BIND('`', ctStandard, aAddRandomItems);
BIND(KEY_CTRL_P, aSetSelectedItemsPriority); BIND(KEY_CTRL_P, ctStandard, aSetSelectedItemsPriority);
BIND('q', aQuit); BIND('q', ctStandard, aQuit);
BIND('k', aScrollUp); BIND('k', ctStandard, aScrollUp);
BIND('j', aScrollDown); BIND('j', ctStandard, aScrollDown);
BIND('d', aDelete); BIND('d', ctStandard, aDelete);
BIND('+', aVolumeUp); BIND('+', ctStandard, aVolumeUp);
BIND('-', aVolumeDown); BIND('-', ctStandard, aVolumeDown);
BIND(KEY_F1, aShowHelp); BIND(KEY_F1, ctNCurses, aShowHelp);
BIND(KEY_F2, aShowPlaylist); BIND(KEY_F2, ctNCurses, aShowPlaylist);
BIND(KEY_F3, aShowBrowser); BIND(KEY_F3, ctNCurses, aShowBrowser);
BIND(KEY_F4, aShowSearchEngine); BIND(KEY_F4, ctNCurses, aShowSearchEngine);
BIND(KEY_F5, aShowMediaLibrary); BIND(KEY_F5, ctNCurses, aShowMediaLibrary);
BIND(KEY_F6, aShowPlaylistEditor); BIND(KEY_F6, ctNCurses, aShowPlaylistEditor);
BIND(KEY_F7, aShowTagEditor); BIND(KEY_F7, ctNCurses, aShowTagEditor);
BIND(KEY_F8, aShowOutputs); BIND(KEY_F8, ctNCurses, aShowOutputs);
BIND(KEY_F9, aShowVisualizer); BIND(KEY_F9, ctNCurses, aShowVisualizer);
BIND(KEY_F10, aShowClock); BIND(KEY_F10, ctNCurses, aShowClock);
BIND('Q', aQuit); BIND('Q', ctStandard, aQuit);
# undef BIND # undef BIND
} }
void NcmpcppConfig::SetDefaults() void Configuration::SetDefaults()
{ {
mpd_host = "localhost"; mpd_host = "localhost";
empty_tag = "<empty>"; empty_tag = "<empty>";
@@ -389,7 +389,7 @@ void NcmpcppConfig::SetDefaults()
screens_seq.push_back(myBrowser); screens_seq.push_back(myBrowser);
} }
NcmpcppConfig::NcmpcppConfig() Configuration::Configuration()
{ {
# ifdef WIN32 # ifdef WIN32
ncmpcpp_directory = GetHomeDirectory() + "ncmpcpp/"; ncmpcpp_directory = GetHomeDirectory() + "ncmpcpp/";
@@ -401,7 +401,7 @@ NcmpcppConfig::NcmpcppConfig()
config_file_path = ncmpcpp_directory + "config"; config_file_path = ncmpcpp_directory + "config";
} }
const std::string &NcmpcppConfig::GetHomeDirectory() const std::string &Configuration::GetHomeDirectory()
{ {
if (!home_directory.empty()) if (!home_directory.empty())
return home_directory; return home_directory;
@@ -419,7 +419,7 @@ const std::string &NcmpcppConfig::GetHomeDirectory()
return home_directory; return home_directory;
} }
void NcmpcppConfig::CheckForCommandLineConfigFilePath(char **argv, int argc) void Configuration::CheckForCommandLineConfigFilePath(char **argv, int argc)
{ {
if (argc < 3) if (argc < 3)
return; return;
@@ -434,7 +434,7 @@ void NcmpcppConfig::CheckForCommandLineConfigFilePath(char **argv, int argc)
} }
} }
void NcmpcppConfig::Read() void Configuration::Read()
{ {
std::ifstream f(config_file_path.c_str()); std::ifstream f(config_file_path.c_str());
std::string cl, v, name; std::string cl, v, name;
@@ -1075,7 +1075,7 @@ void NcmpcppConfig::Read()
f.close(); f.close();
} }
void NcmpcppConfig::GenerateColumns() void Configuration::GenerateColumns()
{ {
columns.clear(); columns.clear();
std::string width; std::string width;
@@ -1143,7 +1143,7 @@ void NcmpcppConfig::GenerateColumns()
*song_in_columns_to_string_format.rbegin() = '}'; *song_in_columns_to_string_format.rbegin() = '}';
} }
void NcmpcppConfig::MakeProperPath(std::string &dir) void Configuration::MakeProperPath(std::string &dir)
{ {
if (dir.empty()) if (dir.empty())
return; return;

View File

@@ -45,21 +45,21 @@ struct Column
bool display_empty_tag; bool display_empty_tag;
}; };
struct NcmpcppKeys struct KeyConfiguration
{ {
typedef std::pair< typedef std::pair<
std::multimap<int, Action *>::iterator std::multimap<Action::Key, Action *>::iterator
, std::multimap<int, Action *>::iterator , std::multimap<Action::Key, Action *>::iterator
> Binding; > Binding;
void GenerateKeybindings(); void GenerateBindings();
std::multimap<int, Action *> Bindings; std::multimap<Action::Key, Action *> Bindings;
}; };
struct NcmpcppConfig struct Configuration
{ {
NcmpcppConfig(); Configuration();
const std::string &GetHomeDirectory(); const std::string &GetHomeDirectory();
void CheckForCommandLineConfigFilePath(char **argv, int argc); void CheckForCommandLineConfigFilePath(char **argv, int argc);
@@ -208,8 +208,8 @@ struct NcmpcppConfig
std::string config_file_path; std::string config_file_path;
}; };
extern NcmpcppKeys Key; extern KeyConfiguration Keys;
extern NcmpcppConfig Config; extern Configuration Config;
void CreateDir(const std::string &dir); void CreateDir(const std::string &dir);

View File

@@ -80,8 +80,9 @@
#define KEY_F12 276 #define KEY_F12 276
// other handy keys // other handy keys
#define KEY_TAB 9
#define KEY_SHIFT_TAB 353 #define KEY_SHIFT_TAB 353
#define KEY_SPACE 32
#define KEY_TAB 9
// define alternative KEY_BACKSPACE (used in some terminal emulators) // define alternative KEY_BACKSPACE (used in some terminal emulators)
#define KEY_BACKSPACE_2 127 #define KEY_BACKSPACE_2 127