Skip to content
This repository has been archived by the owner on Jun 16, 2023. It is now read-only.

Commit

Permalink
Added support for NO_COLOR as per: https://no-color.org/
Browse files Browse the repository at this point in the history
Updated version to 0.9.1
  • Loading branch information
wiremoons committed Jun 12, 2021
1 parent 977f9dd commit 02c593d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ For Windows '`cmd.exe`' use: `set "OPASS_WORDS=7" & set "OPASS_NUM=8" & opass`

For Windows '`Powershell`' use: `$env:OPASS_WORDS=7 ; $env:OPASS_NUM=8 ; ./opass`

Output will use ANSI colour by default. The '**NO_COLOR**' environment is respected and colour
output is disabled if it is set.
This can also be specified on the command line by running commands as shown below:

For Windows '`cmd.exe`' use: `set "NO_COLOR=1" & opass`
For Windows '`Powershell`' use: `$env:NO_COLOR=1 ; ./opass`
For macOS, Linux, '`Unix shells`' use: `NO_COLOR=1 opass`

See: https://no-color.org/ web site for more information about `NO_COLOR` support in
applications.

## Application Screen Outputs

Below are examples of the outputs display when the program is run.
Expand Down
2 changes: 1 addition & 1 deletion src/opass.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#define MAX_PASSWORDS 5
#define MAX_WORDS 3
#define VERSION "0.9.0";
#define VERSION "0.9.1";


char *get_random_password_str(int wordsRequired, int wordArraySize);
Expand Down
27 changes: 23 additions & 4 deletions src/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

#include "output.h"

#include <stdio.h> /* printf */
#include <ctype.h>
#include <stdio.h> /* printf */
#include <stdlib.h> /* getenv */
#include <ctype.h> /* toupper */
#include <string.h>

/*
Expand All @@ -20,13 +21,25 @@
*/
void show_password(char *out_password) {
if ((strlen(out_password) <= 0) || (NULL == out_password)) {
printf("\nERROR\n");
fprintf(stderr,"\nERROR: password to be displayed is zero length or NULL\n");
return;
}
#if DEBUG
printf("\nProcessing: '%s' which has length: '%d'\n",out_password,(int) strlen(out_password));
#endif

/* respect the NO_COLOR setting as: https://no-color.org/ */
if ( getenv("NO_COLOR") ) {
#if DEBUG
printf("\n'NO_COLOR' environment setting found.\n");
#endif
printf("%s",out_password);
#if DEBUG
printf("\nDONE PROCESSING as NO_COLOR ['%d' chars]\n",(int)strlen(out_password));
#endif
return;
}

int test_len = 0;

//char RED[]="\033[1;31m";
Expand Down Expand Up @@ -78,7 +91,13 @@ void show_help() {
"Usage ensures a minimum of seven random three letter words are included and eight different\n"
"password choices will be offered to the user to select from.\n\n"
"For Windows 'cmd.exe' use: set \"OPASS_WORDS=7\" & set \"OPASS_NUM=8\" & opass\n"
"For Windows 'Powershell' use: $env:OPASS_WORDS=7 ; $env:OPASS_NUM=8 ; ./opass\n\n\n"
"For Windows 'Powershell' use: $env:OPASS_WORDS=7 ; $env:OPASS_NUM=8 ; ./opass\n\n"
"Output will use ANSI colour by default. The 'NO_COLOR' environment is respected and colour\n"
"output is disabled if it is set. See: https://no-color.org/\n"
"This can also be specified on the command line by running commands as shown below:\n\n"
"For Windows 'cmd.exe' use: set \"NO_COLOR=1\" & opass\n"
"For Windows 'Powershell' use: $env:NO_COLOR=1 ; ./opass\n"
"For macOS, Linux, 'Unix shells' use: NO_COLOR=1 opass\n\n\n"
"Help Summary: the following command line switches can be used:\n\n"
" -e, --export Dump the full list of three letter words and marks.\n"
" -h, --help Show this help information.\n"
Expand Down

0 comments on commit 02c593d

Please sign in to comment.