Merge Irssi 0.8.16-rc1
[silc.git] / apps / irssi / src / fe-text / gui-printtext.c
index affd2b9f518aa9601a24d20988f791bb0fbd4d92..2b5bfc5f0e40ebcdbbb94760f6ec2150821af2a1 100644 (file)
@@ -13,9 +13,9 @@
     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"
@@ -30,9 +30,8 @@
 #include "gui-windows.h"
 
 int mirc_colors[] = { 15, 0, 1, 2, 12, 4, 5, 6, 14, 10, 3, 11, 9, 13, 8, 7 };
-static int scrollback_lines, scrollback_hours, scrollback_burst_remove;
+static int scrollback_lines, scrollback_time, scrollback_burst_remove;
 
-static int last_fg, last_bg, last_flags;
 static int next_xpos, next_ypos;
 
 static GHashTable *indent_functions;
@@ -83,7 +82,8 @@ void gui_set_default_indent(const char *name)
 
        list = name == NULL ? NULL :
                g_hash_table_lookup(indent_functions, name);
-       default_indent_func = list == NULL ? NULL : list->data;
+       default_indent_func = list == NULL ? NULL :
+               (INDENT_FUNC) list->data;
         gui_windows_reset_settings();
 }
 
@@ -119,7 +119,7 @@ static void remove_old_lines(TEXT_BUFFER_VIEW_REC *view)
        LINE_REC *line;
        time_t old_time;
 
-       old_time = time(NULL)-(scrollback_hours*3600)+1;
+       old_time = time(NULL)-scrollback_time+1;
        if (view->buffer->lines_count >=
            scrollback_lines+scrollback_burst_remove) {
                 /* remove lines by line count */
@@ -129,7 +129,7 @@ static void remove_old_lines(TEXT_BUFFER_VIEW_REC *view)
                            scrollback_lines == 0) {
                                /* too new line, don't remove yet - also
                                   if scrollback_lines is 0, we want to check
-                                  only scrollback_hours setting. */
+                                  only scrollback_time setting. */
                                break;
                        }
                        textbuffer_view_remove_line(view, line);
@@ -144,10 +144,12 @@ static void get_colors(int flags, int *fg, int *bg, int *attr)
                   colors wrap to 0, 1, ... */
                 if (*bg >= 0) *bg = mirc_colors[*bg % 16];
                if (*fg >= 0) *fg = mirc_colors[*fg % 16];
+               if (settings_get_bool("mirc_blink_fix"))
+                       *bg &= ~0x08;
        }
 
        if (*fg < 0 || *fg > 15)
-               *fg = current_theme->default_color;
+               *fg = -1;
        if (*bg < 0 || *bg > 15)
                 *bg = -1;
 
@@ -158,66 +160,6 @@ static void get_colors(int flags, int *fg, int *bg, int *attr)
        if (flags & GUI_PRINT_FLAG_BLINK) *attr |= ATTR_BLINK;
 }
 
-static void line_add_colors(TEXT_BUFFER_REC *buffer, LINE_REC **line,
-                           int fg, int bg, int flags)
-{
-       unsigned char data[20];
-       int pos;
-
-        /* get the fg & bg command chars */
-       fg = fg < 0 ? LINE_COLOR_DEFAULT : fg & 0x0f;
-       bg = LINE_COLOR_BG | (bg < 0 ? LINE_COLOR_DEFAULT : bg & 0x0f);
-       if (flags & GUI_PRINT_FLAG_BOLD)
-               fg |= LINE_COLOR_BOLD;
-       if (flags & GUI_PRINT_FLAG_BLINK)
-                bg |= LINE_COLOR_BLINK;
-
-       pos = 0;
-       if (fg != last_fg) {
-               last_fg = fg;
-               data[pos++] = 0;
-               data[pos++] = fg == 0 ? LINE_CMD_COLOR0 : fg;
-       }
-       if (bg != last_bg) {
-                last_bg = bg;
-               data[pos++] = 0;
-               data[pos++] = bg;
-       }
-
-       if ((flags & GUI_PRINT_FLAG_UNDERLINE) != (last_flags & GUI_PRINT_FLAG_UNDERLINE)) {
-               data[pos++] = 0;
-               data[pos++] = LINE_CMD_UNDERLINE;
-       }
-       if ((flags & GUI_PRINT_FLAG_REVERSE) != (last_flags & GUI_PRINT_FLAG_REVERSE)) {
-               data[pos++] = 0;
-               data[pos++] = LINE_CMD_REVERSE;
-       }
-       if (flags & GUI_PRINT_FLAG_INDENT) {
-               data[pos++] = 0;
-               data[pos++] = LINE_CMD_INDENT;
-       }
-
-        if (pos > 0)
-               *line = textbuffer_insert(buffer, *line, data, pos, NULL);
-
-       last_flags = flags;
-}
-
-static void line_add_indent_func(TEXT_BUFFER_REC *buffer, LINE_REC **line,
-                                const char *function)
-{
-        GSList *list;
-        unsigned char data[1+sizeof(INDENT_FUNC)];
-
-        list = g_hash_table_lookup(indent_functions, function);
-       if (list != NULL) {
-               data[0] = LINE_CMD_INDENT_FUNC;
-               memcpy(data+1, list->data, sizeof(INDENT_FUNC));
-               *line = textbuffer_insert(buffer, *line,
-                                         data, sizeof(data), NULL);
-       }
-}
-
 static void view_add_eol(TEXT_BUFFER_VIEW_REC *view, LINE_REC **line)
 {
        static const unsigned char eol[] = { 0, LINE_CMD_EOL };
@@ -228,7 +170,7 @@ static void view_add_eol(TEXT_BUFFER_VIEW_REC *view, LINE_REC **line)
 
 static void sig_gui_print_text(WINDOW_REC *window, void *fgcolor,
                               void *bgcolor, void *pflags,
-                              char *str, void *level)
+                              char *str, TEXT_DEST_REC *dest)
 {
         GUI_WINDOW_REC *gui;
         TEXT_BUFFER_VIEW_REC *view;
@@ -252,11 +194,11 @@ static void sig_gui_print_text(WINDOW_REC *window, void *fgcolor,
                if (flags & GUI_PRINT_FLAG_CLRTOEOL)
                        term_clrtoeol(root_window);
                term_addstr(root_window, str);
-               next_xpos += strlen(str);
+               next_xpos += strlen(str); /* FIXME utf8 or big5 */
                 return;
        }
 
-       lineinfo.level = GPOINTER_TO_INT(level);
+       lineinfo.level = dest == NULL ? 0 : dest->level;
         lineinfo.time = time(NULL);
 
         gui = WINDOW_GUI(window);
@@ -264,18 +206,14 @@ static void sig_gui_print_text(WINDOW_REC *window, void *fgcolor,
        insert_after = gui->use_insert_after ?
                gui->insert_after : view->buffer->cur_line;
 
-       if (flags & GUI_PRINT_FLAG_NEWLINE)
+       if (flags & GUI_PRINT_FLAG_NEWLINE) {
                 view_add_eol(view, &insert_after);
-       line_add_colors(view->buffer, &insert_after, fg, bg, flags);
-
-       if (flags & GUI_PRINT_FLAG_INDENT_FUNC) {
-               /* specify the indentation function */
-                line_add_indent_func(view->buffer, &insert_after, str);
-       } else {
-               insert_after = textbuffer_insert(view->buffer, insert_after,
-                                                (unsigned char *) str,
-                                                strlen(str), &lineinfo);
        }
+       textbuffer_line_add_colors(view->buffer, &insert_after, fg, bg, flags);
+
+       insert_after = textbuffer_insert(view->buffer, insert_after,
+                                        (unsigned char *) str,
+                                        strlen(str), &lineinfo);
        if (gui->use_insert_after)
                 gui->insert_after = insert_after;
 }
@@ -285,9 +223,6 @@ static void sig_gui_printtext_finished(WINDOW_REC *window)
        TEXT_BUFFER_VIEW_REC *view;
        LINE_REC *insert_after;
 
-        last_fg = last_bg = -1;
-       last_flags = 0;
-
        view = WINDOW_GUI(window)->view;
        insert_after = WINDOW_GUI(window)->use_insert_after ?
                WINDOW_GUI(window)->insert_after : view->buffer->cur_line;
@@ -299,7 +234,7 @@ static void sig_gui_printtext_finished(WINDOW_REC *window)
 static void read_settings(void)
 {
        scrollback_lines = settings_get_int("scrollback_lines");
-       scrollback_hours = settings_get_int("scrollback_hours");
+       scrollback_time = settings_get_time("scrollback_time")/1000;
         scrollback_burst_remove = settings_get_int("scrollback_burst_remove");
 }
 
@@ -311,7 +246,7 @@ void gui_printtext_init(void)
                                            (GCompareFunc) g_str_equal);
 
        settings_add_int("history", "scrollback_lines", 500);
-       settings_add_int("history", "scrollback_hours", 24);
+       settings_add_time("history", "scrollback_time", "1day");
        settings_add_int("history", "scrollback_burst_remove", 10);
 
        signal_add("gui print text", (SIGNAL_FUNC) sig_gui_print_text);