1 /***************************************************************************
2 * Copyright (C) 2008-2014 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
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. *
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. *
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>
27 #include "interfaces.h"
30 namespace Progressbar
{
34 ScopedLock() noexcept
;
35 ~ScopedLock() noexcept
;
38 /// @return true if progressbar is unlocked
42 void draw(unsigned elapsed
, unsigned time
);
50 ScopedLock() noexcept
;
51 ~ScopedLock() noexcept
;
54 /// @return true if statusbar is unlocked
57 /// tries to clear current message put there using Statusbar::printf if there is any
60 /// clears statusbar and move cursor to beginning of line
61 /// @return window object that represents statusbar
66 /// called when statusbar window detects incoming idle notification
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
))
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();
89 std::vector
<std::string
> m_values
;
92 struct FindImmediately
94 FindImmediately(Searchable
*w
, SearchDirection direction
)
95 : m_w(w
), m_direction(direction
), m_found(true)
98 bool operator()(const char *s
);
102 const SearchDirection m_direction
;
107 struct TryExecuteImmediateCommand
109 bool operator()(const char *s
);
117 /// displays message in statusbar for a given period of time
118 void print(int delay
, const std::string
& message
);
120 /// displays message in statusbar for period of time set in configuration file
121 inline void print(const std::string
&message
)
123 print(Config
.message_delay_time
, message
);
126 /// displays formatted message in statusbar for period of time set in configuration file
127 template <typename FormatT
>
128 void printf(FormatT
&&fmt
)
130 print(Config
.message_delay_time
, boost::format(std::forward
<FormatT
>(fmt
)).str());
132 template <typename FormatT
, typename ArgT
, typename
... Args
>
133 void printf(FormatT
&&fmt
, ArgT
&&arg
, Args
&&... args
)
135 printf(boost::format(std::forward
<FormatT
>(fmt
)) % std::forward
<ArgT
>(arg
),
136 std::forward
<Args
>(args
)...
140 /// displays formatted message in statusbar for a given period of time
141 template <typename FormatT
>
142 void printf(int delay
, FormatT
&&fmt
)
144 print(delay
, boost::format(std::forward
<FormatT
>(fmt
)).str());
146 template <typename FormatT
, typename ArgT
, typename
... Args
>
147 void printf(int delay
, FormatT
&&fmt
, ArgT
&&arg
, Args
&&... args
)
149 printf(delay
, boost::format(std::forward
<FormatT
>(fmt
)) % std::forward
<ArgT
>(arg
),
150 std::forward
<Args
>(args
)...
156 #endif // NCMPCPP_STATUSBAR_H