Perform in rust

This commit is contained in:
Greg Shuflin 2023-11-15 19:52:55 -08:00
parent 66429e6714
commit 733693258c
3 changed files with 6 additions and 184 deletions

View File

@ -84,7 +84,7 @@ pub extern "C" fn rust_main() {
exec_effect(input, args.autodecrypt, args.mask_blanks, args.clear_screen); exec_effect(input, args.autodecrypt, args.mask_blanks, args.clear_screen);
} }
fn exec_effect(input: String, autodecrypt: bool, maskblank: bool, clear_screen: bool) { pub(crate) 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};

View File

@ -17,184 +17,5 @@ int main(void) {
rust_sneakers_effect(); rust_sneakers_effect();
int termCols, spaces = 0;
unsigned char *display_uc = NULL;
char *display = NULL;
char *head1Left = "DATANET PROC RECORD: 45-3456-W-3452";
char *head1Right = "Transnet on/xc-3";
char *head2Center = "FEDERAL RESERVE TRANSFER NODE";
char *head3Center = "National Headquarters";
char *head4Center = "************ Remote Systems Network Input Station ************";
char *head5Center = "================================================================";
char *menu1 = "[1] Interbank Funds Transfer (Code Prog: 485-GWU)";
char *menu2 = "[2] International Telelink Access (Code Lim: XRP-262)";
char *menu3 = "[3] Remote Facsimile Send/Receive (Code Tran: 2LZP-517)";
char *menu4 = "[4] Regional Bank Interconnect (Security Code: 47-B34)";
char *menu5 = "[5] Update System Parameters (Entry Auth. Req.)";
char *menu6 = "[6] Remote Operator Logon/Logoff";
char *foot1Center = "================================================================";
char *foot2Center = "[ ] Select Option or ESC to Abort";
// Get terminal dimentions (needed for centering)
struct winsize w;
// if not an interactive tty, w is not populated, resulting in UB
if (ioctl(0, TIOCGWINSZ, &w) == -1) {
perror("Input not from an interactive terminal");
return 1;
}
termCols = w.ws_col;
// Allocate space for our display string
if ((display = malloc(20 * termCols)) == NULL)
{
fprintf(stderr, "Memory Allocation Error. Quitting!\n");
return 1;
}
// Allocate space for our display string
if ((display_uc = malloc(20 * termCols)) == NULL)
{
free(display);
fprintf(stderr, "Memory Allocation Error. Quitting!\n");
return 1;
}
memset(display, 0, 20 * termCols);
memset(display_uc, 0, 20 * termCols);
// Start building the display string
strcpy(display, head1Left);
spaces = termCols - strlen(head1Left) - strlen(head1Right);
while (spaces > 0) {
strcat(display, " ");
--spaces;
}
strcat(display, head1Right);
strcat(display, "\n");
spaces = (termCols - strlen(head2Center)) / 2;
while (spaces > 0) {
strcat(display, " ");
--spaces;
}
strcat(display, head2Center);
strcat(display, "\n");
strcat(display, "\n");
spaces = (termCols - strlen(head3Center)) / 2;
while (spaces > 0) {
strcat(display, " ");
--spaces;
}
strcat(display, head3Center);
strcat(display, "\n");
strcat(display, "\n");
spaces = (termCols - strlen(head4Center)) / 2;
while (spaces > 0) {
strcat(display, " ");
--spaces;
}
strcat(display, head4Center);
strcat(display, "\n");
spaces = (termCols - strlen(head5Center)) / 2;
while (spaces > 0) {
strcat(display, " ");
--spaces;
}
strcat(display, head5Center);
strcat(display, "\n");
strcat(display, "\n");
spaces = ((termCols - strlen(head5Center)) / 2) + 3;
while (spaces > 0) {
strcat(display, " ");
--spaces;
}
strcat(display, menu1);
strcat(display, "\n");
spaces = ((termCols - strlen(head5Center)) / 2) + 3;
while (spaces > 0) {
strcat(display, " ");
--spaces;
}
strcat(display, menu2);
strcat(display, "\n");
spaces = ((termCols - strlen(head5Center)) / 2) + 3;
while (spaces > 0) {
strcat(display, " ");
--spaces;
}
strcat(display, menu3);
strcat(display, "\n");
spaces = ((termCols - strlen(head5Center)) / 2) + 3;
while (spaces > 0) {
strcat(display, " ");
--spaces;
}
strcat(display, menu4);
strcat(display, "\n");
spaces = ((termCols - strlen(head5Center)) / 2) + 3;
while (spaces > 0) {
strcat(display, " ");
--spaces;
}
strcat(display, menu5);
strcat(display, "\n");
spaces = ((termCols - strlen(head5Center)) / 2) + 3;
while (spaces > 0) {
strcat(display, " ");
--spaces;
}
strcat(display, menu6);
strcat(display, "\n");
strcat(display, "\n");
spaces = (termCols - strlen(foot1Center)) / 2;
while (spaces > 0) {
strcat(display, " ");
--spaces;
}
strcat(display, foot1Center);
strcat(display, "\n");
strcat(display, "\n");
spaces = (termCols - strlen(foot2Center)) / 2;
while (spaces > 0) {
strcat(display, " ");
--spaces;
}
strcat(display, foot2Center);
nmseffect_set_clearscr(1);
memcpy(display_uc, display, 20 * termCols);
// Execute effect
nmseffect_exec(display_uc, strlen(display), 0, 0, 1);
free(display);
free(display_uc);
return 0; return 0;
} }

View File

@ -17,7 +17,6 @@ const foot2Center: &str = "[ ] Select Option or ESC to Abort";
#[no_mangle] #[no_mangle]
pub extern "C" fn rust_sneakers_effect() { pub extern "C" fn rust_sneakers_effect() {
println!("Rust sneakers effect");
use std::time::Duration; use std::time::Duration;
let (term_width, _term_height) = crossterm::terminal::size().expect("Error reading terminal size"); let (term_width, _term_height) = crossterm::terminal::size().expect("Error reading terminal size");
@ -61,9 +60,11 @@ pub extern "C" fn rust_sneakers_effect() {
buf.push('\n'); buf.push('\n');
}; };
println!("{}", buf); // println!("{}", buf);
let dur = Duration::from_millis(2000); // let dur = Duration::from_millis(2000);
std::thread::sleep(dur); // std::thread::sleep(dur);
crate::exec_effect(buf, false, false, true);
} }