1 // Copyright (C) 2011-2015 Petr Pavlu <setup@dagobah.cz>
3 // This file is part of CenterIM.
5 // CenterIM 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 // CenterIM 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 CenterIM. If not, see <http://www.gnu.org/licenses/>.
20 #include <cppconsui/KeyConfig.h>
24 Footer
*Footer::my_instance_
= nullptr;
26 Footer
*Footer::instance()
31 void Footer::onScreenResized()
33 moveResizeRect(CENTERIM
->getScreenArea(CenterIM::FOOTER_AREA
));
36 void Footer::setText(const char *fmt
, ...)
45 values_
.push_back(std::string(fmt
));
49 while (*fmt
!= '\0') {
51 if (*(fmt
+ 1) == '%')
53 else if (*(fmt
+ 1) == 's') {
54 const char *v
= va_arg(args
, const char *);
55 values_
.push_back(std::string(v
));
66 Footer::Footer() : Window(0, 24, 80, 1, TYPE_NON_FOCUSABLE
, false)
68 setColorScheme(CenterIM::SCHEME_FOOTER
);
70 label_
= new CppConsUI::Label
;
71 addWidget(*label_
, 0, 0);
78 g_assert(my_instance_
== nullptr);
80 my_instance_
= new Footer
;
84 void Footer::finalize()
86 g_assert(my_instance_
!= nullptr);
89 my_instance_
= nullptr;
92 void Footer::updateText()
94 if (values_
.empty()) {
95 label_
->setText(nullptr);
99 Values::iterator i
= values_
.begin();
100 const char *fmt
= i
->c_str();
106 while (*fmt
!= '\0' && cur_out
< out
+ sizeof(out
) - 1) {
108 if (*(fmt
+ 1) == '%')
110 else if (*(fmt
+ 1) == 's') {
111 char *con
= g_strdup(i
->c_str());
113 char *act
= std::strstr(con
, "|");
116 const char *key
= KEYCONFIG
->getKeyBind(con
, act
);
119 std::strncpy(cur_out
, key
, out
+ sizeof(out
) - 1 - cur_out
);
120 cur_out
+= std::strlen(key
);
130 label_
->setText(out
);
133 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab: