Messing with clear screen

This commit is contained in:
Greg Shuflin 2023-11-12 11:20:13 -08:00
parent ea5efdcf69
commit 297c1aedb9
6 changed files with 11 additions and 25 deletions

View File

@ -11,12 +11,13 @@ use color::Color;
const VERSION: &str = "2.0.0"; const VERSION: &str = "2.0.0";
extern "C" { extern "C" {
fn nmseffect_set_clearscr(_: c_int) -> c_void; fn nmstermio_set_clearscr(_: c_int);
fn nmseffect_exec( fn nmseffect_exec(
input: *const c_char, input: *const c_char,
len: c_int, len: c_int,
autodecrypt_c: c_int, autodecrypt_c: c_int,
maskblank_c: c_int, maskblank_c: c_int,
clear_scr: c_int,
) -> c_char; ) -> c_char;
static mut foregroundColor: c_int; static mut foregroundColor: c_int;
} }
@ -68,7 +69,7 @@ pub extern "C" fn rust_main() {
if args.clear_screen { if args.clear_screen {
unsafe { unsafe {
nmseffect_set_clearscr(1); nmstermio_set_clearscr(2);
} }
} }
@ -79,10 +80,10 @@ pub extern "C" fn rust_main() {
process::exit(1); process::exit(1);
} }
exec_effect(input, args.autodecrypt, args.mask_blanks); exec_effect(input, args.autodecrypt, args.mask_blanks, args.clear_screen);
} }
fn exec_effect(input: String, autodecrypt: bool, maskblank: bool) { fn exec_effect(input: String, autodecrypt: bool, maskblank: bool, clear_screen: bool) {
let maskblank_c = if maskblank { 1 } else { 0 }; let maskblank_c = if maskblank { 1 } else { 0 };
let autodecrypt_c = if autodecrypt { 1 } else { 0}; let autodecrypt_c = if autodecrypt { 1 } else { 0};
@ -90,7 +91,8 @@ fn exec_effect(input: String, autodecrypt: bool, maskblank: bool) {
let output_cstring = CString::new(input).unwrap(); let output_cstring = CString::new(input).unwrap();
let ptr = output_cstring.as_ptr(); let ptr = output_cstring.as_ptr();
let len = output_cstring.as_bytes().len(); let len = output_cstring.as_bytes().len();
let _r = unsafe { nmseffect_exec(ptr, len as i32, autodecrypt_c, maskblank_c) }; let clear = if clear_screen { 1 } else { 0 };
let _r = unsafe { nmseffect_exec(ptr, len as i32, autodecrypt_c, maskblank_c, clear) };
} }

View File

@ -53,7 +53,7 @@ extern void nmseffect_sleep(int);
* string that is provided as an argument. It returns the last character * string that is provided as an argument. It returns the last character
* pressed by the user. * pressed by the user.
*/ */
char nmseffect_exec(unsigned char *string, int string_len, int autoDecrypt, int maskBlank) { char nmseffect_exec(unsigned char *string, int string_len, int autoDecrypt, int maskBlank, int clear_screen) {
struct charAttr *list_pointer = NULL; struct charAttr *list_pointer = NULL;
struct charAttr *list_head = NULL; struct charAttr *list_head = NULL;
struct charAttr *list_temp = NULL; struct charAttr *list_temp = NULL;
@ -70,7 +70,7 @@ char nmseffect_exec(unsigned char *string, int string_len, int autoDecrypt, int
// Initialize terminal // Initialize terminal
nmstermio_init_terminal(); nmstermio_init_terminal();
if (!nmstermio_get_clearscr()) { if (!clear_screen) {
// Get current row position // Get current row position
origRow = nmstermio_get_cursor_row(); origRow = nmstermio_get_cursor_row();
@ -269,7 +269,7 @@ char nmseffect_exec(unsigned char *string, int string_len, int autoDecrypt, int
nmstermio_clear_input(); nmstermio_clear_input();
if (nmstermio_get_clearscr()) { if (clear_screen) {
nmstermio_get_char(); nmstermio_get_char();
} }

View File

@ -9,7 +9,7 @@
#define NMSEFFECT_H 1 #define NMSEFFECT_H 1
// Function prototypes // Function prototypes
char nmseffect_exec(unsigned char *, int string_len, int autoDecrypt, int maskblank); char nmseffect_exec(unsigned char *, int string_len, int autoDecrypt, int maskblank, int clear_screen);
void nmseffect_set_returnopts(char *); void nmseffect_set_returnopts(char *);
void nmseffect_set_clearscr(int); void nmseffect_set_clearscr(int);
void nmseffect_use_color(int); void nmseffect_use_color(int);

View File

@ -206,14 +206,6 @@ void nmstermio_beep(void) {
BEEP(); BEEP();
} }
/*
* Return the status of the clearScr flag. This is used by the nmseffect
* module to make certain decisions based on its value.
*/
int nmstermio_get_clearscr(void) {
return clearScr;
}
/* /*
* Sets the clearScr flag according to the true/false value of the 's' argument. * Sets the clearScr flag according to the true/false value of the 's' argument.
*/ */

View File

@ -22,7 +22,6 @@ char nmstermio_get_char(void);
void nmstermio_print_reveal_string(char *, int); void nmstermio_print_reveal_string(char *, int);
void nmstermio_show_cursor(void); void nmstermio_show_cursor(void);
void nmstermio_beep(void); void nmstermio_beep(void);
int nmstermio_get_clearscr(void);
void nmstermio_set_clearscr(int); void nmstermio_set_clearscr(int);
int nmstermio_get_cursor_row(void); int nmstermio_get_cursor_row(void);

View File

@ -140,13 +140,6 @@ void nmstermio_beep(void) {
beep(); beep();
} }
/*
* Return the status of the clearScr flag. This is used by the nmseffect
* module to make certain decisions based on its value.
*/
int nmstermio_get_clearscr(void) {
return clearScr;
}
/* /*
* Sets the clearScr flag according to the true/false value of the 's' argument. * Sets the clearScr flag according to the true/false value of the 's' argument.