diff --git a/README.md b/README.md index 754a00c..15b2b99 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ enjoy the magic. In the below examples, I use a simple directory listing. ``` ls -l | nms ls -l | nms -a // Set auto-decrypt flag +ls -l | nms -s // Set mask blanks flag ls -l | nms -f green // Set foreground color to green ls -l | nms -c // Clear screen nms -v // Display version diff --git a/nms.6 b/nms.6 index 2d41775..10a6676 100644 --- a/nms.6 +++ b/nms.6 @@ -11,6 +11,9 @@ nms [options] .B -a sets the auto-decrypt flag, decryption sequence starts without requiring a key press. .TP +.B -s +sets the mask blanks flag. Blank spaces will be encrypted and decrypted. +.TP .B -c clear the screen prior to printing any output .TP diff --git a/src/nms.c b/src/nms.c index df9dd74..c63cd44 100644 --- a/src/nms.c +++ b/src/nms.c @@ -19,7 +19,7 @@ int main(int argc, char *argv[]) { char *input = NULL; // Processing command arguments - while ((o = getopt(argc, argv, "f:acv")) != -1) { + while ((o = getopt(argc, argv, "f:ascv")) != -1) { switch (o) { case 'f': nmseffect_set_foregroundcolor(optarg); @@ -27,6 +27,9 @@ int main(int argc, char *argv[]) { case 'a': nmseffect_set_autodecrypt(1); break; + case 's': + nmseffect_set_maskblank(1); + break; case 'c': nmseffect_set_clearscr(1); break; diff --git a/src/nmseffect.c b/src/nmseffect.c index 1b802e5..195d5f1 100644 --- a/src/nmseffect.c +++ b/src/nmseffect.c @@ -34,6 +34,7 @@ // Behavior settings static char *returnOpts = NULL; // Return option setting static int autoDecrypt = 0; // Auto-decrypt flag +static int maskBlank = 0; // Mask blank spaces static int colorOn = 1; // Terminal color flag static int inputPositionX = -1; // X coordinate for input position static int inputPositionY = -1; // Y coordinate for input position @@ -136,10 +137,15 @@ char nmseffect_exec(char *string) { } // Set flag if we have a whitespace character - if (strlen(list_pointer->source) == 1 && isspace(list_pointer->source[0])) - list_pointer->is_space = 1; - else + if (strlen(list_pointer->source) == 1 && isspace(list_pointer->source[0])) { + // If flag is enabled, mask blank spaces as well + if (maskBlank && (list_pointer->source[0] == ' ')) + list_pointer->is_space = 0; + else + list_pointer->is_space = 1; + } else { list_pointer->is_space = 0; + } // Set initial mask chharacter list_pointer->mask = nmscharset_get_random(); @@ -349,6 +355,18 @@ void nmseffect_set_autodecrypt(int setting) { autoDecrypt = 0; } +/* + * Set the maskBlank flag according to the true/false value of the + * 'setting' argument. When set to true, blank spaces characters + * will be masked as well. + */ +void nmseffect_set_maskblank(int setting) { + if (setting) + maskBlank = 1; + else + maskBlank = 0; +} + /* * Pass the 'setting' argument to the nmstermio module where it will set * the clearScr flag according to the true/false value. When set to true, diff --git a/src/nmseffect.h b/src/nmseffect.h index 152e2ba..5c04c3d 100644 --- a/src/nmseffect.h +++ b/src/nmseffect.h @@ -13,6 +13,7 @@ char nmseffect_exec(char *); void nmseffect_set_foregroundcolor(char *); void nmseffect_set_returnopts(char *); void nmseffect_set_autodecrypt(int); +void nmseffect_set_maskblank(int); void nmseffect_set_clearscr(int); void nmseffect_use_color(int); void nmseffect_set_input_position(int, int);