2023-07-23 03:04:59 -07:00
|
|
|
mod args;
|
2023-07-25 01:44:10 -07:00
|
|
|
mod charset;
|
2023-07-23 19:52:25 -07:00
|
|
|
mod color;
|
2023-07-23 03:03:23 -07:00
|
|
|
|
2023-07-24 00:50:34 -07:00
|
|
|
use libc::{c_char, c_int, c_uchar, c_void};
|
|
|
|
use std::ffi::CString;
|
2023-07-23 20:05:26 -07:00
|
|
|
use std::process;
|
2023-07-23 03:14:38 -07:00
|
|
|
|
2023-07-24 00:50:34 -07:00
|
|
|
use color::Color;
|
|
|
|
|
2023-07-23 19:52:25 -07:00
|
|
|
const VERSION: &str = "2.0.0";
|
2023-07-23 03:19:40 -07:00
|
|
|
|
2023-07-23 03:14:49 -07:00
|
|
|
extern "C" {
|
2023-07-23 03:19:40 -07:00
|
|
|
fn nmseffect_set_clearscr(_: c_int) -> c_void;
|
2023-07-24 00:50:34 -07:00
|
|
|
fn nmseffect_exec(input: *const c_char, len: c_int) -> c_char;
|
2023-07-23 19:35:15 -07:00
|
|
|
static mut foregroundColor: c_int;
|
2023-07-23 20:13:44 -07:00
|
|
|
static mut maskBlank: c_int;
|
2023-07-23 20:18:44 -07:00
|
|
|
static mut autoDecrypt: c_int;
|
2023-07-23 03:14:38 -07:00
|
|
|
}
|
|
|
|
|
2023-07-23 03:03:23 -07:00
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn rust_main() {
|
|
|
|
println!("Hello from rust");
|
2023-07-23 03:14:38 -07:00
|
|
|
|
2023-07-23 20:05:26 -07:00
|
|
|
let args = match args::parse_arguments() {
|
|
|
|
Ok(args) => args,
|
|
|
|
Err(e) => {
|
|
|
|
println!("{e}");
|
|
|
|
process::exit(1);
|
|
|
|
}
|
|
|
|
};
|
2023-07-23 19:52:25 -07:00
|
|
|
println!("{:?}", args);
|
2023-07-23 03:14:38 -07:00
|
|
|
|
2023-07-23 03:19:40 -07:00
|
|
|
if args.version {
|
|
|
|
println!("nms version {VERSION}");
|
2023-07-23 20:05:26 -07:00
|
|
|
process::exit(0);
|
2023-07-23 03:19:40 -07:00
|
|
|
}
|
|
|
|
|
2023-07-23 19:52:25 -07:00
|
|
|
if let Some(color) = args.foreground {
|
|
|
|
let color = Color::try_from(color).unwrap_or_default();
|
|
|
|
let n = color as c_int;
|
2023-07-23 19:35:15 -07:00
|
|
|
unsafe {
|
2023-07-23 19:52:25 -07:00
|
|
|
foregroundColor = n;
|
2023-07-23 19:35:15 -07:00
|
|
|
}
|
|
|
|
}
|
2023-07-23 20:13:44 -07:00
|
|
|
unsafe {
|
|
|
|
if args.mask_blanks {
|
|
|
|
maskBlank = 1;
|
|
|
|
} else {
|
|
|
|
maskBlank = 0;
|
|
|
|
}
|
|
|
|
}
|
2023-07-23 19:35:15 -07:00
|
|
|
|
2023-07-23 03:19:40 -07:00
|
|
|
if args.clear_screen {
|
|
|
|
unsafe {
|
|
|
|
nmseffect_set_clearscr(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-23 20:18:44 -07:00
|
|
|
unsafe {
|
|
|
|
if args.autodecrypt {
|
|
|
|
autoDecrypt = 1;
|
|
|
|
} else {
|
|
|
|
autoDecrypt = 0;
|
2023-07-23 03:14:38 -07:00
|
|
|
}
|
|
|
|
}
|
2023-07-24 00:50:34 -07:00
|
|
|
|
|
|
|
let output = get_input("Enter input: ");
|
|
|
|
if output.len() == 0 {
|
|
|
|
eprintln!("Input is empty"); //TODO use error_log()/error_print() abstraction
|
|
|
|
process::exit(1);
|
|
|
|
}
|
|
|
|
let output_cstring = CString::new(output).unwrap();
|
|
|
|
let ptr = output_cstring.as_ptr();
|
|
|
|
let len = output_cstring.as_bytes().len();
|
|
|
|
let _r = unsafe { nmseffect_exec(ptr, len as i32) };
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_input(prompt: &str) -> String {
|
|
|
|
use std::io::{Read, Write};
|
|
|
|
|
|
|
|
let mut stdin = std::io::stdin();
|
|
|
|
let mut stdout = std::io::stdout();
|
|
|
|
let mut buf = String::new();
|
|
|
|
|
|
|
|
if atty::is(atty::Stream::Stdin) {
|
|
|
|
print!("{prompt}");
|
|
|
|
stdout.flush().unwrap();
|
|
|
|
stdin.read_line(&mut buf).unwrap();
|
|
|
|
} else {
|
|
|
|
stdin.read_to_string(&mut buf).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
buf
|
2023-07-23 03:03:23 -07:00
|
|
|
}
|