Move ncurses related files to curses directory
[ncmpcpp.git] / src / statusbar.h
blob23ca1a7b6b1539407ae512f60ab19af5a1a1fac6
1 /***************************************************************************
2 * Copyright (C) 2008-2016 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #ifndef NCMPCPP_STATUSBAR_H
22 #define NCMPCPP_STATUSBAR_H
24 #include <boost/format.hpp>
25 #include "curses/window.h"
26 #include "settings.h"
27 #include "gcc.h"
28 #include "interfaces.h"
30 namespace Progressbar {
32 struct ScopedLock
34 ScopedLock() noexcept;
35 ~ScopedLock() noexcept;
38 /// @return true if progressbar is unlocked
39 bool isUnlocked();
41 /// draws progressbar
42 void draw(unsigned elapsed, unsigned time);
46 namespace Statusbar {
48 struct ScopedLock
50 ScopedLock() noexcept;
51 ~ScopedLock() noexcept;
54 /// @return true if statusbar is unlocked
55 bool isUnlocked();
57 /// tries to clear current message put there using Statusbar::printf if there is any
58 void tryRedraw();
60 /// clears statusbar and move cursor to beginning of line
61 /// @return window object that represents statusbar
62 NC::Window &put();
64 namespace Helpers {
66 /// called when statusbar window detects incoming idle notification
67 void mpd();
69 /// called each time user types another character while inside Window::getString
70 bool mainHook(const char *);
72 /// prompt and return one of the strings specified in the vector
73 std::string promptReturnOneOf(std::vector<std::string> values);
75 struct ImmediatelyReturnOneOf
77 ImmediatelyReturnOneOf(std::vector<std::string> arg)
78 : m_values(std::move(arg))
79 { }
81 bool operator()(const char *s) const;
83 template <typename StringT>
84 bool isOneOf(StringT &&s) const {
85 return std::find(m_values.begin(), m_values.end(), std::forward<StringT>(s)) != m_values.end();
88 private:
89 std::vector<std::string> m_values;
92 struct ApplyFilterImmediately
94 ApplyFilterImmediately(Filterable *w)
95 : m_w(w)
96 { }
98 bool operator()(const char *s);
100 private:
101 Filterable *m_w;
104 struct FindImmediately
106 FindImmediately(Searchable *w, SearchDirection direction)
107 : m_w(w), m_direction(direction)
110 bool operator()(const char *s);
112 private:
113 Searchable *m_w;
114 const SearchDirection m_direction;
117 struct TryExecuteImmediateCommand
119 bool operator()(const char *s);
121 private:
122 std::string m_s;
127 /// displays message in statusbar for a given period of time
128 void print(int delay, const std::string& message);
130 /// displays message in statusbar for period of time set in configuration file
131 inline void print(const std::string &message)
133 print(Config.message_delay_time, message);
136 /// displays formatted message in statusbar for period of time set in configuration file
137 template <typename FormatT>
138 void printf(FormatT &&fmt)
140 print(Config.message_delay_time, boost::format(std::forward<FormatT>(fmt)).str());
142 template <typename FormatT, typename ArgT, typename... Args>
143 void printf(FormatT &&fmt, ArgT &&arg, Args&&... args)
145 printf(boost::format(std::forward<FormatT>(fmt)) % std::forward<ArgT>(arg),
146 std::forward<Args>(args)...
150 /// displays formatted message in statusbar for a given period of time
151 template <typename FormatT>
152 void printf(int delay, FormatT &&fmt)
154 print(delay, boost::format(std::forward<FormatT>(fmt)).str());
156 template <typename FormatT, typename ArgT, typename... Args>
157 void printf(int delay, FormatT &&fmt, ArgT &&arg, Args&&... args)
159 printf(delay, boost::format(std::forward<FormatT>(fmt)) % std::forward<ArgT>(arg),
160 std::forward<Args>(args)...
166 #endif // NCMPCPP_STATUSBAR_H