Skip to content

Commit

Permalink
new update
Browse files Browse the repository at this point in the history
  • Loading branch information
ahqsoftwares committed Jan 1, 2025
1 parent 5d8fe23 commit 52681af
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 13 deletions.
18 changes: 16 additions & 2 deletions lead/src/app/logo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn get_sys_info() -> Vec<String> {
resp
}

pub fn render_lead_logo() {
pub fn render_lead_logo(monochrome: bool) {
let mut stdout = StandardStream::stdout(ColorChoice::Always);

let logo = include!("./logo.bin");
Expand All @@ -52,7 +52,21 @@ pub fn render_lead_logo() {
write!(&mut stdout, "{:<60}", dat).unwrap();

for [r, g, b] in stream {
stdout.set_color(ColorSpec::new().set_fg(Some(Color::Rgb(r, g, b)))).unwrap();
if monochrome {
let r = r as u16;
let g = g as u16;
let b = b as u16;

let avg = (r + g + b) / 3;

if avg > 128 {
stdout.set_color(ColorSpec::new().set_fg(Some(Color::Black))).unwrap();
} else {
stdout.set_color(ColorSpec::new().set_fg(Some(Color::White))).unwrap();
}
} else {
stdout.set_color(ColorSpec::new().set_fg(Some(Color::Rgb(r, g, b)))).unwrap();
}

write!(&mut stdout, "{}", fill).unwrap();
}
Expand Down
28 changes: 20 additions & 8 deletions lead/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ enum FullAccessLevel {

struct Options {
sysinfo: bool,
monochrome: bool,
full_access: FullAccessLevel,
log: bool,
}
Expand All @@ -41,33 +42,42 @@ pub async fn run(args: &[String], chalk: &mut Chalk) {
let data = metadata::get_meta().await;

if options.sysinfo {
logo::render_lead_logo();
logo::render_lead_logo(options.monochrome);
}

let chalk_1_mut: *mut Chalk = unsafe { chalk as *mut _ };
let chalk_2_mut: *mut Chalk = unsafe { chalk as *mut _ };
let pkgmap = create_pkg_map();

// We are guaranteed that the closures run in the single thread & NOT AT THE SAME TIME.
let mut application = Application::new(&data.entry, |path| fs::read(path).expect("Unable to read file"), |name| {
todo!();
}, move |pkg_name| {
let mut chalk = Chalk::new();
let chalk = unsafe { &mut *chalk_1_mut };

let pkg_name: &String = &pkg_name.into();

if data.allow_full_access_to_packages_named.contains(pkg_name) && options.log {
chalk.blue().print(&"[INFO] ");
println!("{pkg_name} has been granted full heap access");
chalk.blue().print(&format!("{pkg_name} "));

println!("has been granted full heap access");
}

if !data.allow_full_access_to_packages_named.contains(pkg_name) {
match options.full_access {
FullAccessLevel::SilentlyAllow => {}
FullAccessLevel::Warn => {
chalk.blue().print(&"[WARN] ");
println!("{pkg_name} was been granted full heap access");
chalk.yellow().print(&"[WARN] ");
chalk.blue().print(&format!("{pkg_name} "));

println!("was been granted full heap access");
}
FullAccessLevel::Deny => {
chalk.blue().print(&"[ERRR] ");
println!("{pkg_name} tried to get full heap access\n Exiting");
chalk.red().print(&"[ERRR] ");
chalk.blue().print(&format!("{pkg_name} "));

println!(" tried to get full heap access\n ❌ Access Denied, Exiting");
}
}
}
Expand Down Expand Up @@ -137,7 +147,8 @@ fn parse(args: &[String]) -> Options {
let mut opt = Options {
sysinfo: true,
log: false,
full_access: FullAccessLevel::Warn
full_access: FullAccessLevel::Warn,
monochrome: false
};

args.iter().for_each(|v| match v.as_str() {
Expand All @@ -146,6 +157,7 @@ fn parse(args: &[String]) -> Options {
opt.log = true;
opt.full_access = FullAccessLevel::Deny;
}
"--monochrome-logo" => opt.monochrome = true,
"--no-sysinfo" => opt.sysinfo = false,
"--log" => opt.log = true,
"--warn-full-access" => opt.full_access = FullAccessLevel::Warn,
Expand Down
1 change: 1 addition & 0 deletions lead/src/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ generate_help!(
format!(" {val}")
} => "",
" --prod" => "Same as --log --deny-full-access --no-sysinfo",
" --monochrome-logo" => "Enables monochrome variant of the lead logo",
" --no-sysinfo" => "Do not show sysinfo on load",
" --log" => "Log Full Heap Access events for packages mentioned in metadata",
" --allow-full-access" => "Silently allow Full Heap Access requests (NOT RECOMMENDED)",
Expand Down
2 changes: 0 additions & 2 deletions lead/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ pub(crate) mod metadata;
///
#[tokio::main]
async fn main() {
println!("⚠️ Under Construction ⚠️");

let mut chalk: Chalk = Chalk::new();

panic::set_hook(Box::new(|info| {
Expand Down
4 changes: 3 additions & 1 deletion lead/test/app.pb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
$2: @s"Hello"
malloc string Hello World

updrate

# $3: ahq::mk

# $3::test

print $1 $2
# print $1 $2

0 comments on commit 52681af

Please sign in to comment.