Skip to content

Commit

Permalink
redoing it (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
nithinmuthukumar authored Nov 11, 2023
1 parent b9f6f05 commit f6080b0
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 60 deletions.
18 changes: 0 additions & 18 deletions plugins/shrs_lang_options/Cargo.toml

This file was deleted.

3 changes: 0 additions & 3 deletions plugins/shrs_lang_options/examples/basic.rs

This file was deleted.

35 changes: 0 additions & 35 deletions plugins/shrs_lang_options/src/lib.rs

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/shrs_mux/examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use shrs_mux::MuxPlugin;

fn main() {
let myshell = ShellBuilder::default()
.with_plugin(MuxPlugin)
.with_plugin(MuxPlugin::new())
.build()
.unwrap();

Expand Down
31 changes: 31 additions & 0 deletions plugins/shrs_mux/src/lang_options.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use std::collections::HashMap;

use shrs::{
anyhow,
prelude::{Context, Highlighter, Runtime, Shell},
};

use crate::ChangeLangCtx;

pub struct LangOptions {
highlighters: HashMap<String, Box<dyn Highlighter>>,
}
impl LangOptions {
pub fn new(highlighters: HashMap<String, Box<dyn Highlighter>>) -> Self {
LangOptions { highlighters }
}
}
impl Default for LangOptions {
fn default() -> Self {
let highlighters: HashMap<String, Box<dyn Highlighter>> = 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(())
}
12 changes: 10 additions & 2 deletions plugins/shrs_mux/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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(),
}
}
}

Expand All @@ -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(())
}
}

2 changes: 1 addition & 1 deletion shrs_example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit f6080b0

Please sign in to comment.