Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for coloured output. #96

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/fping.pod
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ Print usage message.
The minimum amount of time (in milliseconds) between sending a ping packet
to any target (default is 25).

=item B<-k>

Colourise the output.

=item B<-l>

Loop sending packets to each target indefinitely. Can be interrupted with
Expand Down
24 changes: 22 additions & 2 deletions src/fping.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ extern int h_errno;

/*** Constants ***/

#define EMAIL "david@schweikert.ch"
#define EMAIL "david@schweikert.ch"
#define ANSI_COLOUR_RED "\x1b[31m"
#define ANSI_COLOUR_GREEN "\x1b[32m"
#define ANSI_COLOUR_RESET "\x1b[0m"

/*** Ping packet defines ***/

Expand Down Expand Up @@ -301,6 +304,7 @@ int per_recv_flag, report_all_rtts_flag, name_flag, addr_flag, backoff_flag;
int multif_flag;
int timestamp_flag = 0;
int random_data_flag = 0;
int colour_flag = 0;
#if defined( DEBUG ) || defined( _DEBUG )
int randomly_lose_flag, sent_times_flag, trace_flag, print_per_system_flag;
int lose_factor;
Expand Down Expand Up @@ -377,7 +381,7 @@ int main( int argc, char **argv )

/* get command line options */

while( ( c = getopt( argc, argv, "gedhlmnqusaAvDRz:t:H:i:p:f:r:c:b:C:Q:B:S:I:T:O:" ) ) != EOF )
while( ( c = getopt( argc, argv, "gedhklmnqusaAvDRz:t:H:i:p:f:r:c:b:C:Q:B:S:I:T:O:" ) ) != EOF )
{
switch( c )
{
Expand Down Expand Up @@ -429,6 +433,10 @@ int main( int argc, char **argv )
usage(0);
break;

case 'k':
colour_flag = 1;
break;

case 'q':
verbose_flag = 0;
quiet_flag = 1;
Expand Down Expand Up @@ -1113,11 +1121,17 @@ void finish()

if( verbose_flag || unreachable_flag )
{
if( colour_flag )
printf( ANSI_COLOUR_RED );

printf( "%s", h->host );

if( verbose_flag )
printf( " is unreachable" );

if( colour_flag )
printf( ANSI_COLOUR_RESET );

printf( "\n" );

}/* IF */
Expand Down Expand Up @@ -1622,6 +1636,9 @@ int wait_for_reply(long wait_time)
num_alive++;
if( verbose_flag || alive_flag )
{
if( colour_flag )
printf( ANSI_COLOUR_GREEN );

printf( "%s", h->host );

if( verbose_flag )
Expand All @@ -1636,6 +1653,9 @@ int wait_for_reply(long wait_time)
fprintf( stderr, " [<- %s]", buf);
}

if( colour_flag )
printf( ANSI_COLOUR_RESET );

printf( "\n" );

}/* IF */
Expand Down