Exit if stdin is closed

This commit is contained in:
Andrzej Rybczak
2016-12-07 19:46:38 +01:00
parent 56cb940a12
commit 9306f56c34
4 changed files with 25 additions and 17 deletions

1
NEWS
View File

@@ -11,6 +11,7 @@ ncmpcpp-0.8 (????-??-??)
* libcurl dependency is no longer optional.
* When an attempt to write tags fails, show detailed error message.
* Support for fetching lyrics for selected items in background was added.
* Application will now exit if stdin is closed.
ncmpcpp-0.7.7 (2016-10-31)
* Fixed compilation on 32bit platforms.

View File

@@ -474,6 +474,7 @@ bool BindingsConfiguration::read(const std::string &file)
void BindingsConfiguration::generateDefaults()
{
NC::Key::Type k = NC::Key::None;
bind(NC::Key::EoF, Actions::Type::Quit);
if (notBound(k = stringToKey("mouse")))
bind(k, Actions::Type::MouseEvent);
if (notBound(k = stringToKey("up")))
@@ -743,9 +744,6 @@ void BindingsConfiguration::generateDefaults()
bind(k, Actions::Type::SetSelectedItemsPriority);
if (notBound(k = stringToKey("q")))
bind(k, Actions::Type::Quit);
if (notBound(k = stringToKey("-")))
bind(k, Actions::Type::VolumeDown);
}
const Command *BindingsConfiguration::findCommand(const std::string &name)

View File

@@ -1062,29 +1062,37 @@ Key::Type Window::readKey()
return result;
}
fd_set fdset;
FD_ZERO(&fdset);
FD_SET(STDIN_FILENO, &fdset);
fd_set fds_read;
FD_ZERO(&fds_read);
FD_SET(STDIN_FILENO, &fds_read);
timeval timeout = { m_window_timeout/1000, (m_window_timeout%1000)*1000 };
int fd_max = STDIN_FILENO;
for (FDCallbacks::const_iterator it = m_fds.begin(); it != m_fds.end(); ++it)
for (const auto &fd : m_fds)
{
if (it->first > fd_max)
fd_max = it->first;
FD_SET(it->first, &fdset);
if (fd.first > fd_max)
fd_max = fd.first;
FD_SET(fd.first, &fds_read);
}
if (select(fd_max+1, &fdset, 0, 0, m_window_timeout < 0 ? 0 : &timeout) > 0)
auto tv_addr = m_window_timeout < 0 ? nullptr : &timeout;
int res = select(fd_max+1, &fds_read, nullptr, nullptr, tv_addr);
if (res > 0)
{
if (FD_ISSET(STDIN_FILENO, &fdset))
result = getInputChar(wgetch(m_window));
if (FD_ISSET(STDIN_FILENO, &fds_read))
{
int key = wgetch(m_window);
if (key == EOF)
result = Key::EoF;
else
result = getInputChar(key);
}
else
result = Key::None;
for (FDCallbacks::const_iterator it = m_fds.begin(); it != m_fds.end(); ++it)
if (FD_ISSET(it->first, &fdset))
it->second();
for (const auto &fd : m_fds)
if (FD_ISSET(fd.first, &fds_read))
fd.second();
}
else
result = Key::None;

View File

@@ -124,6 +124,7 @@ const Type F10 = Special | 275;
const Type F11 = Special | 276;
const Type F12 = Special | 277;
const Type Mouse = Special | 278;
const Type EoF = Special | 279;
}