Support for the '-a' command line option to auto-start the decryption effect
modified: README.md modified: src/main.c modified: src/nms.c modified: src/nms.h
This commit is contained in:
parent
2eaafe1ef3
commit
ed5e9f689f
11
README.md
11
README.md
@ -62,6 +62,14 @@ Once the "encrypted" data is displayed, the program will pause until you press a
|
|||||||
decryption effect will start. After that is completed, it will again pause until
|
decryption effect will start. After that is completed, it will again pause until
|
||||||
you press a key, at which point the program will terminate.
|
you press a key, at which point the program will terminate.
|
||||||
|
|
||||||
|
#### Command Line Options
|
||||||
|
|
||||||
|
Use the `-a` option to set the auto_decrypt flag. This will automatically start the decryption effect,
|
||||||
|
eliminating the need for the user to press a key to start it.
|
||||||
|
```
|
||||||
|
ls -l / | nms -a
|
||||||
|
```
|
||||||
|
|
||||||
Using the Module in Your Program
|
Using the Module in Your Program
|
||||||
---------------------------------
|
---------------------------------
|
||||||
|
|
||||||
@ -120,6 +128,7 @@ typedef struct {
|
|||||||
int input_cursor_x;
|
int input_cursor_x;
|
||||||
int input_cursor_y;
|
int input_cursor_y;
|
||||||
bool show_cursor;
|
bool show_cursor;
|
||||||
|
bool auto_decrypt;
|
||||||
} NmsArgs;
|
} NmsArgs;
|
||||||
```
|
```
|
||||||
* `char *src`
|
* `char *src`
|
||||||
@ -133,6 +142,8 @@ Useful for displaying menus:
|
|||||||
* If your menu has a specific location that you'd like to place the cursor for user input, use these to set the x and y screen coordinates for the position.
|
* If your menu has a specific location that you'd like to place the cursor for user input, use these to set the x and y screen coordinates for the position.
|
||||||
* `bool show_cursor`
|
* `bool show_cursor`
|
||||||
* 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`
|
||||||
|
* Set to `true` to automatically start the decryption effect, eliminating the need for the user to press a key to start it.
|
||||||
|
|
||||||
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:
|
||||||
|
21
src/main.c
21
src/main.c
@ -1,13 +1,30 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include "nms.h"
|
#include "nms.h"
|
||||||
|
|
||||||
int main(void) {
|
int main(int argc, char *argv[]) {
|
||||||
|
int c, o, inSize = 0;
|
||||||
char *input = NULL;
|
char *input = NULL;
|
||||||
NmsArgs args = INIT_NMSARGS;
|
NmsArgs args = INIT_NMSARGS;
|
||||||
|
|
||||||
|
// Processing command arguments
|
||||||
|
while ((o = getopt(argc, argv, "a")) != -1) {
|
||||||
|
switch (o) {
|
||||||
|
case 'a':
|
||||||
|
args.auto_decrypt = true;
|
||||||
|
break;
|
||||||
|
case '?':
|
||||||
|
if (isprint(optopt))
|
||||||
|
fprintf (stderr, "Unknown option '-%c'.\n", optopt);
|
||||||
|
else
|
||||||
|
fprintf (stderr, "Unknown option character '\\x%x'.\n", optopt);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Geting input
|
// Geting input
|
||||||
int c, inSize = 0;
|
|
||||||
while ((c = getchar()) != EOF) {
|
while ((c = getchar()) != EOF) {
|
||||||
++inSize;
|
++inSize;
|
||||||
input = realloc(input, inSize + 1);
|
input = realloc(input, inSize + 1);
|
||||||
|
@ -153,15 +153,12 @@ char nms_exec(NmsArgs *args) {
|
|||||||
// Flush any input up to this point
|
// Flush any input up to this point
|
||||||
flushinp();
|
flushinp();
|
||||||
|
|
||||||
// Reopen stdin for interactive input (keyboard), then require user
|
// If auto_decrypt flag is set, we sleep. Otherwise, reopen stdin for interactive
|
||||||
// to press a key to continue.
|
// input (keyboard), then require user to press a key to continue.
|
||||||
if (!isatty(STDIN_FILENO))
|
if (args->auto_decrypt == true || (!isatty(STDIN_FILENO) && !freopen ("/dev/tty", "r", stdin)))
|
||||||
if (!freopen ("/dev/tty", "r", stdin))
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
else
|
else
|
||||||
getch();
|
getch();
|
||||||
else
|
|
||||||
getch();
|
|
||||||
|
|
||||||
// Jumble loop
|
// Jumble loop
|
||||||
x = 0;
|
x = 0;
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
// Default arguments for nms_exec()
|
// Default arguments for nms_exec()
|
||||||
#define INIT_NMSARGS { NULL, NULL, -1, -1, false }
|
#define INIT_NMSARGS { NULL, NULL, -1, -1, false, false }
|
||||||
|
|
||||||
// Argument structure for nms_exec()
|
// Argument structure for nms_exec()
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -14,6 +14,7 @@ typedef struct {
|
|||||||
int input_cursor_x;
|
int input_cursor_x;
|
||||||
int input_cursor_y;
|
int input_cursor_y;
|
||||||
bool show_cursor;
|
bool show_cursor;
|
||||||
|
bool auto_decrypt;
|
||||||
} NmsArgs;
|
} NmsArgs;
|
||||||
|
|
||||||
// Display the characters stored in the display queue
|
// Display the characters stored in the display queue
|
||||||
|
Loading…
Reference in New Issue
Block a user