[Initng-svn] r3846 - initng/trunk/plugins/ngc4
svn at initng.thinktux.net
svn at initng.thinktux.net
Wed Apr 19 23:06:57 CEST 2006
Author: jimmy
Date: Wed Apr 19 23:06:56 2006
New Revision: 3846
Modified:
initng/trunk/plugins/ngc4/ngc4.c
Log:
ngc only print colors on a tty.
Modified: initng/trunk/plugins/ngc4/ngc4.c
==============================================================================
--- initng/trunk/plugins/ngc4/ngc4.c (original)
+++ initng/trunk/plugins/ngc4/ngc4.c Wed Apr 19 23:06:56 2006
@@ -60,6 +60,7 @@
int header_printed = FALSE;
int quiet = FALSE;
+int ansi = FALSE;
#define print_out(...); { if(quiet==FALSE) printf(__VA_ARGS__ ); }
@@ -223,13 +224,16 @@
/* TODO, put initng version from rep here */
if (header_printed == FALSE && quiet == FALSE)
{
- /* print banner */
+ /* print banner - only on terminal */
+ if(ansi)
+ {
print_out(C_FG_LIGHT_BLUE " Next Generation init Control. version ( "
C_FG_MAGENTA "%s"
C_FG_LIGHT_BLUE " )" C_OFF
C_FG_LIGHT_RED "\n (c) Jimmy Wennlund, " C_OFF
C_FG_NEON_GREEN "http://www.initng.org/" C_OFF "\n",
VERSION);
+ }
header_printed = TRUE;
}
@@ -251,7 +255,7 @@
/* only print when not quiet */
if (quiet == FALSE)
{
- string = ngcclient_reply_to_string(rep, TRUE);
+ string = ngcclient_reply_to_string(rep, ansi);
print_out("\n\n%s\n", string);
if (string)
free(string);
@@ -278,7 +282,11 @@
*/
header_printed = FALSE;
-
+ /*
+ * If output to a terminal, turn on ansi colors.
+ */
+ if(isatty(1))
+ ansi=TRUE;
/*
@@ -322,13 +330,15 @@
/* check if cmd-line contains "ngdc", if set debug */
if (strncasecmp(Argv, "ngd", 3) == 0)
{
- print_out(C_FG_YELLOW "Warning. This is ngdc!" C_OFF "\n");
+ if(ansi)
+ print_out(C_FG_YELLOW "Warning. This is ngdc!" C_OFF "\n");
debug = TRUE;
}
if (debug == FALSE && getuid() != 0)
{
+ if(ansi)
print_out(C_ERROR "You need root access to communicate with initng."
C_OFF "\n");
exit(2);
More information about the Initng-svn
mailing list