Skip to content

Commit

Permalink
lead_docs_cli
Browse files Browse the repository at this point in the history
  • Loading branch information
ahqsoftwares committed Jan 31, 2025
1 parent 3a6cdb8 commit 25d3913
Show file tree
Hide file tree
Showing 34 changed files with 786 additions and 315 deletions.
4 changes: 1 addition & 3 deletions interpreter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ name = "interpreter"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
chalk_rs = { git = "https://github.com/leadlang/chalk.git" }


lealang_chalk_rs = "1"
2 changes: 1 addition & 1 deletion interpreter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use runtime::_root_syntax::RTCreatedModule;
use types::{DynMethodRes, Heap, LanguagePackages, MethodRes};
pub use val::*;

pub use chalk_rs::Chalk;
pub use lealang_chalk_rs::Chalk;

pub static VERSION_INT: u16 = 3;

Expand Down
34 changes: 24 additions & 10 deletions interpreter/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,24 @@ macro_rules! pkg_name {
};
}

#[macro_export]
macro_rules! methods {
($($x:tt)*) => {
fn methods(&self) -> interpreter::types::MethodRes {
&[
$($x)*
]
}
};
}
// #[macro_export]
// macro_rules! methods {
// ($($x:ident),*) => {
// fn doc(&self) -> std::collections::HashMap<&'static str, &'static str> {
// interpreter::hashmap! {
// $(stringify!($x) => _call_$x_doc),*
// }
// }

// fn methods(&self) -> interpreter::types::MethodRes {
// &[
// $({
// (stringify!($x), $x)
// }),*
// ]
// }
// };
// }

#[macro_export]
macro_rules! document {
Expand Down Expand Up @@ -103,6 +111,12 @@ macro_rules! modify {
};
};

($file:ident + $heap:ident: mut $y:ident) => {
let Some($y) = $heap.get_mut($y) else {
interpreter::error("Invalid Format or Varible not found!", $file);
};
};

($file:ident + $heap:ident: > $y:ident) => {
interpreter::warn("WARN: Deprecated library feature `>`, migrate to the $: syntax instead!");
if !$y.starts_with("$") && !$y.starts_with("*") {
Expand Down
2 changes: 1 addition & 1 deletion interpreter/src/types/fns.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::Package;
use chalk_rs::Chalk;
use lealang_chalk_rs::Chalk;
use std::collections::HashMap;

use super::{HeapWrapper, Options};
Expand Down
2 changes: 1 addition & 1 deletion lead/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ name = "lead_lib"
path = "./src/lib.rs"

[dependencies]
chalk_rs = { git = "https://github.com/leadlang/chalk.git" }
lealang_chalk_rs = "1"
lead_lang_interpreter = { path = "../interpreter" }
libloading = "0.8.6"
serde = { version = "1", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion lead/src/app/logo/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use chalk_rs::Chalk;
use lealang_chalk_rs::Chalk;
use std::{
env::consts::{ARCH, FAMILY, OS},
io::Write,
Expand Down
2 changes: 1 addition & 1 deletion lead/src/app/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use chalk_rs::Chalk;
use lealang_chalk_rs::Chalk;
use interpreter::types::{DynMethodRes, MethodRes};
use interpreter::{Application, Package as Pkg};
use std::env;
Expand Down
2 changes: 1 addition & 1 deletion lead/src/help.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use chalk_rs::Chalk;
use lealang_chalk_rs::Chalk;

macro_rules! generate_help {
($app_name:expr, $($option:expr => $description:expr),*) => {
Expand Down
2 changes: 1 addition & 1 deletion lead/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(unused)]

use chalk_rs::Chalk;
use lealang_chalk_rs::Chalk;
use std::{
env::args,
io::{stderr, Write},
Expand Down
4 changes: 4 additions & 0 deletions lead_docs_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ name = "lead_docs_lib"
crate-type = ["rlib", "cdylib"]

[dependencies]
cursive = { git = "https://github.com/gyscos/cursive.git", default-features = false, features = [
"crossterm-backend",
"markdown",
] }
inquire = { version = "0.7.5", default-features = false, features = [
"fuzzy",
"macros",
Expand Down
7 changes: 4 additions & 3 deletions lead_docs_cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use utils::make_sel;

mod utils;

pub mod viewer;

#[no_mangle]
pub fn run() {
println!("⚠️ Under Construction ⚠️");

make_sel();
viewer::run_cursive();
//make_sel();
}
12 changes: 0 additions & 12 deletions lead_docs_cli/src/utils/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ use std::{
sync::LazyLock,
};

use inquire::Select;

use crate::utils::package::Package;

static VERSION: &'static str = env!("CARGO_PKG_VERSION");
static LEAD_HOME: LazyLock<String> =
LazyLock::new(|| std::env::var("LEAD_HOME").expect("LEAD_HOME must be set"));
Expand Down Expand Up @@ -65,14 +61,6 @@ pub fn lead_ws() -> Vec<PackageEntry> {
data
}

pub(crate) fn prompt(data: Vec<PackageEntry>) -> Package {
let PackageEntry { display, file } = Select::new("Please select your package", data)
.prompt()
.expect("You must respond");

Package::new(file, display)
}

pub fn get_display(a: &str) -> String {
match a {
"liblead_core.so" | "lead_core.dll" | "liblead_core.dylib" => "📦 Lead Core".into(),
Expand Down
142 changes: 72 additions & 70 deletions lead_docs_cli/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,70 +1,72 @@
use std::collections::HashMap;

use inquire::Select;

mod docs;
mod package;

pub fn make_sel() {
let select = vec!["📚 Lead Default", "⚒️ Workspace"];

let category = Select::new("Select", select)
.prompt()
.expect("You must select one...");

let data = match category {
"📚 Lead Default" => docs::lead_lib(),
"⚒️ Workspace" => docs::lead_ws(),
_ => panic!("Invalid category"),
};

let package = docs::prompt(data);
let doc: HashMap<String, HashMap<&str, &str>> = package.doc;

println!("{doc:?}");
navigate(&package.display, &doc);
}

fn navigate(display: &str, doc: &HashMap<String, HashMap<&str, &str>>) {
let mut root: Option<&str> = None;

#[allow(unused_assignments)]
let mut last = None;

let mut current_level: u8 = 0;

loop {
let mut choices = if current_level == 0 { vec![] } else { vec![".."] };
let mut c = match current_level {
1 => doc.get(*root.as_ref().unwrap()).unwrap().iter().map(|(a,_)| a as &str).collect::<Vec<_>>(),
0 => doc.iter().map(|(a, _)| a as &str).collect::<Vec<_>>(),
_ => panic!("Unknown Level")
};

choices.append(&mut c);
choices.push("❌ Quit");

let sel = Select::new(&format!("Inside of {display}"), choices).prompt().expect("You must select one...");

match sel {
".." => {
current_level -= 1;
},
"❌ Quit" => return (),
e => {
current_level += 1;

match current_level {
1 => root = Some(e),
2 => {
last = Some(e);
break;
},
_ => panic!("Unknown Level")
}
}
}
}

println!("? {last:?}");
}
pub mod docs;
pub mod package;

// pub fn make_sel() {
// let select = vec!["📚 Lead Default", "⚒️ Workspace"];

// let category = Select::new("Select", select)
// .prompt()
// .expect("You must select one...");

// let data = match category {
// "📚 Lead Default" => docs::lead_lib(),
// "⚒️ Workspace" => docs::lead_ws(),
// _ => panic!("Invalid category"),
// };

// let package = docs::prompt(data);
// let doc: HashMap<String, HashMap<&str, &str>> = package.doc;

// navigate(&package.display, &doc);
// }

// fn navigate(display: &str, doc: &HashMap<String, HashMap<&str, &str>>) {
// let mut root: Option<&str> = None;

// #[allow(unused_assignments)]
// let mut last = None;

// let mut current_level: u8 = 0;

// loop {
// if current_level == 2 {
// let doc = doc.get(*root.as_ref().unwrap()).unwrap().get(*last.as_ref().unwrap()).unwrap();

// println!("{doc}");
// //show_cursive(include_str!("../../../LICENSE"));

// current_level -= 1;
// continue;
// }

// let mut choices = if current_level == 0 { vec![] } else { vec![".."] };
// let mut c = match current_level {
// 1 => doc.get(*root.as_ref().unwrap()).unwrap().iter().map(|(a,_)| a as &str).collect::<Vec<_>>(),
// 0 => doc.iter().map(|(a, _)| a as &str).collect::<Vec<_>>(),
// _ => panic!("Unknown Level")
// };

// choices.append(&mut c);
// choices.push("❌ Quit");

// let sel = Select::new(&format!("Inside of {display}"), choices).prompt().expect("You must select one...");

// match sel {
// ".." => {
// current_level -= 1;
// },
// "❌ Quit" => return (),
// e => {
// current_level += 1;

// match current_level {
// 1 => root = Some(e),
// 2 => {
// last = Some(e);
// },
// _ => panic!("Unknown Level")
// }
// }
// }
// }
// }
11 changes: 7 additions & 4 deletions lead_docs_cli/src/utils/package.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
use interpreter::Package as TraitPackage;
use libloading::Library;
use std::{collections::HashMap, ffi::OsStr};
use std::collections::HashMap;

use super::docs::PackageEntry;

pub struct Package {
pub name: String,
pub doc: HashMap<String, HashMap<&'static str, &'static str>>,
pub display: String,
_inner: Library,
}

impl Package {
pub fn new<T: AsRef<OsStr>>(path: T, display: String) -> Self {
pub fn new(pkg: &PackageEntry) -> Self {
unsafe {
let path = &pkg.file;
let library = Library::new(path).expect("Unable to load library");

let pkgs = library
Expand All @@ -28,7 +31,7 @@ impl Package {

Self {
_inner: library,
display,
name: pkg.display.clone(),
doc,
}
}
Expand Down
Loading

0 comments on commit 25d3913

Please sign in to comment.