From f6080b08cb5d010198e4327403700735bff1a9f1 Mon Sep 17 00:00:00 2001 From: Nithin Muthukumar <33675303+nithinmuthukumar@users.noreply.github.com> Date: Sat, 11 Nov 2023 12:48:03 -0500 Subject: [PATCH] redoing it (#263) --- plugins/shrs_lang_options/Cargo.toml | 18 ----------- plugins/shrs_lang_options/examples/basic.rs | 3 -- plugins/shrs_lang_options/src/lib.rs | 35 --------------------- plugins/shrs_mux/examples/basic.rs | 2 +- plugins/shrs_mux/src/lang_options.rs | 31 ++++++++++++++++++ plugins/shrs_mux/src/lib.rs | 12 +++++-- shrs_example/src/main.rs | 2 +- 7 files changed, 43 insertions(+), 60 deletions(-) delete mode 100644 plugins/shrs_lang_options/Cargo.toml delete mode 100644 plugins/shrs_lang_options/examples/basic.rs delete mode 100644 plugins/shrs_lang_options/src/lib.rs create mode 100644 plugins/shrs_mux/src/lang_options.rs diff --git a/plugins/shrs_lang_options/Cargo.toml b/plugins/shrs_lang_options/Cargo.toml deleted file mode 100644 index ec4d0664..00000000 --- a/plugins/shrs_lang_options/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "shrs_lang_options" -version = "0.0.2" -description = "" -readme = "README.md" - -authors.workspace = true -categories.workspace = true -edition.workspace = true -homepage.workspace = true -keywords.workspace = true -license.workspace = true -repository.workspace = true - -[dependencies] -shrs = { path = "../../crates/shrs", version = "0.0.2" } -shrs_mux = {path = "../shrs_mux/", version = "0.0.2"} - diff --git a/plugins/shrs_lang_options/examples/basic.rs b/plugins/shrs_lang_options/examples/basic.rs deleted file mode 100644 index ee805639..00000000 --- a/plugins/shrs_lang_options/examples/basic.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - unimplemented!(); -} diff --git a/plugins/shrs_lang_options/src/lib.rs b/plugins/shrs_lang_options/src/lib.rs deleted file mode 100644 index 5fbfa41c..00000000 --- a/plugins/shrs_lang_options/src/lib.rs +++ /dev/null @@ -1,35 +0,0 @@ -use std::{collections::HashMap, default, usize}; - -use shrs::prelude::*; -use shrs_mux::ChangeLangCtx; - -pub struct LangOptionsPlugin { - highlighters: HashMap>, -} -impl LangOptionsPlugin { - pub fn new(highlighters: HashMap>) -> Self { - LangOptionsPlugin { highlighters } - } -} -impl Default for LangOptionsPlugin { - fn default() -> Self { - let highlighters: HashMap> = HashMap::from([]); - Self { highlighters } - } -} - -impl Plugin for LangOptionsPlugin { - fn init(&self, shell: &mut shrs::ShellConfig) -> anyhow::Result<()> { - shell.hooks.register(swap_lang_options); - - Ok(()) - } -} -fn swap_lang_options( - sh: &Shell, - sh_ctx: &mut Context, - sh_rt: &mut Runtime, - ctx: &ChangeLangCtx, -) -> anyhow::Result<()> { - Ok(()) -} diff --git a/plugins/shrs_mux/examples/basic.rs b/plugins/shrs_mux/examples/basic.rs index 105caec3..789b24ad 100644 --- a/plugins/shrs_mux/examples/basic.rs +++ b/plugins/shrs_mux/examples/basic.rs @@ -3,7 +3,7 @@ use shrs_mux::MuxPlugin; fn main() { let myshell = ShellBuilder::default() - .with_plugin(MuxPlugin) + .with_plugin(MuxPlugin::new()) .build() .unwrap(); diff --git a/plugins/shrs_mux/src/lang_options.rs b/plugins/shrs_mux/src/lang_options.rs new file mode 100644 index 00000000..b8e6495e --- /dev/null +++ b/plugins/shrs_mux/src/lang_options.rs @@ -0,0 +1,31 @@ +use std::collections::HashMap; + +use shrs::{ + anyhow, + prelude::{Context, Highlighter, Runtime, Shell}, +}; + +use crate::ChangeLangCtx; + +pub struct LangOptions { + highlighters: HashMap>, +} +impl LangOptions { + pub fn new(highlighters: HashMap>) -> Self { + LangOptions { highlighters } + } +} +impl Default for LangOptions { + fn default() -> Self { + let highlighters: HashMap> = HashMap::from([]); + Self { highlighters } + } +} +pub(crate) fn swap_lang_options( + sh: &Shell, + sh_ctx: &mut Context, + sh_rt: &mut Runtime, + ctx: &ChangeLangCtx, +) -> anyhow::Result<()> { + Ok(()) +} diff --git a/plugins/shrs_mux/src/lib.rs b/plugins/shrs_mux/src/lib.rs index 1df63e33..67d83705 100644 --- a/plugins/shrs_mux/src/lib.rs +++ b/plugins/shrs_mux/src/lib.rs @@ -1,12 +1,14 @@ mod builtin; mod interpreter; mod lang; +mod lang_options; use std::collections::{HashMap, HashSet}; use anyhow::anyhow; use builtin::MuxBuiltin; use lang::{BashLang, MuxLang, NuLang, PythonLang}; +use lang_options::{swap_lang_options, LangOptions}; use shrs::prelude::*; pub struct MuxState { @@ -61,11 +63,15 @@ pub struct ChangeLangCtx { new_lang: String, } -pub struct MuxPlugin; +pub struct MuxPlugin { + lang_options: LangOptions, +} impl MuxPlugin { pub fn new() -> Self { - MuxPlugin + MuxPlugin { + lang_options: LangOptions::default(), + } } } @@ -87,7 +93,9 @@ impl Plugin for MuxPlugin { shell.state.insert(MuxState::new(lang_names).unwrap()); let langs_map = HashMap::from_iter(langs); shell.lang = Box::new(MuxLang::new(langs_map)); + shell.hooks.register(swap_lang_options); Ok(()) } } + diff --git a/shrs_example/src/main.rs b/shrs_example/src/main.rs index 4ab8c13c..ea13e00d 100644 --- a/shrs_example/src/main.rs +++ b/shrs_example/src/main.rs @@ -183,7 +183,7 @@ a rusty POSIX shell | build {}"#, .with_plugin(OutputCapturePlugin) .with_plugin(CommandTimerPlugin) .with_plugin(RunContextPlugin::new()) - .with_plugin(MuxPlugin) + .with_plugin(MuxPlugin::new()) .with_plugin(CdStackPlugin) .build() .expect("Could not construct shell");