From 68c02fd4429c13f474aeba90aee0bb757377bb25 Mon Sep 17 00:00:00 2001 From: dawn <90008@gaze.systems> Date: Thu, 18 Dec 2025 19:54:19 +0300 Subject: [PATCH] add embedded fs for embedding files, move dysnomia stuff out of source --- Cargo.lock | 28 +++++++++++++++++++++- Cargo.toml | 5 ++-- embedded/.gitkeep | 0 src/cmd/ls.rs | 6 +++++ src/cmd/mod.rs | 2 -- src/cmd/sys.rs | 6 +++++ src/cmd/version.rs | 40 ------------------------------- src/completion/suggestions.rs | 3 --- src/globals.rs | 18 +++++++++++--- src/lib.rs | 44 ++--------------------------------- www/index.html | 20 ++++++++-------- www/package.json | 2 +- 12 files changed, 70 insertions(+), 104 deletions(-) create mode 100644 embedded/.gitkeep delete mode 100644 src/cmd/version.rs diff --git a/Cargo.lock b/Cargo.lock index 3481445..9ae5810 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -407,6 +407,16 @@ dependencies = [ "alloc-stdlib", ] +[[package]] +name = "bstr" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63044e1ae8e69f3b5a92c736ca6269b8d12fa7efe39bf34ddb06d102cf0e2cab" +dependencies = [ + "memchr", + "serde", +] + [[package]] name = "btree-range-map" version = "0.7.2" @@ -1404,6 +1414,7 @@ dependencies = [ "nu-protocol", "rapidhash", "reqwest", + "rust-embed", "scc", "serde", "serde_ipld_dagcbor", @@ -1733,6 +1744,19 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" +[[package]] +name = "globset" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52dfc19153a48bde0cbd630453615c8151bce3a5adfac7a0aebfbf0a1e1f57e3" +dependencies = [ + "aho-corasick", + "bstr", + "log", + "regex-automata", + "regex-syntax", +] + [[package]] name = "gloo-storage" version = "0.3.0" @@ -4407,6 +4431,7 @@ version = "8.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60b161f275cb337fe0a44d924a5f4df0ed69c2c39519858f931ce61c779d3475" dependencies = [ + "globset", "sha2", "walkdir", ] @@ -5784,9 +5809,10 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "vfs" version = "0.12.1" -source = "git+https://github.com/landaire/rust-vfs?branch=fix%2Fwasm#c4341e8e7c16a019c1a1415fc8a413bf883a08d5" +source = "git+https://github.com/90-008/rust-vfs?branch=fix%2Fwasm#547b30641d8f329614fb29e44c1c7360ef57ded9" dependencies = [ "filetime", + "rust-embed", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index f664bdb..d42d4cc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ wasm-bindgen = "=0.2.104" wasm-bindgen-futures = "0.4" getrandom = { version = "0.3", features = ["wasm_js"] } web-sys = { version = "0.3", features = ["console", "Window"] } -vfs = { version = "0.12" } +vfs = { version = "0.12", features = ["embedded-fs"] } nu-command = { git = "https://github.com/90-008/nushell", default-features = false } nu-engine = { git = "https://github.com/90-008/nushell", default-features = false } nu-parser = { git = "https://github.com/90-008/nushell", default-features = false } @@ -39,9 +39,10 @@ scc = "3" rapidhash = { version = "4", features = ["unsafe"] } async-lock = "3.4.1" compile-time = "0.2.0" +rust-embed = { version = "8.9.0", features = ["debug-embed", "include-exclude"] } [patch.crates-io] -vfs = { git = "https://github.com/landaire/rust-vfs", branch = "fix/wasm" } +vfs = { git = "https://github.com/90-008/rust-vfs", branch = "fix/wasm" } [profile.release] opt-level = 3 diff --git a/embedded/.gitkeep b/embedded/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/cmd/ls.rs b/src/cmd/ls.rs index 96ddc08..9ea5bea 100644 --- a/src/cmd/ls.rs +++ b/src/cmd/ls.rs @@ -11,6 +11,7 @@ use nu_protocol::{ Category, ListStream, PipelineData, Record, ShellError, Signature, SyntaxShape, Type, Value, engine::{Command, EngineState, Stack}, }; +use wasm_bindgen::JsValue; #[derive(Clone)] pub struct Ls; @@ -55,6 +56,11 @@ impl Command for Ls { let full_paths = call.has_flag(engine_state, stack, "full-paths")?; let pwd = get_pwd(); + // web_sys::console::log_1(&JsValue::from_str(&format!("{pwd:?}"))); + // web_sys::console::log_1(&JsValue::from_str(&format!( + // "{:?}", + // pwd.read_dir().map(|a| a.collect::>()) + // ))); let mut target_dir = pwd.clone(); if let Some(path) = path_arg { target_dir = Arc::new( diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index d3b567c..867c119 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -13,7 +13,6 @@ pub mod rm; pub mod save; pub mod source; pub mod sys; -pub mod version; pub use cd::Cd; pub use fetch::Fetch; @@ -30,4 +29,3 @@ pub use rm::Rm; pub use save::Save; pub use source::Source; pub use sys::Sys; -pub use version::Version; diff --git a/src/cmd/sys.rs b/src/cmd/sys.rs index 62aafea..673621a 100644 --- a/src/cmd/sys.rs +++ b/src/cmd/sys.rs @@ -180,6 +180,12 @@ impl Command for Sys { ); } + let date = compile_time::unix!(); + let rustc = compile_time::rustc_version_str!(); + + rec.push("build_time", Value::int(date, head)); + rec.push("rustc_version", Value::string(rustc, head)); + Ok(Value::record(rec, head).into_pipeline_data()) } } diff --git a/src/cmd/version.rs b/src/cmd/version.rs deleted file mode 100644 index 08b82a1..0000000 --- a/src/cmd/version.rs +++ /dev/null @@ -1,40 +0,0 @@ -use nu_protocol::Type; -use nu_protocol::engine::Call; -use nu_protocol::{ - Category, IntoPipelineData, PipelineData, ShellError, Signature, Value, - engine::{Command, EngineState, Stack}, -}; - -#[derive(Clone)] -pub struct Version; - -impl Command for Version { - fn name(&self) -> &str { - "version" - } - - fn signature(&self) -> Signature { - Signature::build(self.name()) - .input_output_type(Type::Nothing, Type::String) - .category(Category::System) - } - - fn description(&self) -> &str { - "print the version of dysnomia." - } - - fn run( - &self, - _engine_state: &EngineState, - _stack: &mut Stack, - call: &Call, - _input: PipelineData, - ) -> Result { - let date = compile_time::unix!(); - let rustc = compile_time::rustc_version_str!(); - Ok( - Value::string(format!("dysnomia.v099.t{date} (rustc {rustc})"), call.head) - .into_pipeline_data(), - ) - } -} diff --git a/src/completion/suggestions.rs b/src/completion/suggestions.rs index 2e924dc..8971e23 100644 --- a/src/completion/suggestions.rs +++ b/src/completion/suggestions.rs @@ -193,7 +193,6 @@ pub fn generate_flag_suggestions( pub fn generate_command_argument_suggestions( input: &str, engine_guard: &EngineState, - working_set: &StateWorkingSet, prefix: String, span: Span, command_name: String, @@ -299,7 +298,6 @@ pub fn generate_command_argument_suggestions( // Get positional arguments from signature // Check if argument is in required or optional positional let required_count = signature.required_positional.len(); - let is_optional = arg_index >= required_count; // Find the argument at the given index let arg = if arg_index < signature.required_positional.len() { @@ -546,7 +544,6 @@ pub fn generate_suggestions( } => generate_command_argument_suggestions( input, engine_guard, - working_set, prefix, span, command_name, diff --git a/src/globals.rs b/src/globals.rs index 9e175cd..0216d09 100644 --- a/src/globals.rs +++ b/src/globals.rs @@ -3,6 +3,7 @@ use nu_protocol::{ ShellError, Signal, Span, engine::{EngineState, StateDelta}, }; +use rust_embed::RustEmbed; use std::{ collections::HashMap, sync::{ @@ -11,18 +12,29 @@ use std::{ }, time::{Duration, SystemTime, UNIX_EPOCH}, }; -use vfs::{VfsError, VfsPath, error::VfsErrorKind}; +use vfs::{EmbeddedFS, OverlayFS, VfsError, VfsPath, error::VfsErrorKind}; use wasm_bindgen::prelude::*; use crate::memory_fs::MemoryFS; static ROOT: OnceLock> = OnceLock::new(); +fn init_vfs() -> Arc { + let memory_fs = VfsPath::new(MemoryFS::new()); + let embedded_fs = VfsPath::new(EmbeddedFS::::new()); + let overlaid_fs = VfsPath::new(OverlayFS::new(&[memory_fs, embedded_fs])); + Arc::new(overlaid_fs) +} + pub fn get_vfs() -> Arc { - ROOT.get_or_init(|| Arc::new(VfsPath::new(MemoryFS::new()))) - .clone() + ROOT.get_or_init(init_vfs).clone() } +#[derive(RustEmbed, Debug)] +#[folder = "embedded/"] +#[exclude = ".gitkeep"] +pub struct EmbeddedFiles; + static PWD: OnceLock>> = OnceLock::new(); pub fn get_pwd() -> Arc { diff --git a/src/lib.rs b/src/lib.rs index f244f6d..d19a108 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,7 +32,6 @@ pub mod memory_fs; use crate::{ cmd::{ Cd, Fetch, Job, JobKill, JobList, Ls, Mkdir, Mv, Open, Pwd, Random, Rm, Save, Source, Sys, - Version, }, default_context::add_shell_command_context, error::format_error, @@ -94,47 +93,8 @@ fn init_engine_internal() -> Result<(), Report> { engine_state = add_shell_command_context(engine_state); engine_state = add_extra_command_context(engine_state); - let write_file = |name: &str, contents: &str| { - get_vfs() - .join(name) - .and_then(|p| p.create_file()) - .and_then(|mut f| f.write_all(contents.as_bytes()).map_err(VfsError::from)) - .map_err(|e| miette::miette!(e.to_string())) - }; - - let access_log = format!( - r#"/dysnomia.v000 /user: 90008/ /ip: [REDACTED]/ /time: [REDACTED]// -/dysnomia.v002 /user: 90008/ /ip: [REDACTED]/ /time: [REDACTED]// -/dysnomia.v011 /user: 90008/ /ip: [REDACTED]/ /time: [REDACTED]// -[...ENTRIES TRUNCATED...] -/dysnomia.v099 /user: anonymous/ /ip: [REDACTED]/ /time: {time}//"#, - time = current_time() - .and_then(|t| t.duration_since(UNIX_EPOCH).ok()) - .map_or_else( - || "unknown".to_string(), - |time| chrono::DateTime::from_timestamp_nanos(time.as_nanos() as i64) - .format("%Y-%m-%dT%H:%M:%SZ") - .to_string() - ) - ); - write_file(".access.log", &access_log)?; - - let welcome_txt = r#"welcome anonymous ! - - -you are interfacing with dysnomia.v099 -using the nu shell. - - -a few commands you can try: - -"hello, user!" | save message.txt -fetch at://ptr.pet -ls --help"#; - write_file("welcome.txt", &welcome_txt)?; - let mut working_set = StateWorkingSet::new(&engine_state); - let decls: [Box; 16] = [ + let decls: [Box; 15] = [ Box::new(Ls), Box::new(Open), Box::new(Save), @@ -150,7 +110,6 @@ ls --help"#; Box::new(JobKill), Box::new(Sys), Box::new(Random), - Box::new(Version), ]; for decl in decls { working_set.add_decl(decl); @@ -161,6 +120,7 @@ ls --help"#; config.use_ansi_coloring = true.into(); config.show_banner = nu_protocol::BannerKind::Full; config.hooks.display_output = Some("table".into_value(Span::unknown())); + config.table.show_empty = false; engine_state.config = Arc::new(config); engine_state.set_signals(Signals::new(Arc::new(InterruptBool))); diff --git a/www/index.html b/www/index.html index bdd6a47..6d57991 100644 --- a/www/index.html +++ b/www/index.html @@ -1,13 +1,13 @@ - - - - - dysnomia - - -
- - + + + + + faunu + + +
+ + diff --git a/www/package.json b/www/package.json index f9f8011..267d8dc 100644 --- a/www/package.json +++ b/www/package.json @@ -1,5 +1,5 @@ { - "name": "dysnomia", + "name": "faunu", "private": true, "version": "0.0.0", "type": "module", -- 2.51.2