Compare commits
4 Commits
c77fb9818f
...
4f74c2f8cd
Author | SHA1 | Date | |
---|---|---|---|
|
4f74c2f8cd | ||
|
a1e8fb7aec | ||
|
b6acbc2484 | ||
|
c5bdc65923 |
13
justfile
13
justfile
@ -2,6 +2,19 @@ default:
|
|||||||
just --list
|
just --list
|
||||||
|
|
||||||
|
|
||||||
|
# Build from scratch
|
||||||
build:
|
build:
|
||||||
cargo build --release
|
cargo build --release
|
||||||
make nms
|
make nms
|
||||||
|
|
||||||
|
|
||||||
|
# Clean all project files
|
||||||
|
clean:
|
||||||
|
rm -rf obj
|
||||||
|
rm -rf bin
|
||||||
|
cargo clean
|
||||||
|
|
||||||
|
|
||||||
|
# A sample run of the program
|
||||||
|
sample_run *args:
|
||||||
|
cat Cargo.toml | ./bin/nms {{args}}
|
||||||
|
@ -6,6 +6,11 @@ use lexopt::prelude::*;
|
|||||||
pub(crate) struct Args {
|
pub(crate) struct Args {
|
||||||
pub(crate) version: bool,
|
pub(crate) version: bool,
|
||||||
pub(crate) clear_screen: bool,
|
pub(crate) clear_screen: bool,
|
||||||
|
|
||||||
|
///Pass the 'color' argument to the nmstermio module where it will set the
|
||||||
|
///foreground color of the unencrypted characters as they are
|
||||||
|
///revealed. Valid arguments are "white", "yellow", "magenta", "blue",
|
||||||
|
///"green", "red", and "cyan".
|
||||||
pub(crate) foreground: Option<OsString>,
|
pub(crate) foreground: Option<OsString>,
|
||||||
pub(crate) autodecrypt: bool,
|
pub(crate) autodecrypt: bool,
|
||||||
pub(crate) mask_blanks: bool,
|
pub(crate) mask_blanks: bool,
|
||||||
|
40
src/color.rs
Normal file
40
src/color.rs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
use std::{convert::TryFrom, ffi::OsString};
|
||||||
|
|
||||||
|
pub(crate) enum Color {
|
||||||
|
Black = 0,
|
||||||
|
Red = 1,
|
||||||
|
Green = 2,
|
||||||
|
Yellow = 3,
|
||||||
|
Blue = 4,
|
||||||
|
Magenta = 5,
|
||||||
|
Cyan = 6,
|
||||||
|
White = 7,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Color {
|
||||||
|
fn default() -> Self {
|
||||||
|
Color::Blue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<OsString> for Color {
|
||||||
|
type Error = ();
|
||||||
|
|
||||||
|
fn try_from(s: OsString) -> Result<Self, ()> {
|
||||||
|
let s = match s.to_str() {
|
||||||
|
Some(s) => s,
|
||||||
|
None => return Err(()),
|
||||||
|
};
|
||||||
|
Ok(match s {
|
||||||
|
"black" => Color::Black,
|
||||||
|
"red" => Color::Red,
|
||||||
|
"green" => Color::Green,
|
||||||
|
"yellow" => Color::Yellow,
|
||||||
|
"blue" => Color::Blue,
|
||||||
|
"magenta" => Color::Magenta,
|
||||||
|
"cyan" => Color::Cyan,
|
||||||
|
"white" => Color::White,
|
||||||
|
_ => return Err(()),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
15
src/lib.rs
15
src/lib.rs
@ -1,12 +1,15 @@
|
|||||||
mod args;
|
mod args;
|
||||||
|
mod color;
|
||||||
|
|
||||||
|
use color::Color;
|
||||||
use libc::{c_int, c_void};
|
use libc::{c_int, c_void};
|
||||||
|
|
||||||
const VERSION: &str = "2.0.0";
|
const VERSION: &str = "2.0.0";
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
fn nmseffect_set_autodecrypt(_: c_int) -> c_void;
|
fn nmseffect_set_autodecrypt(_: c_int) -> c_void;
|
||||||
fn nmseffect_set_clearscr(_: c_int) -> c_void;
|
fn nmseffect_set_clearscr(_: c_int) -> c_void;
|
||||||
|
static mut foregroundColor: c_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
@ -14,12 +17,21 @@ pub extern "C" fn rust_main() {
|
|||||||
println!("Hello from rust");
|
println!("Hello from rust");
|
||||||
|
|
||||||
let args = args::parse_arguments().unwrap();
|
let args = args::parse_arguments().unwrap();
|
||||||
|
println!("{:?}", args);
|
||||||
|
|
||||||
if args.version {
|
if args.version {
|
||||||
println!("nms version {VERSION}");
|
println!("nms version {VERSION}");
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(color) = args.foreground {
|
||||||
|
let color = Color::try_from(color).unwrap_or_default();
|
||||||
|
let n = color as c_int;
|
||||||
|
unsafe {
|
||||||
|
foregroundColor = n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if args.clear_screen {
|
if args.clear_screen {
|
||||||
unsafe {
|
unsafe {
|
||||||
nmseffect_set_clearscr(1);
|
nmseffect_set_clearscr(1);
|
||||||
@ -31,5 +43,4 @@ pub extern "C" fn rust_main() {
|
|||||||
nmseffect_set_autodecrypt(1);
|
nmseffect_set_autodecrypt(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!("{:?}", args);
|
|
||||||
}
|
}
|
||||||
|
@ -29,9 +29,6 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
switch (o)
|
switch (o)
|
||||||
{
|
{
|
||||||
case 'f':
|
|
||||||
nmseffect_set_foregroundcolor(optarg);
|
|
||||||
break;
|
|
||||||
case 's':
|
case 's':
|
||||||
nmseffect_set_maskblank(1);
|
nmseffect_set_maskblank(1);
|
||||||
break;
|
break;
|
||||||
|
@ -290,16 +290,6 @@ char nmseffect_exec(unsigned char *string, int string_len) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Pass the 'color' argument to the nmstermio module where it will set the
|
|
||||||
* foreground color of the unencrypted characters as they are
|
|
||||||
* revealed. Valid arguments are "white", "yellow", "magenta", "blue",
|
|
||||||
* "green", "red", and "cyan".
|
|
||||||
*/
|
|
||||||
void nmseffect_set_foregroundcolor(char *color) {
|
|
||||||
nmstermio_set_foregroundcolor(color);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set the autoDecrypt flag according to the true/false value of the
|
* Set the autoDecrypt flag according to the true/false value of the
|
||||||
* 'setting' argument. When set to true, nmseffect_exec() will not
|
* 'setting' argument. When set to true, nmseffect_exec() will not
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
// Function prototypes
|
// Function prototypes
|
||||||
char nmseffect_exec(unsigned char *, int string_len);
|
char nmseffect_exec(unsigned char *, int string_len);
|
||||||
void nmseffect_set_foregroundcolor(char *);
|
|
||||||
void nmseffect_set_returnopts(char *);
|
void nmseffect_set_returnopts(char *);
|
||||||
void nmseffect_set_autodecrypt(int);
|
void nmseffect_set_autodecrypt(int);
|
||||||
void nmseffect_set_maskblank(int);
|
void nmseffect_set_maskblank(int);
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
|
|
||||||
// Terminal IO settings
|
// Terminal IO settings
|
||||||
static int clearScr = 0; // clearScr flag
|
static int clearScr = 0; // clearScr flag
|
||||||
static int foregroundColor = COLOR_BLUE; // Foreground color setting
|
int foregroundColor = COLOR_BLUE; // Foreground color setting
|
||||||
|
|
||||||
// Function prototypes
|
// Function prototypes
|
||||||
static void nmstermio_set_terminal(int);
|
static void nmstermio_set_terminal(int);
|
||||||
@ -224,33 +224,6 @@ void nmstermio_set_clearscr(int s) {
|
|||||||
clearScr = 0;
|
clearScr = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Set the desired foreground color of the unencrypted characters as they
|
|
||||||
* are revealed by nmstermio_print_reveal_string(). Valid arguments are
|
|
||||||
* "white", "yellow", "magenta", "blue", "green", "red", and "cyan".
|
|
||||||
*/
|
|
||||||
void nmstermio_set_foregroundcolor(char *c) {
|
|
||||||
|
|
||||||
if(strcmp("white", c) == 0)
|
|
||||||
foregroundColor = COLOR_WHITE;
|
|
||||||
else if(strcmp("yellow", c) == 0)
|
|
||||||
foregroundColor = COLOR_YELLOW;
|
|
||||||
else if(strcmp("black", c) == 0)
|
|
||||||
foregroundColor = COLOR_BLACK;
|
|
||||||
else if(strcmp("magenta", c) == 0)
|
|
||||||
foregroundColor = COLOR_MAGENTA;
|
|
||||||
else if(strcmp("blue", c) == 0)
|
|
||||||
foregroundColor = COLOR_BLUE;
|
|
||||||
else if(strcmp("green", c) == 0)
|
|
||||||
foregroundColor = COLOR_GREEN;
|
|
||||||
else if(strcmp("red", c) == 0)
|
|
||||||
foregroundColor = COLOR_RED;
|
|
||||||
else if(strcmp("cyan", c) == 0)
|
|
||||||
foregroundColor = COLOR_CYAN;
|
|
||||||
else
|
|
||||||
foregroundColor = COLOR_BLUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get and returns the current row position of the cursor. This involves
|
* Get and returns the current row position of the cursor. This involves
|
||||||
* sending the appropriate ANSI escape code to the terminal and
|
* sending the appropriate ANSI escape code to the terminal and
|
||||||
|
@ -24,7 +24,6 @@ void nmstermio_show_cursor(void);
|
|||||||
void nmstermio_beep(void);
|
void nmstermio_beep(void);
|
||||||
int nmstermio_get_clearscr(void);
|
int nmstermio_get_clearscr(void);
|
||||||
void nmstermio_set_clearscr(int);
|
void nmstermio_set_clearscr(int);
|
||||||
void nmstermio_set_foregroundcolor(char *);
|
|
||||||
int nmstermio_get_cursor_row(void);
|
int nmstermio_get_cursor_row(void);
|
||||||
|
|
||||||
|
|
||||||
|
@ -158,33 +158,6 @@ void nmstermio_set_clearscr(int s) {
|
|||||||
clearScr = 0;
|
clearScr = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Set the desired foreground color of the unencrypted characters as they
|
|
||||||
* are revealed by nmstermio_print_reveal_string(). Valid arguments are
|
|
||||||
* "white", "yellow", "magenta", "blue", "green", "red", and "cyan".
|
|
||||||
*/
|
|
||||||
void nmstermio_set_foregroundcolor(char *c) {
|
|
||||||
|
|
||||||
if(strcmp("white", c) == 0)
|
|
||||||
foregroundColor = COLOR_WHITE;
|
|
||||||
else if(strcmp("yellow", c) == 0)
|
|
||||||
foregroundColor = COLOR_YELLOW;
|
|
||||||
else if(strcmp("black", c) == 0)
|
|
||||||
foregroundColor = COLOR_BLACK;
|
|
||||||
else if(strcmp("magenta", c) == 0)
|
|
||||||
foregroundColor = COLOR_MAGENTA;
|
|
||||||
else if(strcmp("blue", c) == 0)
|
|
||||||
foregroundColor = COLOR_BLUE;
|
|
||||||
else if(strcmp("green", c) == 0)
|
|
||||||
foregroundColor = COLOR_GREEN;
|
|
||||||
else if(strcmp("red", c) == 0)
|
|
||||||
foregroundColor = COLOR_RED;
|
|
||||||
else if(strcmp("cyan", c) == 0)
|
|
||||||
foregroundColor = COLOR_CYAN;
|
|
||||||
else
|
|
||||||
foregroundColor = COLOR_BLUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get and returns the current row position of the cursor.
|
* Get and returns the current row position of the cursor.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user