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

@@ -49,8 +49,41 @@ enum ActionType
aShowVisualizer, aShowClock, aShowServerInfo
};
enum CharType { ctStandard, ctNCurses };
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 };
Action(ActionType type, const char *name) : itsType(type), itsName(name) { }
@@ -68,6 +101,8 @@ struct Action
return false;
}
static Key ReadKey(Window &w);
static void ValidateScreenSize();
static void SetResizeFlags();
static void ResizeScreen();
@@ -87,6 +122,8 @@ struct Action
static size_t FooterHeight;
static size_t FooterStartY;
static Key NoOp;
protected:
virtual bool canBeRun() const { return true; }
virtual void Run() = 0;