Make single character prompts more robust
This commit is contained in:
@@ -281,9 +281,9 @@ void confirmAction(const boost::format &description)
|
|||||||
<< " [" << NC::Format::Bold << 'y' << NC::Format::NoBold
|
<< " [" << NC::Format::Bold << 'y' << NC::Format::NoBold
|
||||||
<< '/' << NC::Format::Bold << 'n' << NC::Format::NoBold
|
<< '/' << NC::Format::Bold << 'n' << NC::Format::NoBold
|
||||||
<< "] ";
|
<< "] ";
|
||||||
auto answer = Statusbar::Helpers::promptReturnOneOf({"y", "n"});
|
char answer = Statusbar::Helpers::promptReturnOneOf({'y', 'n'});
|
||||||
if (answer == "n")
|
if (answer == 'n')
|
||||||
throw NC::PromptAborted(std::move(answer));
|
throw NC::PromptAborted(std::string(1, answer));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isMPDMusicDirSet()
|
bool isMPDMusicDirSet()
|
||||||
@@ -2106,7 +2106,7 @@ void ToggleReplayGainMode::run()
|
|||||||
<< "/" << NC::Format::Bold << 't' << NC::Format::NoBold << "rack"
|
<< "/" << NC::Format::Bold << 't' << NC::Format::NoBold << "rack"
|
||||||
<< "/" << NC::Format::Bold << 'a' << NC::Format::NoBold << "lbum"
|
<< "/" << NC::Format::Bold << 'a' << NC::Format::NoBold << "lbum"
|
||||||
<< "] ";
|
<< "] ";
|
||||||
rgm = Statusbar::Helpers::promptReturnOneOf({"t", "a", "o"})[0];
|
rgm = Statusbar::Helpers::promptReturnOneOf({'t', 'a', 'o'});
|
||||||
}
|
}
|
||||||
switch (rgm)
|
switch (rgm)
|
||||||
{
|
{
|
||||||
@@ -2176,7 +2176,7 @@ void AddRandomItems::run()
|
|||||||
<< "/" << "album" << NC::Format::Bold << 'A' << NC::Format::NoBold << "rtists"
|
<< "/" << "album" << NC::Format::Bold << 'A' << NC::Format::NoBold << "rtists"
|
||||||
<< "/" << "al" << NC::Format::Bold << 'b' << NC::Format::NoBold << "ums"
|
<< "/" << "al" << NC::Format::Bold << 'b' << NC::Format::NoBold << "ums"
|
||||||
<< "] ";
|
<< "] ";
|
||||||
rnd_type = Statusbar::Helpers::promptReturnOneOf({"s", "a", "A", "b"})[0];
|
rnd_type = Statusbar::Helpers::promptReturnOneOf({'s', 'a', 'A', 'b'});
|
||||||
}
|
}
|
||||||
|
|
||||||
mpd_tag_type tag_type = MPD_TAG_ARTIST;
|
mpd_tag_type tag_type = MPD_TAG_ARTIST;
|
||||||
@@ -2262,7 +2262,7 @@ void ToggleLibraryTagType::run()
|
|||||||
<< "/" << NC::Format::Bold << 'c' << NC::Format::NoBold << "omposer"
|
<< "/" << NC::Format::Bold << 'c' << NC::Format::NoBold << "omposer"
|
||||||
<< "/" << NC::Format::Bold << 'p' << NC::Format::NoBold << "erformer"
|
<< "/" << NC::Format::Bold << 'p' << NC::Format::NoBold << "erformer"
|
||||||
<< "] ";
|
<< "] ";
|
||||||
tag_type = Statusbar::Helpers::promptReturnOneOf({"a", "A", "y", "g", "c", "p"})[0];
|
tag_type = Statusbar::Helpers::promptReturnOneOf({'a', 'A', 'y', 'g', 'c', 'p'});
|
||||||
}
|
}
|
||||||
mpd_tag_type new_tagitem = charToTagType(tag_type);
|
mpd_tag_type new_tagitem = charToTagType(tag_type);
|
||||||
if (new_tagitem != Config.media_lib_primary_tag)
|
if (new_tagitem != Config.media_lib_primary_tag)
|
||||||
|
|||||||
@@ -132,9 +132,11 @@ const Type EoF = Special | 279;
|
|||||||
/// @see Window::getString()
|
/// @see Window::getString()
|
||||||
struct PromptAborted : std::exception
|
struct PromptAborted : std::exception
|
||||||
{
|
{
|
||||||
|
PromptAborted() { }
|
||||||
|
|
||||||
template <typename ArgT>
|
template <typename ArgT>
|
||||||
PromptAborted(ArgT &&prompt)
|
PromptAborted(ArgT &&prompt)
|
||||||
: m_prompt(std::forward<ArgT>(prompt)) { }
|
: m_prompt(std::forward<ArgT>(prompt)) { }
|
||||||
|
|
||||||
virtual const char *what() const noexcept override { return m_prompt.c_str(); }
|
virtual const char *what() const noexcept override { return m_prompt.c_str(); }
|
||||||
|
|
||||||
|
|||||||
@@ -195,18 +195,19 @@ bool Statusbar::Helpers::mainHook(const char *)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Statusbar::Helpers::promptReturnOneOf(std::vector<std::string> values)
|
char Statusbar::Helpers::promptReturnOneOf(const std::vector<char> &values)
|
||||||
{
|
{
|
||||||
Statusbar::Helpers::ImmediatelyReturnOneOf prompt_hook(std::move(values));
|
if (values.empty())
|
||||||
NC::Window::ScopedPromptHook hook(*wFooter, prompt_hook);
|
throw std::logic_error("empty vector of acceptable input");
|
||||||
int x = wFooter->getX(), y = wFooter->getY();
|
NC::Key::Type result;
|
||||||
std::string result;
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
wFooter->goToXY(x, y);
|
wFooter->refresh();
|
||||||
result = wFooter->prompt();
|
result = wFooter->readKey();
|
||||||
|
if (result == NC::Key::Ctrl_C || result == NC::Key::Ctrl_G)
|
||||||
|
throw NC::PromptAborted();
|
||||||
}
|
}
|
||||||
while (!prompt_hook.isOneOf(result));
|
while (std::find(values.begin(), values.end(), result) == values.end());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,8 +69,8 @@ void mpd();
|
|||||||
/// called each time user types another character while inside Window::getString
|
/// called each time user types another character while inside Window::getString
|
||||||
bool mainHook(const char *);
|
bool mainHook(const char *);
|
||||||
|
|
||||||
/// prompt and return one of the strings specified in the vector
|
/// prompt and return one of the characters specified in the vector
|
||||||
std::string promptReturnOneOf(std::vector<std::string> values);
|
char promptReturnOneOf(const std::vector<char> &values);
|
||||||
|
|
||||||
struct ImmediatelyReturnOneOf
|
struct ImmediatelyReturnOneOf
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user