Merge branch 'feature/colour' of https://github.com/anthonysterling/no-more-secrets into anthonysterling-feature/colour

This commit is contained in:
Brian Barto 2016-05-03 09:44:41 -04:00
commit eef49d2ce6
4 changed files with 58 additions and 3 deletions

View File

@ -70,6 +70,11 @@ eliminating the need for the user to press a key to start it.
ls -l / | nms -a ls -l / | nms -a
``` ```
Use the `-f` option to set foreground color to either white, yellow, black, magenta, blue, green, or red - this is blue by default.
```
ls -l / | nms -f green
```
Using the Module in Your Program Using the Module in Your Program
--------------------------------- ---------------------------------
@ -129,6 +134,7 @@ typedef struct {
int input_cursor_y; int input_cursor_y;
bool show_cursor; bool show_cursor;
bool auto_decrypt; bool auto_decrypt;
int foreground_color;
} NmsArgs; } NmsArgs;
``` ```
* `char *src` * `char *src`
@ -144,6 +150,8 @@ Useful for displaying menus:
* Set to `true` if you want the cursor to be visible during the text decryption effect. It is set to `false` by default. * Set to `true` if you want the cursor to be visible during the text decryption effect. It is set to `false` by default.
* `bool auto_decrypt` * `bool auto_decrypt`
* Set to `true` to automatically start the decryption effect, eliminating the need for the user to press a key to start it. * Set to `true` to automatically start the decryption effect, eliminating the need for the user to press a key to start it.
* `int foreground_color`
* Use this to assign a default (ncurses) color to the foreground
Assign values to the structure members as needed. Then simply pass a pointer to the structure to the Assign values to the structure members as needed. Then simply pass a pointer to the structure to the
nms_exec() function: nms_exec() function:

View File

@ -13,8 +13,11 @@ int main(int argc, char *argv[]) {
NmsArgs args = INIT_NMSARGS; NmsArgs args = INIT_NMSARGS;
// Processing command arguments // Processing command arguments
while ((o = getopt(argc, argv, "av")) != -1) { while ((o = getopt(argc, argv, "f:av")) != -1) {
switch (o) { switch (o) {
case 'f':
args.foreground_color = getColorByName(optarg, args.foreground_color);
break;
case 'a': case 'a':
args.auto_decrypt = true; args.auto_decrypt = true;
break; break;

View File

@ -86,7 +86,7 @@ char nms_exec(NmsArgs *args) {
// Setting up and starting colors if terminal supports them // Setting up and starting colors if terminal supports them
if (has_colors()) { if (has_colors()) {
start_color(); start_color();
init_pair(1, COLOR_BLUE, COLOR_BLACK); init_pair(1, args->foreground_color, COLOR_BLACK);
} }
// Get terminal window size // Get terminal window size
@ -284,3 +284,43 @@ char getMaskChar(void) {
return maskChars[rand() % strlen(maskChars)]; return maskChars[rand() % strlen(maskChars)];
} }
/*
* char getColorByName(char *string, int fallback)
*
* DESCR:
* Returns an ncurses color by its name.
*
*/
int getColorByName(char *string, int fallback) {
if(strcmp("white", string) == 0) {
return COLOR_WHITE;
}
if(strcmp("yellow", string) == 0) {
return COLOR_YELLOW;
}
if(strcmp("black", string) == 0) {
return COLOR_BLACK;
}
if(strcmp("magenta", string) == 0) {
return COLOR_MAGENTA;
}
if(strcmp("blue", string) == 0) {
return COLOR_BLUE;
}
if(strcmp("green", string) == 0) {
return COLOR_GREEN;
}
if(strcmp("red", string) == 0) {
return COLOR_RED;
}
return fallback;
}

View File

@ -3,9 +3,10 @@
#include <stddef.h> #include <stddef.h>
#include <stdbool.h> #include <stdbool.h>
#include <ncurses.h>
// Default arguments for nms_exec() // Default arguments for nms_exec()
#define INIT_NMSARGS { NULL, NULL, -1, -1, false, false } #define INIT_NMSARGS { NULL, NULL, -1, -1, false, false , COLOR_BLUE }
// Argument structure for nms_exec() // Argument structure for nms_exec()
typedef struct { typedef struct {
@ -15,9 +16,12 @@ typedef struct {
int input_cursor_y; int input_cursor_y;
bool show_cursor; bool show_cursor;
bool auto_decrypt; bool auto_decrypt;
int foreground_color;
} NmsArgs; } NmsArgs;
// Display the characters stored in the display queue // Display the characters stored in the display queue
char nms_exec(NmsArgs *); char nms_exec(NmsArgs *);
int getColorByName(char *string, int fallback);
#endif #endif