[Iftop-users] [PATCH] Add colored output to iftop
James Lay
jlay at slave-tothe-box.net
Mon, 24 Mar 2014 06:54:44 -0600
--=-oYcildRDn8GHjf1bb8hs
Content-Type: multipart/alternative; boundary="=-k66q1CW+6PVHyvIrbBRq"
--=-k66q1CW+6PVHyvIrbBRq
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
On Wed, 2014-03-19 at 18:05 +0100, David Heidelberger wrote:
> Add colored output to iftop.
>=20
> Based on https://github.com/srix/iftopcolor
>=20
> 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
>=20
> +#define COLOR_SENT 1
> +#define COLOR_RECV 2
> +#define COLOR_BOTH 3
>=20
> extern hash_type* history;
> extern int history_pos;
> @@ -199,12 +202,13 @@
> }
> }
>=20
> -void draw_bar(float n, int y) {
> +void draw_bar(float n, int y, short colorpair) {
> int L;
> + colorpair =3D has_colors() ? colorpair : 0; /* set 0 if terminal is=
=20
> not color capable*/
> mvchgat(y, 0, -1, A_NORMAL, 0, NULL);
> L =3D 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);
> }
>=20
> void draw_line_totals(int y, host_pair_line* line, option_linedisplay_t=
=20
> 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] +=20
> line->sent[options.bar_interval],y);
> + draw_bar(line->recv[options.bar_interval] +=20
> line->sent[options.bar_interval],y, COLOR_BOTH);
> break;
> }
> }
> @@ -428,6 +432,13 @@
>=20
> 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=
=20
> */
> (void) cbreak(); /* take input chars one at a time, no wait=
=20
> for \n */
>=20
> _______________________________________________
> iftop-users mailing list
> iftop-users@lists.beasts.org
> http://lists.beasts.org/mailman/listinfo/iftop-users
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
--=-k66q1CW+6PVHyvIrbBRq
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; CHARSET=3DUTF-8">
<META NAME=3D"GENERATOR" CONTENT=3D"GtkHTML/4.6.6">
</HEAD>
<BODY>
On Wed, 2014-03-19 at 18:05 +0100, David Heidelberger wrote:
<BLOCKQUOTE TYPE=3DCITE>
<PRE>
Add colored output to iftop.
Based on <A HREF=3D"https://github.com/srix/iftopcolor">https://github.com/=
srix/iftopcolor</A>
Signed-off-by: David Heidelberger <<A HREF=3D"mailto:david.heidelberger@=
ixit.cz">david.heidelberger@ixit.cz</A>>
---
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 =3D has_colors() ? colorpair : 0; /* set 0 if terminal is=
=20
not color capable*/
mvchgat(y, 0, -1, A_NORMAL, 0, NULL);
L =3D 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=
=20
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] +=20
line->sent[options.bar_interval],y);
+ draw_bar(line->recv[options.bar_interval] +=20
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 outpu=
t=20
*/
(void) cbreak(); /* take input chars one at a time, no wait=20
for \n */
_______________________________________________
iftop-users mailing list
<A HREF=3D"mailto:iftop-users@lists.beasts.org">iftop-users@lists.beasts.or=
g</A>
<A HREF=3D"http://lists.beasts.org/mailman/listinfo/iftop-users">http://lis=
ts.beasts.org/mailman/listinfo/iftop-users</A>
</PRE>
</BLOCKQUOTE>
<BR>
I couldn't get this to apply to either 0.17 or 1.0pre4...unless I'm doing s=
omething radically wrong. Download, untar and:<BR>
<BR>
patch -p0 < patch.diff<BR>
<BR>
Yes? Thank you...this will be cool when I get it working.<BR>
<BR>
James
</BODY>
</HTML>
--=-k66q1CW+6PVHyvIrbBRq--
--=-oYcildRDn8GHjf1bb8hs
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: This is a digitally signed message part
Content-Transfer-Encoding: 7bit
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.14 (GNU/Linux)
iQEcBAABAgAGBQJTMCsUAAoJEIOvN0kaoY6s7mkIAKGUhv7lfI4tanj3txf2HL29
mEIyHO9qivdwLfWj2v02NkWPgM9PBwt8ZPh9QYVjEPAUCCwflFyER/BLsCVLQhKC
DNA83KixHv+AGBuAIVcHEWwNkVBq/d+oWrYMNgfftISWI18Ot0+KcqN5EZB/Nugf
fb+F0YCn15clK1w5CcjNREZFE7MViLVhII5PmjY7x8kMOMX29awOOzgssbzYRqtR
DPMr4A9LTCv+hIosBI6W4zZk5eRelnRYqUMu4AahvkOs77qCROUM2fUZmMM97CJg
ZJKugOD9t3AMoJFk547KJkwF3jKnS/0cq8IelotGuMebxEq+PZtXas+NCOs7+cw=
=wr9Q
-----END PGP SIGNATURE-----
--=-oYcildRDn8GHjf1bb8hs--