Added SILC Thread Queue API
[crypto.git] / apps / irssi / src / fe-text / statusbar.c
index 7f3bbe3c258fb04b9682171d708236904198c4a6..5eba9557f9ace85104067cf6b8687e3a930794ef 100644 (file)
@@ -653,13 +653,39 @@ 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)
 {
        SERVER_REC *server;
-       WI_ITEM_REC *wiitem;
-        char *tmpstr, *tmpstr2;
+       WI_ITEM_REC *wiitem; 
+       char *tmpstr, *tmpstr2;
        int len;
 
        if (str == NULL)
@@ -673,8 +699,9 @@ void statusbar_item_default_handler(SBAR_ITEM_REC *item, int get_size_only,
                server = NULL;
                 wiitem = NULL;
        } else {
-               server = active_win->active_server;
-                wiitem = active_win->active;
+               server = active_win->active_server != NULL ?
+                       active_win->active_server : active_win->connect_server;
+               wiitem = active_win->active;
        }
 
        /* expand templates */
@@ -693,6 +720,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 {
@@ -700,6 +732,22 @@ void statusbar_item_default_handler(SBAR_ITEM_REC *item, int get_size_only,
                         /* 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;
+                       }
                }
 
                tmpstr2 = update_statusbar_bg(tmpstr, item->bar->color);
@@ -828,8 +876,11 @@ static void statusbar_item_default_signals(SBAR_ITEM_REC *item)
                                 func = NULL;
                                 break;
                        }
-                        if (func != NULL)
-                               signal_add_to_id(MODULE_NAME, 1, *pos, func);
+                       if (func != NULL) {
+                               signal_add_full_id(MODULE_NAME,
+                                                  SIGNAL_PRIORITY_DEFAULT,
+                                                  *pos, func, NULL);
+                       }
                }
 
                if (g_slist_find(list, item) == NULL)
@@ -880,10 +931,10 @@ SBAR_ITEM_REC *statusbar_item_create(STATUSBAR_REC *bar,
 
 static void statusbar_signal_remove(int signal_id)
 {
-       signal_remove_id(signal_id, (SIGNAL_FUNC) statusbar_update_item);
-       signal_remove_id(signal_id, (SIGNAL_FUNC) statusbar_update_server);
-       signal_remove_id(signal_id, (SIGNAL_FUNC) statusbar_update_window);
-       signal_remove_id(signal_id, (SIGNAL_FUNC) statusbar_update_window_item);
+       signal_remove_id(signal_id, (SIGNAL_FUNC) statusbar_update_item, NULL);
+       signal_remove_id(signal_id, (SIGNAL_FUNC) statusbar_update_server, NULL);
+       signal_remove_id(signal_id, (SIGNAL_FUNC) statusbar_update_window, NULL);
+       signal_remove_id(signal_id, (SIGNAL_FUNC) statusbar_update_window_item, NULL);
 }
 
 static void statusbar_item_remove_signal(SBAR_ITEM_REC *item, int signal_id)