[ekg2-commit] r3899 - trunk/plugins/ncurses: +trunk/plugins/ncurses/commands-pl.txt trunk/plugins/ncurses/main.c trunk/plugins/ncurses/old.c trunk/plugins/ncurses/old.h

SVN commit svn w toxygen.net
Pią, 14 Mar 2008, 11:49:47 CET


Author: wiechu
Date: 2008-03-14 11:49:46 +0100 (Fri, 14 Mar 2008)
New Revision: 3899

Added:
   trunk/plugins/ncurses/commands-pl.txt
Modified:
   trunk/plugins/ncurses/main.c
   trunk/plugins/ncurses/old.c
   trunk/plugins/ncurses/old.h
Log:

New ncurses command: /mark
    Add thin red line to window.


Added: trunk/plugins/ncurses/commands-pl.txt
===================================================================
--- trunk/plugins/ncurses/commands-pl.txt	                        (rev 0)
+++ trunk/plugins/ncurses/commands-pl.txt	2008-03-14 10:49:46 UTC (rev 3899)
@@ -0,0 +1,6 @@
+mark
+	parametry:  [opcje]
+	krotki opis: dodaje znacznik do aktualnego okna
+	
+	-a, --all   dodaje znacznik do wszystkich nieaktywnych okien
+

Modified: trunk/plugins/ncurses/main.c
===================================================================
--- trunk/plugins/ncurses/main.c	2008-03-12 23:27:12 UTC (rev 3898)
+++ trunk/plugins/ncurses/main.c	2008-03-14 10:49:46 UTC (rev 3899)
@@ -648,6 +648,8 @@
 	query_connect_id(&ncurses_plugin, USERLIST_REMOVED, ncurses_all_contacts_changed, NULL);
 	query_connect_id(&ncurses_plugin, USERLIST_RENAMED, ncurses_all_contacts_changed, NULL);
 
+	command_add(&ncurses_plugin, ("mark"), NULL, cmd_mark, 0, "-a --all");
+
 #ifdef WITH_ASPELL
 	variable_add(&ncurses_plugin, ("aspell"), VAR_BOOL, 1, &config_aspell, ncurses_changed_aspell, NULL, NULL);
         variable_add(&ncurses_plugin, ("aspell_lang"), VAR_STR, 1, &config_aspell_lang, ncurses_changed_aspell, NULL, NULL);

Modified: trunk/plugins/ncurses/old.c
===================================================================
--- trunk/plugins/ncurses/old.c	2008-03-12 23:27:12 UTC (rev 3898)
+++ trunk/plugins/ncurses/old.c	2008-03-14 10:49:46 UTC (rev 3899)
@@ -952,6 +952,54 @@
 }
 
 /*
+ * cmd_mark()
+ *
+ * add marker (red line) to window
+ *
+ */
+COMMAND(cmd_mark) {
+	window_t *w;
+	ncurses_window_t *n;
+
+	if (match_arg(params[0], 'a', ("all"), 2)) {
+		list_t l;
+
+		for (l = windows; l; l = l->next) {
+			w = l->data;
+			if (!w->floating && (w->act != 2)) {
+				n = w->private;
+				n->last_red_line = time(0);
+				n->redraw = 1;
+			}
+		}
+		return 0;
+	}
+
+	w = window_current;
+	n = w->private;
+	n->last_red_line = time(0);
+	n->redraw = 1;
+
+	return 0;
+}
+
+/*
+ * draw_thin_red_line()
+ *
+ */
+static void draw_thin_red_line(window_t *w, int y)
+{
+	ncurses_window_t *n = w->private;
+	int x;
+	int attr = color_pair(COLOR_RED, COLOR_BLACK) | A_BOLD | A_ALTCHARSET;
+	unsigned char ch = (unsigned char) ncurses_fixchar((CHAR_T) ACS_HLINE, &attr);
+
+	wattrset(n->window, attr);
+	for (x = 0; x < w->width; x++)
+		mvwaddch(n->window, y, x, ch);
+}
+
+/*
  * ncurses_redraw()
  *
  * przerysowuje zawartość okienka.
@@ -960,8 +1008,12 @@
  */
 void ncurses_redraw(window_t *w)
 {
-	int x, y, left, top, height, width;
+	int x, y, left, top, height, width, fix_trl;
 	ncurses_window_t *n = w->private;
+	int dtrl = 0;	/* dtrl -- draw thin red line
+			 *	0 - not on this page or line already drawn
+			 *	1 - mayby on this page, we'll see later
+			 */
 	
 	if (!n)
 		return;
@@ -1043,18 +1095,35 @@
 			top = tmp;
 	}
 
+	fix_trl=0;
 	for (y = 0; y < height && n->start + y < n->lines_count; y++) {
 		struct screen_line *l = &n->lines[n->start + y];
 
-		int cur_y = (top + y);	
+		int cur_y = (top + y + fix_trl);
 		int cur_x;
 
 		int fixup = 0;
 
+		if (( y == 0 ) && n->last_red_line && (n->backlog[l->backlog]->ts < n->last_red_line))
+			dtrl = 1;	/* First line timestamp is less then mark. Mayby marker is on this page? */
+
+		if (dtrl && (n->backlog[l->backlog]->ts >= n->last_red_line)) {
+			draw_thin_red_line(w, cur_y);
+			if (n->lines_count-n->start == height) {
+				/* we have stolen line for marker, so we scroll up */
+				wmove(n->window, top, 0);
+				winsdelln(n->window,-1);
+			} else {
+				fix_trl = 1;
+				cur_y++;
+			}
+			dtrl = 0;
+		}
+
 		wattrset(n->window, A_NORMAL);
 
 		cur_x = (left);
-		
+
 		if (l->ts) {
 			/* XXX,
 			 * 	po co sprawdzamy l->ts[x] i l->ts_len? nie wystarczy jedno?
@@ -1109,6 +1178,16 @@
 
 	n->redraw = 0;
 
+	if (dtrl && (n->start + y >= n->lines_count)) {
+		/* marker still not drawn and last line from backlog. */
+		if (y >= height) {
+			wmove(n->window, top, 0);
+			winsdelln(n->window,-1);
+			y--;
+		}
+		draw_thin_red_line(w, top+y);
+	}
+
 	if (w == window_current)
 		ncurses_redraw_input(0);
 }

Modified: trunk/plugins/ncurses/old.h
===================================================================
--- trunk/plugins/ncurses/old.h	2008-03-12 23:27:12 UTC (rev 3898)
+++ trunk/plugins/ncurses/old.h	2008-03-14 10:49:46 UTC (rev 3899)
@@ -5,6 +5,7 @@
 
 #include "ecurses.h"
 
+#include <ekg/commands.h>
 #include <ekg/plugins.h>
 #include <ekg/themes.h>
 #include <ekg/windows.h>
@@ -78,6 +79,7 @@
 
 	CHAR_T *prompt_real;	/* prompt shortened to 2/3 of window width & converted to real chartype */
 	int prompt_real_len;	/* real prompt length, including cutting, in chars instead of bytes */
+	time_t last_red_line;	/* timestamp for red line marker */
 } ncurses_window_t;
 
 struct format_data {
@@ -163,6 +165,7 @@
 WATCHER(ncurses_watch_stdin);
 WATCHER(ncurses_watch_winch);
 int ncurses_command_window(void *data, va_list ap);
+COMMAND(cmd_mark);
 
 extern int have_winch_pipe;
 extern int winch_pipe[2];



Więcej informacji o liście dyskusyjnej ekg2-commit