Compare commits
10 Commits
db66a6a562
...
c334492ea9
Author | SHA1 | Date | |
---|---|---|---|
|
c334492ea9 | ||
|
78fb4ecbfc | ||
|
c280dbe716 | ||
|
d7b402c764 | ||
|
ec74203e70 | ||
|
cb4873e2ab | ||
|
9e23931041 | ||
|
8842fb7e04 | ||
|
8a326f8ef4 | ||
|
d124669e02 |
1
.github/FUNDING.yml
vendored
Normal file
1
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1 @@
|
||||
github: bartobri
|
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,3 +1,8 @@
|
||||
bin/*
|
||||
obj/*
|
||||
.vs
|
||||
|
||||
|
||||
# Added by cargo
|
||||
|
||||
/target
|
||||
|
23
Cargo.lock
generated
Normal file
23
Cargo.lock
generated
Normal file
@ -0,0 +1,23 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "lexopt"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baff4b617f7df3d896f97fe922b64817f6cd9a756bb81d40f8883f2f66dcb401"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.147"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
|
||||
|
||||
[[package]]
|
||||
name = "nmsrust"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"lexopt",
|
||||
"libc",
|
||||
]
|
15
Cargo.toml
Normal file
15
Cargo.toml
Normal file
@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "nmsrust"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
lexopt = "0.3.0"
|
||||
libc = "0.2.147"
|
||||
|
2
Makefile
2
Makefile
@ -18,7 +18,7 @@ CFLAGS ?= -Wextra -Wall -O2
|
||||
.PHONY: all install uninstall clean
|
||||
|
||||
nms: $(OBJ)/input.o $(OBJ)/error.o $(OBJ)/nmscharset.o $(OBJ)/nmstermio.o $(OBJ)/nmseffect.o $(OBJ)/nms.o | $(BIN)
|
||||
$(CC) $(CFLAGS) -o $(BIN)/$@ $^
|
||||
$(CC) $(CFLAGS) -o $(BIN)/$@ $^ target/release/libnmsrust.a
|
||||
|
||||
sneakers: $(OBJ)/nmscharset.o $(OBJ)/nmstermio.o $(OBJ)/nmseffect.o $(OBJ)/sneakers.o | $(BIN)
|
||||
$(CC) $(CFLAGS) -o $(BIN)/$@ $^
|
||||
|
@ -1,5 +1,7 @@
|
||||
![Version](https://img.shields.io/badge/Version-1.0.1-green.svg)
|
||||
|
||||
Like this project? Consider tipping me: [https://github.com/sponsors/bartobri](https://github.com/sponsors/bartobri)
|
||||
|
||||
No More Secrets
|
||||
===============
|
||||
|
||||
@ -33,7 +35,6 @@ Table of Contents
|
||||
2. [Usage](#usage)
|
||||
3. [The NMS Library](#the-nms-library)
|
||||
4. [License](#license)
|
||||
5. [Tips](#tips)
|
||||
|
||||
Download and Install
|
||||
--------------------
|
||||
@ -143,8 +144,3 @@ License
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License. See [LICENSE](LICENSE) for
|
||||
more details.
|
||||
|
||||
Tips
|
||||
----
|
||||
|
||||
[Tips are always appreciated!](https://github.com/bartobri/tips)
|
||||
|
42
src/args.rs
Normal file
42
src/args.rs
Normal file
@ -0,0 +1,42 @@
|
||||
use std::ffi::OsString;
|
||||
|
||||
use lexopt::prelude::*;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub(crate) struct Args {
|
||||
pub(crate) version: bool,
|
||||
pub(crate) clear_screen: bool,
|
||||
pub(crate) foreground: Option<OsString>,
|
||||
pub(crate) autodecrypt: bool,
|
||||
pub(crate) mask_blanks: bool,
|
||||
}
|
||||
|
||||
pub(crate) fn parse_arguments() -> Result<Args, lexopt::Error> {
|
||||
let mut parser = lexopt::Parser::from_env();
|
||||
|
||||
let mut args = Args::default();
|
||||
|
||||
while let Some(arg) = parser.next()? {
|
||||
match arg {
|
||||
Short('a') => {
|
||||
args.autodecrypt = true;
|
||||
}
|
||||
Short('c') => {
|
||||
args.clear_screen = true;
|
||||
}
|
||||
Short('f') => {
|
||||
let foreground = parser.value()?;
|
||||
args.foreground = Some(foreground);
|
||||
}
|
||||
Short('s') => {
|
||||
args.mask_blanks = true;
|
||||
}
|
||||
Short('v') => {
|
||||
args.version = true;
|
||||
}
|
||||
_ => return Err(arg.unexpected()),
|
||||
}
|
||||
}
|
||||
|
||||
Ok(args)
|
||||
}
|
35
src/lib.rs
Normal file
35
src/lib.rs
Normal file
@ -0,0 +1,35 @@
|
||||
mod args;
|
||||
|
||||
use libc::{c_int, c_void};
|
||||
|
||||
const VERSION: &str = "2.0.0";
|
||||
|
||||
extern "C" {
|
||||
fn nmseffect_set_autodecrypt(_: c_int) -> c_void;
|
||||
fn nmseffect_set_clearscr(_: c_int) -> c_void;
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn rust_main() {
|
||||
println!("Hello from rust");
|
||||
|
||||
let args = args::parse_arguments().unwrap();
|
||||
|
||||
if args.version {
|
||||
println!("nms version {VERSION}");
|
||||
std::process::exit(0);
|
||||
}
|
||||
|
||||
if args.clear_screen {
|
||||
unsafe {
|
||||
nmseffect_set_clearscr(1);
|
||||
}
|
||||
}
|
||||
|
||||
if args.autodecrypt {
|
||||
unsafe {
|
||||
nmseffect_set_autodecrypt(1);
|
||||
}
|
||||
}
|
||||
println!("{:?}", args);
|
||||
}
|
12
src/nms.c
12
src/nms.c
@ -15,8 +15,11 @@
|
||||
|
||||
#define VERSION "1.0.1"
|
||||
|
||||
extern void rust_main();
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
rust_main();
|
||||
int r, o;
|
||||
unsigned char *input;
|
||||
|
||||
@ -29,18 +32,9 @@ int main(int argc, char *argv[])
|
||||
case 'f':
|
||||
nmseffect_set_foregroundcolor(optarg);
|
||||
break;
|
||||
case 'a':
|
||||
nmseffect_set_autodecrypt(1);
|
||||
break;
|
||||
case 's':
|
||||
nmseffect_set_maskblank(1);
|
||||
break;
|
||||
case 'c':
|
||||
nmseffect_set_clearscr(1);
|
||||
break;
|
||||
case 'v':
|
||||
printf("nms version " VERSION "\n");
|
||||
return EXIT_SUCCESS;
|
||||
case '?':
|
||||
if (isprint(optopt))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user