MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "module.h"
}
}
+void statusbar_item_set_size(struct SBAR_ITEM_REC *item, int min_size, int max_size)
+{
+ item->min_size = min_size;
+ item->max_size = max_size;
+}
+
STATUSBAR_GROUP_REC *statusbar_group_create(const char *name)
{
STATUSBAR_GROUP_REC *rec;
return NULL;
}
-static char *update_statusbar_bg(const char *str, const char *color)
-{
- GString *out;
- char *ret;
-
- out = g_string_new(color);
- while (*str != '\0') {
- if (*str == '%' && str[1] == 'n') {
- g_string_append(out, color);
- str += 2;
- continue;
- }
-
- g_string_append_c(out, *str);
- str++;
- }
-
- ret = out->str;
- g_string_free(out, FALSE);
- return ret;
-}
-
-const char *statusbar_item_get_value(SBAR_ITEM_REC *item)
+static const char *statusbar_item_get_value(SBAR_ITEM_REC *item)
{
const char *value;
return value;
}
-static char *reverse_controls(const char *str)
+static GString *finalize_string(const char *str, const char *color)
{
GString *out;
- char *ret;
- out = g_string_new(NULL);
+ out = g_string_new(color);
while (*str != '\0') {
if ((unsigned char) *str < 32 ||
(term_type == TERM_TYPE_8BIT &&
(unsigned char) (*str & 0x7f) < 32)) {
/* control char */
- g_string_sprintfa(out, "%%8%c%%8",
+ g_string_append_printf(out, "%%8%c%%8",
'A'-1 + (*str & 0x7f));
+ } else if (*str == '%' && str[1] == 'n') {
+ g_string_append(out, color);
+ str++;
} else {
g_string_append_c(out, *str);
}
str++;
}
- ret = out->str;
- g_string_free(out, FALSE);
- return ret;
+ return out;
}
void statusbar_item_default_handler(SBAR_ITEM_REC *item, int get_size_only,
tmpstr = strip_codes(tmpstr2);
g_free(tmpstr2);
- /* show all control chars reversed */
- tmpstr2 = reverse_controls(tmpstr);
- g_free(tmpstr);
-
- tmpstr = tmpstr2;
if (get_size_only) {
item->min_size = item->max_size = format_get_length(tmpstr);
} else {
+ GString *out;
+
if (item->size < item->min_size) {
/* they're forcing us smaller than minimum size.. */
len = format_real_length(tmpstr, item->size);
tmpstr[len] = '\0';
- } else {
- /* make sure the str is big enough to fill the
- requested size, so it won't corrupt screen */
- len = format_get_length(tmpstr);
- if (len < item->size) {
- char *fill;
-
- len = item->size-len;
- fill = g_malloc(len + 1);
- memset(fill, ' ', len); fill[len] = '\0';
-
- tmpstr2 = g_strconcat(tmpstr, fill, NULL);
- g_free(fill);
- g_free(tmpstr);
- tmpstr = tmpstr2;
- }
+ }
+ out = finalize_string(tmpstr, item->bar->color);
+ /* make sure the str is big enough to fill the
+ requested size, so it won't corrupt screen */
+ len = format_get_length(tmpstr);
+ if (len < item->size) {
+ int i;
+
+ len = item->size-len;
+ for (i = 0; i < len; i++)
+ g_string_append_c(out, ' ');
}
- tmpstr2 = update_statusbar_bg(tmpstr, item->bar->color);
- gui_printtext(item->xpos, item->bar->real_ypos, tmpstr2);
- g_free(tmpstr2);
+ gui_printtext(item->xpos, item->bar->real_ypos, out->str);
+ g_string_free(out, TRUE);
}
g_free(tmpstr);
}