From 297c1aedb901be3b902595fe7582ba9fbdf893ca Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sun, 12 Nov 2023 11:20:13 -0800 Subject: [PATCH] Messing with clear screen --- src/lib.rs | 12 +++++++----- src/nmseffect.c | 6 +++--- src/nmseffect.h | 2 +- src/nmstermio.c | 8 -------- src/nmstermio.h | 1 - src/nmstermio_ncurses.c | 7 ------- 6 files changed, 11 insertions(+), 25 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ffff8da..4c03658 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,12 +11,13 @@ use color::Color; const VERSION: &str = "2.0.0"; extern "C" { - fn nmseffect_set_clearscr(_: c_int) -> c_void; + fn nmstermio_set_clearscr(_: c_int); fn nmseffect_exec( input: *const c_char, len: c_int, autodecrypt_c: c_int, maskblank_c: c_int, + clear_scr: c_int, ) -> c_char; static mut foregroundColor: c_int; } @@ -68,7 +69,7 @@ pub extern "C" fn rust_main() { if args.clear_screen { unsafe { - nmseffect_set_clearscr(1); + nmstermio_set_clearscr(2); } } @@ -79,10 +80,10 @@ pub extern "C" fn rust_main() { 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 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 ptr = output_cstring.as_ptr(); 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) }; } diff --git a/src/nmseffect.c b/src/nmseffect.c index 405c604..60c3baf 100644 --- a/src/nmseffect.c +++ b/src/nmseffect.c @@ -53,7 +53,7 @@ extern void nmseffect_sleep(int); * string that is provided as an argument. It returns the last character * 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_head = NULL; struct charAttr *list_temp = NULL; @@ -70,7 +70,7 @@ char nmseffect_exec(unsigned char *string, int string_len, int autoDecrypt, int // Initialize terminal nmstermio_init_terminal(); - if (!nmstermio_get_clearscr()) { + if (!clear_screen) { // Get current row position origRow = nmstermio_get_cursor_row(); @@ -269,7 +269,7 @@ char nmseffect_exec(unsigned char *string, int string_len, int autoDecrypt, int nmstermio_clear_input(); - if (nmstermio_get_clearscr()) { + if (clear_screen) { nmstermio_get_char(); } diff --git a/src/nmseffect.h b/src/nmseffect.h index 6d520b7..ece7aab 100644 --- a/src/nmseffect.h +++ b/src/nmseffect.h @@ -9,7 +9,7 @@ #define NMSEFFECT_H 1 // 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_clearscr(int); void nmseffect_use_color(int); diff --git a/src/nmstermio.c b/src/nmstermio.c index bcce7ee..fde7fc1 100644 --- a/src/nmstermio.c +++ b/src/nmstermio.c @@ -206,14 +206,6 @@ void nmstermio_beep(void) { 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. */ diff --git a/src/nmstermio.h b/src/nmstermio.h index 7b4dd97..9b07437 100644 --- a/src/nmstermio.h +++ b/src/nmstermio.h @@ -22,7 +22,6 @@ char nmstermio_get_char(void); void nmstermio_print_reveal_string(char *, int); void nmstermio_show_cursor(void); void nmstermio_beep(void); -int nmstermio_get_clearscr(void); void nmstermio_set_clearscr(int); int nmstermio_get_cursor_row(void); diff --git a/src/nmstermio_ncurses.c b/src/nmstermio_ncurses.c index 3bea8e7..5eb560e 100644 --- a/src/nmstermio_ncurses.c +++ b/src/nmstermio_ncurses.c @@ -140,13 +140,6 @@ void nmstermio_beep(void) { 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.