diff mcabber/src/screen.c @ 108:7fb72bc13732

[/trunk] Changeset 122 by mikael * Add /clear command.
author mikael
date Fri, 22 Apr 2005 22:06:53 +0000
parents 91d3ec21c24e
children 96d239239c7a
line wrap: on
line diff
--- a/mcabber/src/screen.c	Fri Apr 22 21:43:25 2005 +0000
+++ b/mcabber/src/screen.c	Fri Apr 22 22:06:53 2005 +0000
@@ -24,10 +24,11 @@
 
 typedef struct _window_entry_t {
   WINDOW *win;
-  PANEL *panel;
-  char *name;
-  GList *hbuf;
-  GList *top; // If top is not specified (NULL), we'll display the last lines
+  PANEL  *panel;
+  char   *name;
+  GList  *hbuf;
+  GList  *top; // If top is not specified (NULL), we'll display the last lines
+  char    cleared; // For ex, user has issued a /clear command...
   struct list_head list;
 } window_entry_t;
 
@@ -226,6 +227,14 @@
   char **lines;
   GList *hbuf_head;
 
+  width = scr_WindowWidth(win_entry->win);
+
+  // Should the window be empty?
+  if (win_entry->cleared) {
+    scr_clear_box(win_entry->win, 0, 0, CHAT_WIN_HEIGHT, width, COLOR_GENERAL);
+    return;
+  }
+
   // win_entry->top is the top message of the screen.  If it set to NULL, we
   // are displaying the last messages.
 
@@ -249,7 +258,6 @@
   lines = hbuf_get_lines(hbuf_head, CHAT_WIN_HEIGHT);
 
   // Display these lines
-  width = scr_WindowWidth(win_entry->win);
   wmove(win_entry->win, 0, 0);
   for (n = 0; n < CHAT_WIN_HEIGHT; n++) {
     int r = width;
@@ -347,6 +355,11 @@
                 maxX - scr_WindowWidth(rosterWnd) - 14);
   free(fullprefix);
 
+  if (win_entry->cleared) {
+    win_entry->cleared = 0; // The message must be displayed
+    win_entry->top = g_list_last(win_entry->hbuf);
+  }
+
   if (!dont_show) {
     // Show and refresh the window
     top_panel(win_entry->panel);
@@ -674,6 +687,31 @@
   doupdate();
 }
 
+void scr_Clear(void)
+{
+  const gchar *jid;
+  window_entry_t *win_entry;
+
+  // Get win_entry
+  if (!current_buddy)
+    return;
+  jid = CURRENT_JID;
+  if (!jid)
+    return;
+  win_entry  = scr_SearchWindow(jid);
+  if (!win_entry)
+    return;
+
+  win_entry->cleared = TRUE;
+
+  // Refresh the window
+  scr_UpdateWindow(win_entry);
+
+  // Finished :)
+  update_panels();
+  doupdate();
+}
+
 //  scr_LogPrint(...)
 // Display a message in the log window.
 void scr_LogPrint(const char *fmt, ...)