wip: Massive doc automation and improvement.
This commit is contained in:
@@ -25,6 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
|
||||
### Removed
|
||||
|
||||
- Deprecated attribute warning which cluttered the logs.
|
||||
- `std::json` (Rhai has built in json support).
|
||||
- `std::math` (Rhai already convers everything that it has).
|
||||
|
||||
## [0.1.0-beta] - 2025-08-27
|
||||
|
||||
|
||||
246
Cargo.lock
generated
246
Cargo.lock
generated
@@ -382,7 +382,7 @@ dependencies = [
|
||||
"glib",
|
||||
"libc",
|
||||
"once_cell",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -626,6 +626,41 @@ dependencies = [
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling"
|
||||
version = "0.20.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"darling_macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_core"
|
||||
version = "0.20.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e"
|
||||
dependencies = [
|
||||
"fnv",
|
||||
"ident_case",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"strsim",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_macro"
|
||||
version = "0.20.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"quote",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dbusmenu-glib"
|
||||
version = "0.1.0"
|
||||
@@ -690,6 +725,37 @@ dependencies = [
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_builder"
|
||||
version = "0.20.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "507dfb09ea8b7fa618fcf76e953f4f5e192547945816d5358edffe39f6f94947"
|
||||
dependencies = [
|
||||
"derive_builder_macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_builder_core"
|
||||
version = "0.20.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2d5bcf7b024d6835cfb3d473887cd966994907effbe9227e8c8219824d06c4e8"
|
||||
dependencies = [
|
||||
"darling",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_builder_macro"
|
||||
version = "0.20.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ab63b0e2bf4d5928aff72e83a7dace85d7bba5fe12dcc3c5a572d78caffd3f3c"
|
||||
dependencies = [
|
||||
"derive_builder_core",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_more"
|
||||
version = "1.0.0"
|
||||
@@ -860,7 +926,7 @@ dependencies = [
|
||||
"smart-default",
|
||||
"static_assertions",
|
||||
"sysinfo",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
"unescape",
|
||||
@@ -929,6 +995,12 @@ dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||
|
||||
[[package]]
|
||||
name = "fsevent-sys"
|
||||
version = "4.1.0"
|
||||
@@ -1137,6 +1209,15 @@ dependencies = [
|
||||
"x11",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "generate-rhai-docs"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"iirhai",
|
||||
"rhai",
|
||||
"rhai-autodocs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.14.7"
|
||||
@@ -1204,7 +1285,7 @@ dependencies = [
|
||||
"once_cell",
|
||||
"pin-project-lite",
|
||||
"smallvec",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1240,7 +1321,7 @@ dependencies = [
|
||||
"memchr",
|
||||
"once_cell",
|
||||
"smallvec",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1383,6 +1464,22 @@ dependencies = [
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "handlebars"
|
||||
version = "6.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "759e2d5aea3287cb1190c8ec394f42866cb5bf74fcbf213f354e3c856ea26098"
|
||||
dependencies = [
|
||||
"derive_builder",
|
||||
"log",
|
||||
"num-order",
|
||||
"pest",
|
||||
"pest_derive",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror 2.0.16",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.14.5"
|
||||
@@ -1452,6 +1549,12 @@ dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ident_case"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
||||
|
||||
[[package]]
|
||||
name = "iirhai"
|
||||
version = "0.1.0"
|
||||
@@ -1472,7 +1575,7 @@ dependencies = [
|
||||
"sysinfo",
|
||||
"termsize",
|
||||
"textwrap",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
]
|
||||
@@ -1744,7 +1847,7 @@ dependencies = [
|
||||
"log",
|
||||
"quick-xml",
|
||||
"serde",
|
||||
"thiserror",
|
||||
"thiserror 1.0.64",
|
||||
"tokio",
|
||||
"zbus",
|
||||
]
|
||||
@@ -1777,6 +1880,21 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-modular"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "17bb261bf36fa7d83f4c294f834e91256769097b3cb505d44831e0a179ac647f"
|
||||
|
||||
[[package]]
|
||||
name = "num-order"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "537b596b97c40fcf8056d153049eb22f481c17ebce72a513ec9286e4986d1bb6"
|
||||
dependencies = [
|
||||
"num-modular",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
@@ -1868,6 +1986,50 @@ dependencies = [
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pest"
|
||||
version = "2.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1db05f56d34358a8b1066f67cbb203ee3e7ed2ba674a6263a1d5ec6db2204323"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"thiserror 2.0.16",
|
||||
"ucd-trie",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pest_derive"
|
||||
version = "2.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb056d9e8ea77922845ec74a1c4e8fb17e7c218cc4fc11a15c5d25e189aa40bc"
|
||||
dependencies = [
|
||||
"pest",
|
||||
"pest_generator",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pest_generator"
|
||||
version = "2.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87e404e638f781eb3202dc82db6760c8ae8a1eeef7fb3fa8264b2ef280504966"
|
||||
dependencies = [
|
||||
"pest",
|
||||
"pest_meta",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pest_meta"
|
||||
version = "2.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "edd1101f170f5903fde0914f899bb503d9ff5271d7ba76bbb70bea63690cc0d5"
|
||||
dependencies = [
|
||||
"pest",
|
||||
"sha2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "phf"
|
||||
version = "0.11.2"
|
||||
@@ -2208,11 +2370,25 @@ dependencies = [
|
||||
"num-traits",
|
||||
"once_cell",
|
||||
"rhai_codegen",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"smallvec",
|
||||
"smartstring",
|
||||
"thin-vec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rhai-autodocs"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ebabdcbc322e497a1a6d20a18b2c667db2eaf8246d0e3288def5648af86c46a"
|
||||
dependencies = [
|
||||
"handlebars",
|
||||
"rhai",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rhai_codegen"
|
||||
version = "2.2.0"
|
||||
@@ -2295,18 +2471,18 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.215"
|
||||
version = "1.0.219"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f"
|
||||
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.215"
|
||||
version = "1.0.219"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0"
|
||||
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@@ -2315,9 +2491,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.128"
|
||||
version = "1.0.143"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8"
|
||||
checksum = "d401abef1d108fbd9cbaebc3e46611f4b1021f714a0597a71f41ee463f5f4a5a"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
@@ -2356,6 +2532,17 @@ dependencies = [
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.10.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
@@ -2401,6 +2588,9 @@ name = "smallvec"
|
||||
version = "1.13.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smart-default"
|
||||
@@ -2420,6 +2610,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"serde",
|
||||
"static_assertions",
|
||||
"version_check",
|
||||
]
|
||||
@@ -2578,6 +2769,9 @@ name = "thin-vec"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "144f754d318415ac792f9d69fc87abbbfc043ce2ef041c60f16ad828f638717d"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
@@ -2585,7 +2779,16 @@ version = "1.0.64"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
"thiserror-impl 1.0.64",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "2.0.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3467d614147380f2e4e374161426ff399c91084acd2363eaf549172b3d5e60c0"
|
||||
dependencies = [
|
||||
"thiserror-impl 2.0.16",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2599,6 +2802,17 @@ dependencies = [
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "2.0.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c5e1be1c48b9172ee610da68fd9cd2770e7a4056cb3fc98710ee6906f0c7960"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.87",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tiny-keccak"
|
||||
version = "2.0.2"
|
||||
@@ -2733,6 +2947,12 @@ version = "1.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
|
||||
|
||||
[[package]]
|
||||
name = "ucd-trie"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971"
|
||||
|
||||
[[package]]
|
||||
name = "uds_windows"
|
||||
version = "1.1.0"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[workspace]
|
||||
members = ["crates/*"]
|
||||
members = ["crates/*", "tools/*"]
|
||||
resolver = "2"
|
||||
|
||||
[workspace.dependencies]
|
||||
|
||||
@@ -7,17 +7,18 @@
|
||||
for providing data or doing certain actions.
|
||||
*/
|
||||
|
||||
mod apilib;
|
||||
mod builtin_signals;
|
||||
mod helper;
|
||||
mod stdlib;
|
||||
mod apilib;
|
||||
|
||||
use crate::module_resolver::{ChainedResolver, SimpleFileResolver};
|
||||
use rhai::module_resolvers::StaticModuleResolver;
|
||||
|
||||
use apilib::register_apilib;
|
||||
use builtin_signals::register_all_signals;
|
||||
use stdlib::register_stdlib;
|
||||
// expose the api's publically
|
||||
pub use stdlib::register_stdlib;
|
||||
pub use apilib::register_apilib;
|
||||
|
||||
pub fn register_all_providers(engine: &mut rhai::Engine) {
|
||||
let mut resolver = StaticModuleResolver::new();
|
||||
|
||||
@@ -4,6 +4,25 @@ use std::process::Command;
|
||||
|
||||
#[export_module]
|
||||
pub mod command {
|
||||
/// Executes a shell command without capturing the output.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `cmd` - The shell command to execute as a string.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// This function returns nothing if the command executes successfully. If there is an error
|
||||
/// running the command, it returns the error.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```js
|
||||
/// import "std::command" as cmd;
|
||||
///
|
||||
/// // Run a shell command (e.g., list directory contents)
|
||||
/// cmd::run("ls -l");
|
||||
/// ```
|
||||
#[rhai_fn(return_raw)]
|
||||
pub fn run(cmd: &str) -> Result<(), Box<EvalAltResult>> {
|
||||
Command::new("sh")
|
||||
@@ -14,6 +33,26 @@ pub mod command {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Executes a shell command and captures its output.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `cmd` - The shell command to execute as a string.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// This function returns the standard output of the command as a `string`. If the command fails,
|
||||
/// it returns the error.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```js
|
||||
/// import "std::command" as cmd;
|
||||
///
|
||||
/// // Run a shell command and capture its output
|
||||
/// let output = cmd::run_and_read("echo 'Hello, world!'");
|
||||
/// print(output); // output: Hello, world!
|
||||
/// ```
|
||||
#[rhai_fn(return_raw)]
|
||||
pub fn run_and_read(cmd: &str) -> Result<String, Box<EvalAltResult>> {
|
||||
let output = Command::new("sh")
|
||||
|
||||
@@ -3,29 +3,116 @@ use rhai::EvalAltResult;
|
||||
|
||||
#[export_module]
|
||||
pub mod env {
|
||||
/// Get the value of an environment variable.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `var` - The name of the environment variable to retrieve.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// This function returns the value of the environment variable as a `String`.
|
||||
/// If the variable is not found or there is an error, it returns a `Result::Err` with the error message.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```js
|
||||
/// import "std::env" as env;
|
||||
///
|
||||
/// // Get the value of the "HOME" environment variable
|
||||
/// let home_dir = env::get_env("HOME");
|
||||
/// print(home_dir); // output: /home/username
|
||||
/// ```
|
||||
#[rhai_fn(return_raw)]
|
||||
pub fn get_env(var: &str) -> Result<String, Box<EvalAltResult>> {
|
||||
std::env::var(var).map_err(|e| format!("Failed to get env: {e}").into())
|
||||
}
|
||||
|
||||
/// Set the value of an environment variable.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `var` - The name of the environment variable to set.
|
||||
/// * `value` - The value to assign to the environment variable.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// This function does not return a value.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```js
|
||||
/// import "std::env" as env;
|
||||
///
|
||||
/// // Set the value of the "MY_VAR" environment variable
|
||||
/// env::set_env("MY_VAR", "SomeValue");
|
||||
/// ```
|
||||
pub fn set_env(var: &str, value: &str) {
|
||||
std::env::set_var(var, value);
|
||||
}
|
||||
|
||||
/// Get the path to the home directory.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// This function returns the value of the "HOME" environment variable as a `String`.
|
||||
/// If the variable is not found or there is an error, it returns a `Result::Err` with the error message.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```js
|
||||
/// import "std::env" as env;
|
||||
///
|
||||
/// // Get the home directory
|
||||
/// let home_dir = env::get_home_dir();
|
||||
/// print(home_dir); // output: /home/username
|
||||
/// ```
|
||||
#[rhai_fn(return_raw)]
|
||||
pub fn get_home_dir() -> Result<String, Box<EvalAltResult>> {
|
||||
std::env::var("HOME").map_err(|e| format!("Failed to get home directory: {e}").into())
|
||||
}
|
||||
|
||||
/// Get the current working directory.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// This function returns the current working directory as a `String`. If there is an error
|
||||
/// (e.g., if the path cannot be retrieved), it returns a `Result::Err` with the error message.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```js
|
||||
/// import "std::env" as env;
|
||||
///
|
||||
/// // Get the current working directory
|
||||
/// let current_dir = env::get_current_dir();
|
||||
/// print(current_dir); // output: /home/username/project
|
||||
/// ```
|
||||
#[rhai_fn(return_raw)]
|
||||
pub fn get_current_dir() -> Result<String, Box<EvalAltResult>> {
|
||||
std::env::current_dir()
|
||||
.map_err(|e| format!("Failed to get CURRENT DIRECTORY: {e}").into())
|
||||
.map_err(|e| format!("Failed to get current directory: {e}").into())
|
||||
.and_then(|p| {
|
||||
p.into_os_string().into_string().map_err(|_| "Invalid path encoding".into())
|
||||
})
|
||||
}
|
||||
|
||||
/// Get the current username.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// This function returns the value of the "USER" environment variable as a `String`.
|
||||
/// If the variable is not found or there is an error, it returns a `Result::Err` with the error message.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```js
|
||||
/// import "std::env" as env;
|
||||
///
|
||||
/// // Get the username of the current user
|
||||
/// let username = env::get_username();
|
||||
/// print(username); // output: username
|
||||
/// ```
|
||||
#[rhai_fn(return_raw)]
|
||||
pub fn get_username() -> Result<String, Box<EvalAltResult>> {
|
||||
std::env::var("USER").map_err(|e| format!("Failed to get USER: {e}").into())
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
use rhai::plugin::*;
|
||||
use rhai::Dynamic;
|
||||
use rhai::EvalAltResult;
|
||||
use serde_json::Value;
|
||||
|
||||
#[export_module]
|
||||
pub mod json {
|
||||
// parse a JSON string into a Dynamic representing serde_json::Value
|
||||
#[rhai_fn(return_raw)]
|
||||
pub fn parse_json(json_str: &str) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
serde_json::from_str::<Value>(json_str)
|
||||
.map(Dynamic::from)
|
||||
.map_err(|e| format!("Failed to parse JSON: {e}").into())
|
||||
}
|
||||
|
||||
// Turn a dyn JSON val back to a string
|
||||
#[rhai_fn(return_raw)]
|
||||
pub fn to_string(json: Dynamic) -> Result<String, Box<EvalAltResult>> {
|
||||
let value: Value = json.try_cast::<Value>().ok_or("Expected a JSON value")?;
|
||||
serde_json::to_string(&value).map_err(|e| format!("Failed to serialize JSON: {e}").into())
|
||||
}
|
||||
|
||||
// get a key in a JSON object
|
||||
#[rhai_fn(return_raw)]
|
||||
pub fn get(json: Dynamic, key: &str) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
let value: Value = json.try_cast::<Value>().ok_or("Expected a JSON object")?;
|
||||
match value.get(key) {
|
||||
Some(v) => Ok(Dynamic::from(v.clone())),
|
||||
None => Ok(Dynamic::UNIT),
|
||||
}
|
||||
}
|
||||
|
||||
// Set a key in a JSON object
|
||||
#[rhai_fn(return_raw)]
|
||||
pub fn set(json: Dynamic, key: &str, value: Dynamic) -> Result<(), Box<EvalAltResult>> {
|
||||
let mut map: Value = json.try_cast::<Value>().ok_or("Expected a JSON object")?;
|
||||
if let Value::Object(ref mut obj) = map {
|
||||
let v: Value = value.try_cast::<Value>().ok_or("Expected JSON value")?;
|
||||
obj.insert(key.to_string(), v);
|
||||
Ok(())
|
||||
} else {
|
||||
Err("JSON value is not an object".into())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,157 +0,0 @@
|
||||
use rhai::plugin::*;
|
||||
use rhai::EvalAltResult;
|
||||
|
||||
#[export_module]
|
||||
pub mod math {
|
||||
// math constants
|
||||
pub const PI: f64 = std::f64::consts::PI;
|
||||
pub const E: f64 = std::f64::consts::E;
|
||||
pub const TAU: f64 = std::f64::consts::TAU;
|
||||
|
||||
// basics
|
||||
pub fn abs(x: f64) -> f64 {
|
||||
x.abs()
|
||||
}
|
||||
|
||||
#[rhai_fn(return_raw)]
|
||||
pub fn sqrt(x: f64) -> Result<f64, Box<EvalAltResult>> {
|
||||
if x < 0.0 {
|
||||
Err("Math error: sqrt of negative number".into())
|
||||
} else {
|
||||
Ok(x.sqrt())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pow(base: f64, exp: f64) -> f64 {
|
||||
base.powf(exp)
|
||||
}
|
||||
|
||||
pub fn sin(x: f64) -> f64 {
|
||||
x.sin()
|
||||
}
|
||||
pub fn cos(x: f64) -> f64 {
|
||||
x.cos()
|
||||
}
|
||||
pub fn tan(x: f64) -> f64 {
|
||||
x.tan()
|
||||
}
|
||||
|
||||
// exponentiation
|
||||
pub fn exp(x: f64) -> f64 {
|
||||
x.exp()
|
||||
}
|
||||
|
||||
#[rhai_fn(return_raw)]
|
||||
pub fn ln(x: f64) -> Result<f64, Box<EvalAltResult>> {
|
||||
if x <= 0.0 {
|
||||
Err("Math error: ln of non-positive number".into())
|
||||
} else {
|
||||
Ok(x.ln())
|
||||
}
|
||||
}
|
||||
|
||||
#[rhai_fn(return_raw)]
|
||||
pub fn log10(x: f64) -> Result<f64, Box<EvalAltResult>> {
|
||||
if x <= 0.0 {
|
||||
Err("Math error: log10 of non-positive number".into())
|
||||
} else {
|
||||
Ok(x.log10())
|
||||
}
|
||||
}
|
||||
|
||||
#[rhai_fn(return_raw)]
|
||||
pub fn log(base: f64, x: f64) -> Result<f64, Box<EvalAltResult>> {
|
||||
if base <= 0.0 || base == 1.0 {
|
||||
Err("Math error: invalid base for log".into())
|
||||
} else if x <= 0.0 {
|
||||
Err("Math error: log of non-positive number".into())
|
||||
} else {
|
||||
Ok(x.log(base))
|
||||
}
|
||||
}
|
||||
|
||||
// advanced
|
||||
#[rhai_fn(return_raw)]
|
||||
pub fn asin(x: f64) -> Result<f64, Box<EvalAltResult>> {
|
||||
if x < -1.0 || x > 1.0 {
|
||||
Err("Math error: asin input out of range [-1,1]".into())
|
||||
} else {
|
||||
Ok(x.asin())
|
||||
}
|
||||
}
|
||||
|
||||
#[rhai_fn(return_raw)]
|
||||
pub fn acos(x: f64) -> Result<f64, Box<EvalAltResult>> {
|
||||
if x < -1.0 || x > 1.0 {
|
||||
Err("Math error: acos input out of range [-1,1]".into())
|
||||
} else {
|
||||
Ok(x.acos())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn atan(x: f64) -> f64 {
|
||||
x.atan()
|
||||
}
|
||||
pub fn atan2(y: f64, x: f64) -> f64 {
|
||||
y.atan2(x)
|
||||
}
|
||||
|
||||
pub fn sinh(x: f64) -> f64 {
|
||||
x.sinh()
|
||||
}
|
||||
pub fn cosh(x: f64) -> f64 {
|
||||
x.cosh()
|
||||
}
|
||||
pub fn tanh(x: f64) -> f64 {
|
||||
x.tanh()
|
||||
}
|
||||
|
||||
pub fn floor(x: f64) -> f64 {
|
||||
x.floor()
|
||||
}
|
||||
pub fn ceil(x: f64) -> f64 {
|
||||
x.ceil()
|
||||
}
|
||||
pub fn round(x: f64) -> f64 {
|
||||
x.round()
|
||||
}
|
||||
pub fn trunc(x: f64) -> f64 {
|
||||
x.trunc()
|
||||
}
|
||||
pub fn fract(x: f64) -> f64 {
|
||||
x.fract()
|
||||
}
|
||||
|
||||
pub fn min(a: f64, b: f64) -> f64 {
|
||||
a.min(b)
|
||||
}
|
||||
pub fn max(a: f64, b: f64) -> f64 {
|
||||
a.max(b)
|
||||
}
|
||||
pub fn clamp(x: f64, min: f64, max: f64) -> f64 {
|
||||
x.clamp(min, max)
|
||||
}
|
||||
|
||||
// other api's
|
||||
#[rhai_fn(return_raw)]
|
||||
pub fn to_float(x: Dynamic) -> Result<f64, Box<EvalAltResult>> {
|
||||
if let Some(f) = x.clone().try_cast::<f64>() {
|
||||
Ok(f)
|
||||
} else if let Some(i) = x.try_cast::<i64>() {
|
||||
Ok(i as f64)
|
||||
} else {
|
||||
Err("Expected a number".into())
|
||||
}
|
||||
}
|
||||
|
||||
#[rhai_fn(return_raw)]
|
||||
pub fn to_int(x: Dynamic) -> Result<i64, Box<EvalAltResult>> {
|
||||
if let Some(i) = x.clone().try_cast::<i64>() {
|
||||
Ok(i)
|
||||
} else if let Some(f) = x.try_cast::<f64>() {
|
||||
Ok(f as i64)
|
||||
} else {
|
||||
Err("Expected a number".into())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
pub mod command;
|
||||
pub mod env;
|
||||
pub mod json;
|
||||
pub mod math;
|
||||
pub mod monitor;
|
||||
pub mod text;
|
||||
|
||||
@@ -10,22 +8,18 @@ use rhai::module_resolvers::StaticModuleResolver;
|
||||
|
||||
pub fn register_stdlib(resolver: &mut StaticModuleResolver) {
|
||||
use crate::providers::stdlib::{
|
||||
command::command, env::env, json::json, math::math, monitor::monitor, text::text,
|
||||
command::command, env::env, monitor::monitor, text::text,
|
||||
};
|
||||
|
||||
// adding modules
|
||||
let text_mod = exported_module!(text);
|
||||
let env_mod = exported_module!(env);
|
||||
let monitor_mod = exported_module!(monitor);
|
||||
let json_mod = exported_module!(json);
|
||||
let math_mod = exported_module!(math);
|
||||
let command_mod = exported_module!(command);
|
||||
|
||||
// inserting modules
|
||||
resolver.insert("std::text", text_mod);
|
||||
resolver.insert("std::env", env_mod);
|
||||
resolver.insert("std::monitor", monitor_mod);
|
||||
resolver.insert("std::json", json_mod);
|
||||
resolver.insert("std::math", math_mod);
|
||||
resolver.insert("std::command", command_mod);
|
||||
}
|
||||
|
||||
@@ -4,24 +4,97 @@ use rhai::plugin::*;
|
||||
|
||||
#[export_module]
|
||||
pub mod monitor {
|
||||
/// Get the number of connected monitors.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Returns the total number of connected monitors as an `i64`.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```js
|
||||
/// import "std::monitor" as monitor;
|
||||
///
|
||||
/// let count = monitor::count();
|
||||
/// print(count); // Output: Number of connected monitors
|
||||
/// ```
|
||||
pub fn count() -> i64 {
|
||||
get_monitor_count()
|
||||
}
|
||||
|
||||
pub fn primary_resolution() -> Vec<i64> {
|
||||
/// Get the resolution of the primary monitor.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Returns an array containing the width and height of the primary monitor as two `i64` values.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```js
|
||||
/// import "std::monitor" as monitor;
|
||||
///
|
||||
/// let resolution = monitor::primary_resolution();
|
||||
/// print(resolution); // Output: [width, height]
|
||||
/// ```
|
||||
pub fn primary_resolution() -> [i64; 2] {
|
||||
let (w, h) = get_primary_monitor_resolution();
|
||||
vec![w, h]
|
||||
[w, h]
|
||||
}
|
||||
|
||||
/// Get the resolution of the primary monitor as a string.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Returns the resolution of the primary monitor as a string in the format "width x height".
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```js
|
||||
/// import "std::monitor" as monitor;
|
||||
///
|
||||
/// let resolution_str = monitor::primary_resolution_str();
|
||||
/// print(resolution_str); // Output: "1920x1080"
|
||||
/// ```
|
||||
pub fn primary_resolution_str() -> String {
|
||||
let (w, h) = get_primary_monitor_resolution();
|
||||
format!("{w}x{h}")
|
||||
}
|
||||
|
||||
pub fn all_resolutions() -> Vec<Vec<i64>> {
|
||||
get_all_monitor_resolutions().into_iter().map(|(w, h)| vec![w, h]).collect()
|
||||
/// Get the resolutions of all connected monitors.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Returns an array of arrays, where each inner array contains the width and height of a monitor.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```js
|
||||
/// import "std::monitor" as monitor;
|
||||
///
|
||||
/// let resolutions = monitor::all_resolutions();
|
||||
/// print(resolutions); // Output: [[width1, height1], [width2, height2], ...]
|
||||
/// ```
|
||||
pub fn all_resolutions() -> Vec<[i64; 2]> {
|
||||
get_all_monitor_resolutions()
|
||||
.into_iter()
|
||||
.map(|(w, h)| [w, h])
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Get the resolutions of all connected monitors as a string.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Returns a string where each monitor's resolution is formatted as "width x height", separated by commas.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```js
|
||||
/// import "std::monitor" as monitor;
|
||||
///
|
||||
/// let resolutions_str = monitor::all_resolutions_str();
|
||||
/// print(resolutions_str); // Output: "1920x1080, 1280x720"
|
||||
/// ```
|
||||
pub fn all_resolutions_str() -> String {
|
||||
get_all_monitor_resolutions()
|
||||
.into_iter()
|
||||
@@ -30,20 +103,92 @@ pub mod monitor {
|
||||
.join(", ")
|
||||
}
|
||||
|
||||
pub fn dimensions(index: i64) -> Vec<i64> {
|
||||
/// Get the dimensions (x, y, width, height) of a specific monitor.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `index` - The index of the monitor (0-based).
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Returns an array with the monitor's position (x, y) and size (width, height).
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```js
|
||||
/// import "std::monitor" as monitor;
|
||||
///
|
||||
/// let dimensions = monitor::dimensions(0);
|
||||
/// print(dimensions); // Output: [x, y, width, height]
|
||||
/// ```
|
||||
pub fn dimensions(index: i64) -> [i64; 4] {
|
||||
let (x, y, w, h) = get_monitor_dimensions(index as usize);
|
||||
vec![x, y, w, h]
|
||||
[x, y, w, h]
|
||||
}
|
||||
|
||||
/// Get the dimensions of a specific monitor as a string.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `index` - The index of the monitor (0-based).
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Returns the monitor's dimensions as a string in the format "x,y - width x height".
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```js
|
||||
/// import "std::monitor" as monitor;
|
||||
///
|
||||
/// let dimensions_str = monitor::dimensions_str(0);
|
||||
/// print(dimensions_str); // Output: "0,0 - 1920x1080"
|
||||
/// ```
|
||||
pub fn dimensions_str(index: i64) -> String {
|
||||
let (x, y, w, h) = get_monitor_dimensions(index as usize);
|
||||
format!("{x},{y} - {w}x{h}")
|
||||
}
|
||||
|
||||
/// Get the DPI (dots per inch) of a specific monitor.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `index` - The index of the monitor (0-based).
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Returns the DPI (scale factor * base DPI) of the monitor as a `f64`.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```js
|
||||
/// import "std::monitor" as monitor;
|
||||
///
|
||||
/// let dpi = monitor::dpi(0);
|
||||
/// print(dpi); // Output: DPI of the monitor
|
||||
/// ```
|
||||
pub fn dpi(index: i64) -> f64 {
|
||||
get_monitor_dpi(index as usize)
|
||||
}
|
||||
|
||||
/// Get the DPI of a specific monitor as a string.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `index` - The index of the monitor (0-based).
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Returns the DPI of the monitor as a string formatted to 1 decimal place.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```js
|
||||
/// import "std::monitor" as monitor;
|
||||
///
|
||||
/// let dpi_str = monitor::dpi_str(0);
|
||||
/// print(dpi_str); // Output: "96.0"
|
||||
/// ```
|
||||
pub fn dpi_str(index: i64) -> String {
|
||||
format!("{:.1}", get_monitor_dpi(index as usize))
|
||||
}
|
||||
|
||||
@@ -1,7 +1,27 @@
|
||||
use rhai::plugin::*;
|
||||
|
||||
/// A module providing utility functions for string manipulation.
|
||||
#[export_module]
|
||||
pub mod text {
|
||||
|
||||
/// Converts a string to a slug (lowercase words joined by hyphens).
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `text` - A string to be converted to a slug.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Returns the `text` as a slug.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```js
|
||||
/// import "std::text" as text;
|
||||
///
|
||||
/// let result = text::to_slug("Hello World!");
|
||||
/// print(result); // output: "hello-world"
|
||||
/// ```
|
||||
pub fn to_slug(text: &str) -> String {
|
||||
let lower = text.to_lowercase();
|
||||
|
||||
@@ -16,6 +36,24 @@ pub mod text {
|
||||
slug
|
||||
}
|
||||
|
||||
/// Converts a string to camel case.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `text` - A string to be converted to camel case.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Returns the `text` in camel case format.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```js
|
||||
/// import "std::text" as text;
|
||||
///
|
||||
/// let result = text::to_camel_case("hello world example");
|
||||
/// print(result); // output: "helloWorldExample"
|
||||
/// ```
|
||||
pub fn to_camel_case(text: &str) -> String {
|
||||
let cleaned: String = text
|
||||
.chars()
|
||||
@@ -42,6 +80,25 @@ pub mod text {
|
||||
camel
|
||||
}
|
||||
|
||||
/// Truncates a string to the specified number of characters.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `text` - A string to be truncated.
|
||||
/// * `max_chars` - The maximum number of characters to keep in the string.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Returns a truncated string.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```js
|
||||
/// import "std::text" as text;
|
||||
///
|
||||
/// let result = text::truncate_chars("Hello World!", 5);
|
||||
/// print(result); // output: "Hello"
|
||||
/// ```
|
||||
pub fn truncate_chars(text: String, max_chars: i64) -> String {
|
||||
match text.char_indices().nth(max_chars.try_into().unwrap()) {
|
||||
None => text,
|
||||
@@ -49,10 +106,46 @@ pub mod text {
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts a string to uppercase.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `s` - A string to be converted to uppercase.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Returns the string in uppercase.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```js
|
||||
/// import "std::text" as text;
|
||||
///
|
||||
/// let result = text::to_upper("hello");
|
||||
/// print(result); // output: "HELLO"
|
||||
/// ```
|
||||
pub fn to_upper(s: &str) -> String {
|
||||
s.to_uppercase()
|
||||
}
|
||||
|
||||
/// Converts a string to lowercase.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `s` - A string to be converted to lowercase.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// Returns the string in lowercase.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```js
|
||||
/// import "std::text" as text;
|
||||
///
|
||||
/// let result = text::to_lower("HELLO");
|
||||
/// print(result); // output: "hello"
|
||||
/// ```
|
||||
pub fn to_lower(s: &str) -> String {
|
||||
s.to_lowercase()
|
||||
}
|
||||
|
||||
@@ -10,5 +10,5 @@ default-theme = "latte"
|
||||
preferred-dark-theme = "ewwii"
|
||||
site-url = "/ewwii/"
|
||||
git-repository-url = "https://github.com/Ewwii-sh/ewwii"
|
||||
additional-js = ["js/home_button.js"]
|
||||
additional-css = ["./theme/catppuccin.css", "./theme/ewwii.css"]
|
||||
additional-js = ["./js/home_button.js", "./theme/rhai-autodocs/tabs.js"]
|
||||
additional-css = ["./theme/catppuccin.css", "./theme/ewwii.css", "./theme/rhai-autodocs/default.css"]
|
||||
@@ -24,6 +24,7 @@
|
||||
- [Modules](modules/modules.md)
|
||||
|
||||
- [User Defined Modules](modules/user_defined.md)
|
||||
- [Global Builtin Rhai Functions](modules/global.md)
|
||||
- [Std Library](modules/stdlib.md)
|
||||
- [API Library](modules/apilib.md)
|
||||
|
||||
|
||||
@@ -1,81 +1,254 @@
|
||||
# API Library
|
||||
# env
|
||||
|
||||
## `api::wifi`
|
||||
`Namespace: global/std/env`
|
||||
|
||||
The `wifi` module provides cross-platform Wi-Fi management for Linux and macOS systems. Functions include scanning networks, querying the current connection, connecting/disconnecting, and enabling/disabling the Wi-Fi adapter.
|
||||
<div style='box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2); padding: 15px; border-radius: 5px; border: 1px solid var(--theme-hover)'>
|
||||
<h2 class="func-name"> <code>fn</code> get_current_dir </h2>
|
||||
|
||||
> **Note:** macOS support is largely untested and may behave differently depending on system configuration.
|
||||
|
||||
### Usage
|
||||
|
||||
```js
|
||||
import "api::wifi" as wifi;
|
||||
|
||||
// Scan for available networks
|
||||
let networks = wifi::scan();
|
||||
|
||||
// Get current Wi-Fi connection info
|
||||
let current = wifi::current_connection();
|
||||
|
||||
// Connect to a network with password
|
||||
wifi::connect("MySSID", "MyPassword");
|
||||
|
||||
// Connect to a network without password (using saved profile)
|
||||
wifi::connect_without_password("MySSID");
|
||||
|
||||
// Disconnect from the current network
|
||||
wifi::disconnect();
|
||||
|
||||
// Enable/disable the Wi-Fi adapter
|
||||
wifi::enable_adapter();
|
||||
wifi::disable_adapter();
|
||||
|
||||
// Get adapter connection
|
||||
wifi::get_adapter_connectivity();
|
||||
```rust,ignore
|
||||
fn get_current_dir() -> String
|
||||
```
|
||||
|
||||
### Functions
|
||||
<div>
|
||||
<div class="tab">
|
||||
<button group="get_current_dir" id="link-get_current_dir-Description" class="tablinks active"
|
||||
onclick="openTab(event, 'get_current_dir', 'Description')">
|
||||
Description
|
||||
</button>
|
||||
<button group="get_current_dir" id="link-get_current_dir-Returns" class="tablinks"
|
||||
onclick="openTab(event, 'get_current_dir', 'Returns')">
|
||||
Returns
|
||||
</button>
|
||||
<button group="get_current_dir" id="link-get_current_dir-Example" class="tablinks"
|
||||
onclick="openTab(event, 'get_current_dir', 'Example')">
|
||||
Example
|
||||
</button>
|
||||
</div>
|
||||
|
||||
| Function | Description |
|
||||
| -------------------------------- | ----------------------------------------------------------------------------------------------- |
|
||||
| `scan()` | Returns a list of nearby Wi-Fi networks with `ssid`, `signal`, and `security` fields. |
|
||||
| `scan_linux()` | **Linux only**. Returns a list of nearby Wi-Fi networks. Equivalent to `scan()`. |
|
||||
| `scan_macos()` | **macOS only (untested)**. Returns a list of nearby Wi-Fi networks. Equivalent to `scan()`. |
|
||||
| `current_connection()` | Returns information about the current Wi-Fi connection as a map (`ssid`, `signal`, `security`). |
|
||||
| `connect(ssid, password)` | Connects to a Wi-Fi network. |
|
||||
| `connect_without_password(ssid)` | Connects to a Wi-Fi network without password by using the saved profile. |
|
||||
| `disconnect()` | Disconnects from the currently connected network (does not disable the adapter). |
|
||||
| `enable_adapter()` | Turns the Wi-Fi adapter on. |
|
||||
| `get_adapter_connectivity()` | Returns a normalized connectivity status of the Wi-Fi adapter. |
|
||||
<div group="get_current_dir" id="get_current_dir-Description" class="tabcontent" style="display: block;" >
|
||||
Get the current working directory.
|
||||
</div>
|
||||
<div group="get_current_dir" id="get_current_dir-Returns" class="tabcontent" style="display: none;" >
|
||||
|
||||
### Extra Notes
|
||||
This function returns the current working directory as a `String`. If there is an error
|
||||
(e.g., if the path cannot be retrieved), it returns a `Result::Err` with the error message.
|
||||
|
||||
`get_adapter_connectivity()` has different outcome possibilities in each OS.
|
||||
</div>
|
||||
<div group="get_current_dir" id="get_current_dir-Example" class="tabcontent" style="display: none;" >
|
||||
|
||||
**All possible results:**
|
||||
```
|
||||
import "std::env" as env;
|
||||
|
||||
- **Linux**: `"full"` (internet available), `"limited"` (network only, no internet), `"portal"` (captive portal), `"none"` (no connectivity)
|
||||
- **macOS**: `"full"` (connected to a Wi-Fi network) or `"none"` (not connected)
|
||||
|
||||
### Platform Notes
|
||||
|
||||
- **Linux**: Uses `nmcli` for all operations. The module assumes `nmcli` is installed and accessible in `$PATH`.
|
||||
- **macOS**: Uses `/System/Library/PrivateFrameworks/Apple80211.framework/.../airport` for scanning and disconnecting, and `networksetup` for connecting and enabling/disabling the adapter.
|
||||
- **Unsupported OS**: All functions return an error if the platform is neither Linux nor macOS.
|
||||
|
||||
### Returned Data Formats
|
||||
|
||||
- `scan()` (or `scan_linux` / `scan_macos`) returns an **array of maps**:
|
||||
|
||||
```js
|
||||
[
|
||||
{ ssid: "HomeWiFi", signal: "78", security: "WPA2" },
|
||||
{ ssid: "CafeNet", signal: "65", security: "WPA" },
|
||||
];
|
||||
// Get the current working directory
|
||||
let current_dir = env::get_current_dir();
|
||||
print(current_dir); // output: /home/username/project
|
||||
```
|
||||
|
||||
- `current_connection()` returns a **map**:
|
||||
</div>
|
||||
|
||||
```js
|
||||
{ "ssid": "HomeWiFi", "signal": "78", "security": "WPA2" }
|
||||
</div>
|
||||
</div>
|
||||
</br>
|
||||
<div style='box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2); padding: 15px; border-radius: 5px; border: 1px solid var(--theme-hover)'>
|
||||
<h2 class="func-name"> <code>fn</code> get_env </h2>
|
||||
|
||||
```rust,ignore
|
||||
fn get_env(var: String) -> String
|
||||
```
|
||||
|
||||
<div>
|
||||
<div class="tab">
|
||||
<button group="get_env" id="link-get_env-Description" class="tablinks active"
|
||||
onclick="openTab(event, 'get_env', 'Description')">
|
||||
Description
|
||||
</button>
|
||||
<button group="get_env" id="link-get_env-Arguments" class="tablinks"
|
||||
onclick="openTab(event, 'get_env', 'Arguments')">
|
||||
Arguments
|
||||
</button>
|
||||
<button group="get_env" id="link-get_env-Returns" class="tablinks"
|
||||
onclick="openTab(event, 'get_env', 'Returns')">
|
||||
Returns
|
||||
</button>
|
||||
<button group="get_env" id="link-get_env-Example" class="tablinks"
|
||||
onclick="openTab(event, 'get_env', 'Example')">
|
||||
Example
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div group="get_env" id="get_env-Description" class="tabcontent" style="display: block;" >
|
||||
Get the value of an environment variable.
|
||||
</div>
|
||||
<div group="get_env" id="get_env-Arguments" class="tabcontent" style="display: none;" >
|
||||
|
||||
- `var` - The name of the environment variable to retrieve.
|
||||
</div>
|
||||
<div group="get_env" id="get_env-Returns" class="tabcontent" style="display: none;" >
|
||||
|
||||
This function returns the value of the environment variable as a `String`.
|
||||
If the variable is not found or there is an error, it returns a `Result::Err` with the error message.
|
||||
|
||||
</div>
|
||||
<div group="get_env" id="get_env-Example" class="tabcontent" style="display: none;" >
|
||||
|
||||
```
|
||||
import "std::env" as env;
|
||||
|
||||
// Get the value of the "HOME" environment variable
|
||||
let home_dir = env::get_env("HOME");
|
||||
print(home_dir); // output: /home/username
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</br>
|
||||
<div style='box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2); padding: 15px; border-radius: 5px; border: 1px solid var(--theme-hover)'>
|
||||
<h2 class="func-name"> <code>fn</code> get_home_dir </h2>
|
||||
|
||||
```rust,ignore
|
||||
fn get_home_dir() -> String
|
||||
```
|
||||
|
||||
<div>
|
||||
<div class="tab">
|
||||
<button group="get_home_dir" id="link-get_home_dir-Description" class="tablinks active"
|
||||
onclick="openTab(event, 'get_home_dir', 'Description')">
|
||||
Description
|
||||
</button>
|
||||
<button group="get_home_dir" id="link-get_home_dir-Returns" class="tablinks"
|
||||
onclick="openTab(event, 'get_home_dir', 'Returns')">
|
||||
Returns
|
||||
</button>
|
||||
<button group="get_home_dir" id="link-get_home_dir-Example" class="tablinks"
|
||||
onclick="openTab(event, 'get_home_dir', 'Example')">
|
||||
Example
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div group="get_home_dir" id="get_home_dir-Description" class="tabcontent" style="display: block;" >
|
||||
Get the path to the home directory.
|
||||
</div>
|
||||
<div group="get_home_dir" id="get_home_dir-Returns" class="tabcontent" style="display: none;" >
|
||||
|
||||
This function returns the value of the "HOME" environment variable as a `String`.
|
||||
If the variable is not found or there is an error, it returns a `Result::Err` with the error message.
|
||||
|
||||
</div>
|
||||
<div group="get_home_dir" id="get_home_dir-Example" class="tabcontent" style="display: none;" >
|
||||
|
||||
```
|
||||
import "std::env" as env;
|
||||
|
||||
// Get the home directory
|
||||
let home_dir = env::get_home_dir();
|
||||
print(home_dir); // output: /home/username
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</br>
|
||||
<div style='box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2); padding: 15px; border-radius: 5px; border: 1px solid var(--theme-hover)'>
|
||||
<h2 class="func-name"> <code>fn</code> get_username </h2>
|
||||
|
||||
```rust,ignore
|
||||
fn get_username() -> String
|
||||
```
|
||||
|
||||
<div>
|
||||
<div class="tab">
|
||||
<button group="get_username" id="link-get_username-Description" class="tablinks active"
|
||||
onclick="openTab(event, 'get_username', 'Description')">
|
||||
Description
|
||||
</button>
|
||||
<button group="get_username" id="link-get_username-Returns" class="tablinks"
|
||||
onclick="openTab(event, 'get_username', 'Returns')">
|
||||
Returns
|
||||
</button>
|
||||
<button group="get_username" id="link-get_username-Example" class="tablinks"
|
||||
onclick="openTab(event, 'get_username', 'Example')">
|
||||
Example
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div group="get_username" id="get_username-Description" class="tabcontent" style="display: block;" >
|
||||
Get the current username.
|
||||
</div>
|
||||
<div group="get_username" id="get_username-Returns" class="tabcontent" style="display: none;" >
|
||||
|
||||
This function returns the value of the "USER" environment variable as a `String`.
|
||||
If the variable is not found or there is an error, it returns a `Result::Err` with the error message.
|
||||
|
||||
</div>
|
||||
<div group="get_username" id="get_username-Example" class="tabcontent" style="display: none;" >
|
||||
|
||||
```
|
||||
import "std::env" as env;
|
||||
|
||||
// Get the username of the current user
|
||||
let username = env::get_username();
|
||||
print(username); // output: username
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</br>
|
||||
<div style='box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2); padding: 15px; border-radius: 5px; border: 1px solid var(--theme-hover)'>
|
||||
<h2 class="func-name"> <code>fn</code> set_env </h2>
|
||||
|
||||
```rust,ignore
|
||||
fn set_env(var: String, value: String)
|
||||
```
|
||||
|
||||
<div>
|
||||
<div class="tab">
|
||||
<button group="set_env" id="link-set_env-Description" class="tablinks active"
|
||||
onclick="openTab(event, 'set_env', 'Description')">
|
||||
Description
|
||||
</button>
|
||||
<button group="set_env" id="link-set_env-Arguments" class="tablinks"
|
||||
onclick="openTab(event, 'set_env', 'Arguments')">
|
||||
Arguments
|
||||
</button>
|
||||
<button group="set_env" id="link-set_env-Returns" class="tablinks"
|
||||
onclick="openTab(event, 'set_env', 'Returns')">
|
||||
Returns
|
||||
</button>
|
||||
<button group="set_env" id="link-set_env-Example" class="tablinks"
|
||||
onclick="openTab(event, 'set_env', 'Example')">
|
||||
Example
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div group="set_env" id="set_env-Description" class="tabcontent" style="display: block;" >
|
||||
Set the value of an environment variable.
|
||||
</div>
|
||||
<div group="set_env" id="set_env-Arguments" class="tabcontent" style="display: none;" >
|
||||
|
||||
- `var` - The name of the environment variable to set.
|
||||
- `value` - The value to assign to the environment variable.
|
||||
</div>
|
||||
<div group="set_env" id="set_env-Returns" class="tabcontent" style="display: none;" >
|
||||
|
||||
This function does not return a value.
|
||||
|
||||
</div>
|
||||
<div group="set_env" id="set_env-Example" class="tabcontent" style="display: none;" >
|
||||
|
||||
```
|
||||
import "std::env" as env;
|
||||
|
||||
// Set the value of the "MY_VAR" environment variable
|
||||
env::set_env("MY_VAR", "SomeValue");
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</br>
|
||||
|
||||
6642
docs/src/modules/global.md
Normal file
6642
docs/src/modules/global.md
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
54
docs/theme/rhai-autodocs/default.css
vendored
Normal file
54
docs/theme/rhai-autodocs/default.css
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
pre {
|
||||
display: block;
|
||||
font-family: monospace;
|
||||
white-space: pre;
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
.func-name {
|
||||
/* override mdbook default margin for h2/h3 */
|
||||
margin-top: 0em;
|
||||
}
|
||||
|
||||
/* Annotations for a diagram or a snippet */
|
||||
.ann {
|
||||
text-align: center;
|
||||
font-size: 0.8em;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
/* custom css for the rust SectionFormat::Tabs option */
|
||||
/* NOTE: variables used here are from mdbook's css */
|
||||
|
||||
.tab {
|
||||
overflow: hidden;
|
||||
border-left: 1px solid var(--theme-hover);
|
||||
border-right: 1px solid var(--theme-hover);
|
||||
}
|
||||
|
||||
.tab button {
|
||||
color: var(--icons);
|
||||
background-color: var(--theme-hover);
|
||||
float: left;
|
||||
border: none;
|
||||
outline: none;
|
||||
cursor: pointer;
|
||||
padding: 14px 16px;
|
||||
transition: 0.3s;
|
||||
}
|
||||
|
||||
.tab button:hover {
|
||||
color: var(--icons-hover);
|
||||
background-color: var(--theme-hover);
|
||||
}
|
||||
|
||||
.tab button.active {
|
||||
background-color: var(--theme-bg);
|
||||
}
|
||||
|
||||
.tabcontent {
|
||||
display: none;
|
||||
padding: 6px 12px;
|
||||
border: 1px solid var(--theme-hover);
|
||||
border-top: none;
|
||||
}
|
||||
23
docs/theme/rhai-autodocs/tabs.js
vendored
Normal file
23
docs/theme/rhai-autodocs/tabs.js
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
function openTab(evt, group, tab) {
|
||||
const tabcontent = document.getElementsByClassName("tabcontent");
|
||||
|
||||
for (let i = 0; i < tabcontent.length; i++) {
|
||||
if (tabcontent[i].getAttribute("group") === group) {
|
||||
tabcontent[i].style.display = "none";
|
||||
}
|
||||
}
|
||||
|
||||
const tablinks = document.getElementsByClassName("tablinks");
|
||||
|
||||
for (let i = 0; i < tablinks.length; i++) {
|
||||
if (tabcontent[i].getAttribute("group") === group) {
|
||||
tablinks[i].className = tablinks[i].className.replace(
|
||||
" active",
|
||||
""
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById(`${group}-${tab}`).style.display = "block";
|
||||
evt.currentTarget.className += " active";
|
||||
}
|
||||
Binary file not shown.
13
tools/README.md
Normal file
13
tools/README.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# Ewwii tools
|
||||
|
||||
## 1. generate-rhai-docs
|
||||
|
||||
Generate rhai docs is a tool that will generate the documentation of rhai's builtin stdlib.
|
||||
|
||||
### How to run
|
||||
|
||||
Run the following command in the root of the repository to run `generate-rhai-docs`:
|
||||
|
||||
```bash
|
||||
$ cargo run --release -p generate-rhai-docs
|
||||
```
|
||||
1
tools/generate-rhai-docs/.gitignore
vendored
Normal file
1
tools/generate-rhai-docs/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
612
tools/generate-rhai-docs/Cargo.lock
generated
Normal file
612
tools/generate-rhai-docs/Cargo.lock
generated
Normal file
@@ -0,0 +1,612 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.8.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"const-random",
|
||||
"getrandom 0.3.3",
|
||||
"once_cell",
|
||||
"version_check",
|
||||
"zerocopy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34efbcccd345379ca2868b2b2c9d3782e9cc58ba87bc7d79d5b53d9c9ae6f25d"
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.10.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9"
|
||||
|
||||
[[package]]
|
||||
name = "const-random"
|
||||
version = "0.1.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87e00182fe74b066627d63b85fd550ac2998d4b0bd86bfed477a0ae4c7c71359"
|
||||
dependencies = [
|
||||
"const-random-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "const-random-macro"
|
||||
version = "0.1.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e"
|
||||
dependencies = [
|
||||
"getrandom 0.2.16",
|
||||
"once_cell",
|
||||
"tiny-keccak",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crunchy"
|
||||
version = "0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5"
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling"
|
||||
version = "0.20.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"darling_macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_core"
|
||||
version = "0.20.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e"
|
||||
dependencies = [
|
||||
"fnv",
|
||||
"ident_case",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"strsim",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_macro"
|
||||
version = "0.20.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_builder"
|
||||
version = "0.20.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "507dfb09ea8b7fa618fcf76e953f4f5e192547945816d5358edffe39f6f94947"
|
||||
dependencies = [
|
||||
"derive_builder_macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_builder_core"
|
||||
version = "0.20.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2d5bcf7b024d6835cfb3d473887cd966994907effbe9227e8c8219824d06c4e8"
|
||||
dependencies = [
|
||||
"darling",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_builder_macro"
|
||||
version = "0.20.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ab63b0e2bf4d5928aff72e83a7dace85d7bba5fe12dcc3c5a572d78caffd3f3c"
|
||||
dependencies = [
|
||||
"derive_builder_core",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.10.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"crypto-common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||
|
||||
[[package]]
|
||||
name = "generate-rhai-docs"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rhai",
|
||||
"rhai-autodocs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.14.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
|
||||
dependencies = [
|
||||
"typenum",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi 0.11.1+wasi-snapshot-preview1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"r-efi",
|
||||
"wasi 0.14.3+wasi-0.2.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "handlebars"
|
||||
version = "6.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "759e2d5aea3287cb1190c8ec394f42866cb5bf74fcbf213f354e3c856ea26098"
|
||||
dependencies = [
|
||||
"derive_builder",
|
||||
"log",
|
||||
"num-order",
|
||||
"pest",
|
||||
"pest_derive",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ident_case"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
||||
|
||||
[[package]]
|
||||
name = "instant"
|
||||
version = "0.1.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.175"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0"
|
||||
|
||||
[[package]]
|
||||
name = "num-modular"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "17bb261bf36fa7d83f4c294f834e91256769097b3cb505d44831e0a179ac647f"
|
||||
|
||||
[[package]]
|
||||
name = "num-order"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "537b596b97c40fcf8056d153049eb22f481c17ebce72a513ec9286e4986d1bb6"
|
||||
dependencies = [
|
||||
"num-modular",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.21.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||
dependencies = [
|
||||
"portable-atomic",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pest"
|
||||
version = "2.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1db05f56d34358a8b1066f67cbb203ee3e7ed2ba674a6263a1d5ec6db2204323"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"thiserror",
|
||||
"ucd-trie",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pest_derive"
|
||||
version = "2.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb056d9e8ea77922845ec74a1c4e8fb17e7c218cc4fc11a15c5d25e189aa40bc"
|
||||
dependencies = [
|
||||
"pest",
|
||||
"pest_generator",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pest_generator"
|
||||
version = "2.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87e404e638f781eb3202dc82db6760c8ae8a1eeef7fb3fa8264b2ef280504966"
|
||||
dependencies = [
|
||||
"pest",
|
||||
"pest_meta",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pest_meta"
|
||||
version = "2.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "edd1101f170f5903fde0914f899bb503d9ff5271d7ba76bbb70bea63690cc0d5"
|
||||
dependencies = [
|
||||
"pest",
|
||||
"sha2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic"
|
||||
version = "1.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.101"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "r-efi"
|
||||
version = "5.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
|
||||
|
||||
[[package]]
|
||||
name = "rhai"
|
||||
version = "1.22.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2780e813b755850e50b178931aaf94ed24f6817f46aaaf5d21c13c12d939a249"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bitflags",
|
||||
"instant",
|
||||
"num-traits",
|
||||
"once_cell",
|
||||
"rhai_codegen",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"smallvec",
|
||||
"smartstring",
|
||||
"thin-vec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rhai-autodocs"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ebabdcbc322e497a1a6d20a18b2c667db2eaf8246d0e3288def5648af86c46a"
|
||||
dependencies = [
|
||||
"handlebars",
|
||||
"rhai",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rhai_codegen"
|
||||
version = "2.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a5a11a05ee1ce44058fa3d5961d05194fdbe3ad6b40f904af764d81b86450e6b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.219"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.219"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.143"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d401abef1d108fbd9cbaebc3e46611f4b1021f714a0597a71f41ee463f5f4a5a"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.10.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cpufeatures",
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.15.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smartstring"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"serde",
|
||||
"static_assertions",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "static_assertions"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thin-vec"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "144f754d318415ac792f9d69fc87abbbfc043ce2ef041c60f16ad828f638717d"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "2.0.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3467d614147380f2e4e374161426ff399c91084acd2363eaf549172b3d5e60c0"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "2.0.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c5e1be1c48b9172ee610da68fd9cd2770e7a4056cb3fc98710ee6906f0c7960"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tiny-keccak"
|
||||
version = "2.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237"
|
||||
dependencies = [
|
||||
"crunchy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f"
|
||||
|
||||
[[package]]
|
||||
name = "ucd-trie"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2896d95c02a80c6d6a5d6e953d479f5ddf2dfdb6a244441010e373ac0fb88971"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.1+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.14.3+wasi-0.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a51ae83037bdd272a9e28ce236db8c07016dd0d50c27038b3f407533c030c95"
|
||||
dependencies = [
|
||||
"wit-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen"
|
||||
version = "0.45.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "052283831dbae3d879dc7f51f3d92703a316ca49f91540417d38591826127814"
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.8.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f"
|
||||
dependencies = [
|
||||
"zerocopy-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy-derive"
|
||||
version = "0.8.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
9
tools/generate-rhai-docs/Cargo.toml
Normal file
9
tools/generate-rhai-docs/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "generate-rhai-docs"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
iirhai.workspace = true
|
||||
rhai = "1.22.2"
|
||||
rhai-autodocs = "0.9.0"
|
||||
6655
tools/generate-rhai-docs/rhai_docs/global.md
Normal file
6655
tools/generate-rhai-docs/rhai_docs/global.md
Normal file
File diff suppressed because it is too large
Load Diff
63
tools/generate-rhai-docs/src/main.rs
Normal file
63
tools/generate-rhai-docs/src/main.rs
Normal file
@@ -0,0 +1,63 @@
|
||||
use rhai::{Engine, module_resolvers::StaticModuleResolver};
|
||||
use std::{env, fs, path::Path};
|
||||
use iirhai::providers;
|
||||
use rhai_autodocs::{export::options, generate::mdbook};
|
||||
|
||||
fn generate_docs(engine: &Engine, path: &str, filename: &str, include_std: bool) {
|
||||
let docs = options()
|
||||
.include_standard_packages(include_std)
|
||||
.export(engine)
|
||||
.expect("failed to generate documentation");
|
||||
|
||||
// Generate markdown documentation content
|
||||
let docs_content = mdbook().generate(&docs).unwrap();
|
||||
|
||||
if docs_content.is_empty() {
|
||||
eprintln!("No documentation generated for {}.", filename);
|
||||
return;
|
||||
}
|
||||
|
||||
// Combine all module docs into one
|
||||
let full_docs = docs_content.into_iter().map(|(_, doc)| doc).collect::<Vec<String>>().join("\n");
|
||||
|
||||
// Write documentation to markdown file
|
||||
let file_path = Path::new(path).join(format!("{}.md", filename));
|
||||
fs::write(&file_path, full_docs).expect("failed to write documentation");
|
||||
println!("Documentation generated at: {}", file_path.display());
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let path = if args.len() > 1 {
|
||||
&args[1]
|
||||
} else {
|
||||
"./docs/src/modules"
|
||||
};
|
||||
|
||||
// engine/resolver
|
||||
let engine = Engine::new();
|
||||
let mut resolver = StaticModuleResolver::new();
|
||||
|
||||
// Generate global.md (full docs)
|
||||
generate_docs(&engine, path, "global", true);
|
||||
|
||||
// Generate stdlib.md docs (custom stdlib)
|
||||
resolver.clear();
|
||||
let mut engine = Engine::new(); // recreate engine to reset state
|
||||
providers::register_stdlib(&mut resolver);
|
||||
for (module_name, module) in resolver.iter() {
|
||||
engine.register_static_module(module_name, module.clone());
|
||||
}
|
||||
generate_docs(&engine, path, "stdlib", false);
|
||||
|
||||
// Generate apilib.md docs
|
||||
resolver.clear();
|
||||
let mut engine = Engine::new(); // recreate engine to reset state
|
||||
providers::register_apilib(&mut resolver);
|
||||
for (module_name, module) in resolver.iter() {
|
||||
engine.register_static_module(module_name, module.clone());
|
||||
}
|
||||
generate_docs(&engine, path, "apilib", false);
|
||||
|
||||
println!("Docs generation completed.");
|
||||
}
|
||||
Reference in New Issue
Block a user