Merged Irssi 0.8.2 from irssi.org cvs.
[silc.git] / apps / irssi / src / fe-text / statusbar.c
index a9271b3cf7808a6fb42c47f65c2da3698d66e5ed..9d39ede790e8c68bbe83a94df7d975d33e2ba364 100644 (file)
@@ -231,8 +231,7 @@ static void statusbar_resize_items(STATUSBAR_REC *bar, int max_width)
 }
 
 #define SBAR_ITEM_REDRAW_NEEDED(_bar, _item, _xpos) \
-       (((_bar)->dirty_xpos != -1 && \
-         (_xpos) >= (_bar)->dirty_xpos) || \
+       (((_bar)->dirty_xpos != -1 && (_xpos) >= (_bar)->dirty_xpos) || \
         (_item)->xpos != (_xpos) || (_item)->current_size != (_item)->size)
 
 static void statusbar_calc_item_positions(STATUSBAR_REC *bar)
@@ -279,7 +278,9 @@ static void statusbar_calc_item_positions(STATUSBAR_REC *bar)
                if (rec->config->right_alignment) {
                         if (rec->size > 0)
                                right_items = g_slist_prepend(right_items, rec);
-                       else if (rec->current_size > 0) {
+                       else if (rec->current_size > 0 &&
+                                (bar->dirty_xpos == -1 ||
+                                 rec->xpos < bar->dirty_xpos)) {
                                /* item was hidden - set the dirty position
                                   to begin from the item's old xpos */
                                irssi_set_dirty();
@@ -652,6 +653,32 @@ const char *statusbar_item_get_value(SBAR_ITEM_REC *item)
         return value;
 }
 
+static char *reverse_controls(const char *str)
+{
+       GString *out;
+        char *ret;
+
+       out = g_string_new(NULL);
+
+       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",
+                                         'A'-1 + (*str & 0x7f));
+               } else {
+                       g_string_append_c(out, *str);
+               }
+
+               str++;
+       }
+
+       ret = out->str;
+        g_string_free(out, FALSE);
+       return ret;
+}
+
 void statusbar_item_default_handler(SBAR_ITEM_REC *item, int get_size_only,
                                    const char *str, const char *data,
                                    int escape_vars)
@@ -692,6 +719,11 @@ 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 {
@@ -1069,10 +1101,8 @@ static void statusbar_item_signal_destroy(void *key, GSList *value)
         g_slist_free(value);
 }
 
-static void sig_setup_reload(void)
+void statusbars_create_window_bars(void)
 {
-       /* statusbar-config.c recreates root statusbars,
-          we need to create window-statusbars */
         g_slist_foreach(mainwindows, (GFunc) statusbars_add_visible, NULL);
 }
 
@@ -1098,7 +1128,6 @@ void statusbar_init(void)
        signal_add("gui window created", (SIGNAL_FUNC) sig_gui_window_created);
        signal_add("window changed", (SIGNAL_FUNC) sig_window_changed);
        signal_add("mainwindow destroyed", (SIGNAL_FUNC) sig_mainwindow_destroyed);
-       signal_add_last("setup reread", (SIGNAL_FUNC) sig_setup_reload);
 
        statusbar_items_init();
        statusbar_config_init(); /* signals need to be before this call */
@@ -1130,7 +1159,6 @@ void statusbar_deinit(void)
        signal_remove("gui window created", (SIGNAL_FUNC) sig_gui_window_created);
        signal_remove("window changed", (SIGNAL_FUNC) sig_window_changed);
        signal_remove("mainwindow destroyed", (SIGNAL_FUNC) sig_mainwindow_destroyed);
-       signal_remove("setup reread", (SIGNAL_FUNC) sig_setup_reload);
 
        statusbar_items_deinit();
        statusbar_config_deinit();