On Mon, 2014-03-24 at 15:14 +0100, David Heidelberger wrote:
Oh, try "patch -p1 < file" with attached file.

Look like email client damaged some spaces or something.
============================================

Add colored output to iftop.

Based on https://github.com/srix/iftopcolor

Signed-off-by: David Heidelberger <david.heidelberger@ixit.cz>
---
diff -Naur a/ui.c b/ui.c
--- a/ui.c	2014-01-08 14:00:48.776905827 +0100
+++ b/ui.c	2014-01-08 14:07:51.064903944 +0100
@@ -51,6 +51,9 @@
  "\n"\
  "iftop, version " IFTOP_VERSION

+#define COLOR_SENT 1
+#define COLOR_RECV 2
+#define COLOR_BOTH 3

  extern hash_type* history;
  extern int history_pos;
@@ -199,12 +202,13 @@
      }
  }

-void draw_bar(float n, int y) {
+void draw_bar(float n, int y, short colorpair) {
      int L;
+    colorpair = has_colors() ? colorpair : 0; /* set 0 if terminal is 
not color capable*/
      mvchgat(y, 0, -1, A_NORMAL, 0, NULL);
      L = get_bar_length(8 * n);
      if (L > 0)
-        mvchgat(y, 0, L + 1, A_REVERSE, 0, NULL);
+        mvchgat(y, 0, L + 1, A_REVERSE, colorpair, NULL);
  }

  void draw_line_totals(int y, host_pair_line* line, option_linedisplay_t 
linedisplay) {
@@ -219,17 +223,17 @@
      if(options.showbars) {
        switch(linedisplay) {
          case OPTION_LINEDISPLAY_TWO_LINE:
-          draw_bar(line->sent[options.bar_interval],y);
-          draw_bar(line->recv[options.bar_interval],y+1);
+          draw_bar(line->sent[options.bar_interval],y,  COLOR_SENT);
+          draw_bar(line->recv[options.bar_interval],y+1, COLOR_RECV);
            break;
          case OPTION_LINEDISPLAY_ONE_LINE_SENT:
-          draw_bar(line->sent[options.bar_interval],y);
+          draw_bar(line->sent[options.bar_interval],y,COLOR_SENT);
            break;
          case OPTION_LINEDISPLAY_ONE_LINE_RECV:
-          draw_bar(line->recv[options.bar_interval],y);
+          draw_bar(line->recv[options.bar_interval],y,COLOR_RECV);
            break;
          case OPTION_LINEDISPLAY_ONE_LINE_BOTH:
-          draw_bar(line->recv[options.bar_interval] + 
line->sent[options.bar_interval],y);
+          draw_bar(line->recv[options.bar_interval] + 
line->sent[options.bar_interval],y, COLOR_BOTH);
            break;
        }
      }
@@ -428,6 +432,13 @@

  void ui_curses_init() {
      (void) initscr();      /* initialize the curses library */
+    if (has_colors()) {
+	start_color();
+	use_default_colors();
+	init_pair(COLOR_RECV, COLOR_GREEN, -1);
+	init_pair(COLOR_SENT, COLOR_BLUE, -1);
+	init_pair(COLOR_BOTH, COLOR_MAGENTA, -1);
+    }
      keypad(stdscr, TRUE);  /* enable keyboard mapping */
      (void) nonl();         /* tell curses not to do NL->CR/NL on output 
*/
      (void) cbreak();       /* take input chars one at a time, no wait 
for \n */
---


Dne 2014-03-24 13:54, James Lay napsal:

> On Wed, 2014-03-19 at 18:05 +0100, David Heidelberger wrote:
> 
>> Add colored output to iftop.
>> 
>> Based on https://github.com/srix/iftopcolor [1]
>> 
>> Signed-off-by: David Heidelberger <david.heidelberger@ixit.cz>
>> ---
>> diff -Naur a/ui.c b/ui.c
>> --- a/ui.c 2014-01-08 14:00:48.776905827 +0100
>> +++ b/ui.c 2014-01-08 14:07:51.064903944 +0100
>> @@ -51,6 +51,9 @@
>> "n"
>> "iftop, version " IFTOP_VERSION
>> 
>> +#define COLOR_SENT 1
>> +#define COLOR_RECV 2
>> +#define COLOR_BOTH 3
>> 
>> extern hash_type* history;
>> extern int history_pos;
>> @@ -199,12 +202,13 @@
>> }
>> }
>> 
>> -void draw_bar(float n, int y) {
>> +void draw_bar(float n, int y, short colorpair) {
>> int L;
>> + colorpair = has_colors() ? colorpair : 0; /* set 0 if terminal is
>> not color capable*/
>> mvchgat(y, 0, -1, A_NORMAL, 0, NULL);
>> L = get_bar_length(8 * n);
>> if (L > 0)
>> - mvchgat(y, 0, L + 1, A_REVERSE, 0, NULL);
>> + mvchgat(y, 0, L + 1, A_REVERSE, colorpair, NULL);
>> }
>> 
>> void draw_line_totals(int y, host_pair_line* line, 
>> option_linedisplay_t
>> linedisplay) {
>> @@ -219,17 +223,17 @@
>> if(options.showbars) {
>> switch(linedisplay) {
>> case OPTION_LINEDISPLAY_TWO_LINE:
>> - draw_bar(line->sent[options.bar_interval],y);
>> - draw_bar(line->recv[options.bar_interval],y+1);
>> + draw_bar(line->sent[options.bar_interval],y, COLOR_SENT);
>> + draw_bar(line->recv[options.bar_interval],y+1, COLOR_RECV);
>> break;
>> case OPTION_LINEDISPLAY_ONE_LINE_SENT:
>> - draw_bar(line->sent[options.bar_interval],y);
>> + draw_bar(line->sent[options.bar_interval],y,COLOR_SENT);
>> break;
>> case OPTION_LINEDISPLAY_ONE_LINE_RECV:
>> - draw_bar(line->recv[options.bar_interval],y);
>> + draw_bar(line->recv[options.bar_interval],y,COLOR_RECV);
>> break;
>> case OPTION_LINEDISPLAY_ONE_LINE_BOTH:
>> - draw_bar(line->recv[options.bar_interval] +
>> line->sent[options.bar_interval],y);
>> + draw_bar(line->recv[options.bar_interval] +
>> line->sent[options.bar_interval],y, COLOR_BOTH);
>> break;
>> }
>> }
>> @@ -428,6 +432,13 @@
>> 
>> void ui_curses_init() {
>> (void) initscr(); /* initialize the curses library */
>> + if (has_colors()) {
>> + start_color();
>> + use_default_colors();
>> + init_pair(COLOR_RECV, COLOR_GREEN, -1);
>> + init_pair(COLOR_SENT, COLOR_BLUE, -1);
>> + init_pair(COLOR_BOTH, COLOR_MAGENTA, -1);
>> + }
>> keypad(stdscr, TRUE); /* enable keyboard mapping */
>> (void) nonl(); /* tell curses not to do NL->CR/NL on output
>> */
>> (void) cbreak(); /* take input chars one at a time, no wait
>> for n */
>> 
>> _______________________________________________
>> iftop-users mailing list
>> iftop-users@lists.beasts.org
>> http://lists.beasts.org/mailman/listinfo/iftop-users [2]
> 
> I couldn't get this to apply to either 0.17 or 1.0pre4...unless I'm 
> doing something radically wrong. Download, untar and:
> 
> patch -p0 < patch.diff
> 
> Yes? Thank you...this will be cool when I get it working.
> 
> James


Links:
------
[1] https://github.com/srix/iftopcolor
[2] http://lists.beasts.org/mailman/listinfo/iftop-users

Thanks Dave,

-p1 worked with this


[12:05:02 jlay@gateway:~/iftop-1.0pre4$] patch -p1 < color.patch
patching file ui.c
Hunk #1 succeeded at 53 with fuzz 2 (offset 2 lines).
Hunk #2 succeeded at 204 (offset 2 lines).
Hunk #3 succeeded at 225 (offset 2 lines).
Hunk #4 succeeded at 434 (offset 2 lines).

James