Refactor logging system to switch between stdout and file logging
* Refactor logging to switch between stdout and file logging * Use "clear" instead of "tput reset" for unix * Remove redundant comments
This commit is contained in:
parent
d449c61643
commit
a4a8c59bb8
16 changed files with 252 additions and 148 deletions
|
@ -3,5 +3,3 @@ name = "editor"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("editor")
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,10 +6,11 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.93"
|
anyhow = "1.0.93"
|
||||||
chrono = "0.4.38"
|
chrono = "0.4.38"
|
||||||
|
clap = { version = "4.5.21", features = ["derive"] }
|
||||||
colored = "2.1.0"
|
colored = "2.1.0"
|
||||||
lazy_static = "1.5.0"
|
lazy_static = "1.5.0"
|
||||||
#log = "0.4.22"
|
log = "0.4.22"
|
||||||
log2 = "0.1.14"
|
once_cell = "1.20.2"
|
||||||
parking_lot = "0.12.3"
|
parking_lot = "0.12.3"
|
||||||
reedline = "0.37.0"
|
reedline = "0.37.0"
|
||||||
regex = "1.11.1"
|
regex = "1.11.1"
|
||||||
|
|
|
@ -11,4 +11,3 @@ pub fn init_renderer() -> Result<()> {
|
||||||
let mut app = App::default();
|
let mut app = App::default();
|
||||||
Ok(event_loop.run_app(&mut app)?)
|
Ok(event_loop.run_app(&mut app)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use tokio::task::spawn_blocking;
|
|
||||||
use winit::window::Window;
|
use winit::window::Window;
|
||||||
|
|
||||||
pub struct WgpuCtx<'window> {
|
pub struct WgpuCtx<'window> {
|
||||||
|
@ -46,13 +45,14 @@ impl<'window> WgpuCtx<'window> {
|
||||||
surface.configure(&device, &surface_config);
|
surface.configure(&device, &surface_config);
|
||||||
|
|
||||||
Ok(WgpuCtx {
|
Ok(WgpuCtx {
|
||||||
device: device,
|
device,
|
||||||
queue: queue,
|
queue,
|
||||||
surface: surface,
|
surface,
|
||||||
surface_config: surface_config,
|
surface_config,
|
||||||
adapter: adapter,
|
adapter,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_blocking(window: Arc<Window>) -> Result<WgpuCtx<'window>> {
|
pub fn new_blocking(window: Arc<Window>) -> Result<WgpuCtx<'window>> {
|
||||||
tokio::task::block_in_place(|| {
|
tokio::task::block_in_place(|| {
|
||||||
tokio::runtime::Runtime::new()
|
tokio::runtime::Runtime::new()
|
||||||
|
@ -60,19 +60,25 @@ impl<'window> WgpuCtx<'window> {
|
||||||
.block_on(async { WgpuCtx::new(window).await })
|
.block_on(async { WgpuCtx::new(window).await })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resize(&mut self, new_size: (u32, u32)) {
|
pub fn resize(&mut self, new_size: (u32, u32)) {
|
||||||
let (width, height) = new_size;
|
let (width, height) = new_size;
|
||||||
self.surface_config.width = width.max(1);
|
self.surface_config.width = width.max(1);
|
||||||
self.surface_config.height = height.max(1);
|
self.surface_config.height = height.max(1);
|
||||||
self.surface.configure(&self.device, &self.surface_config);
|
self.surface.configure(&self.device, &self.surface_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw(&mut self) {
|
pub fn draw(&mut self) {
|
||||||
let surface_texture = self
|
let surface_texture = self
|
||||||
.surface
|
.surface
|
||||||
.get_current_texture()
|
.get_current_texture()
|
||||||
.expect("Failed to get surface texture");
|
.expect("Failed to get surface texture");
|
||||||
let view = surface_texture.texture.create_view(&wgpu::TextureViewDescriptor::default());
|
let view = surface_texture
|
||||||
let mut encoder = self.device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
|
.texture
|
||||||
|
.create_view(&wgpu::TextureViewDescriptor::default());
|
||||||
|
let mut encoder = self
|
||||||
|
.device
|
||||||
|
.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
|
||||||
{
|
{
|
||||||
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||||
label: None,
|
label: None,
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
use std::sync::Arc;
|
pub mod ctx;
|
||||||
|
|
||||||
use ctx::WgpuCtx;
|
use ctx::WgpuCtx;
|
||||||
use log2::{debug, error, trace};
|
|
||||||
|
use log::{debug, trace};
|
||||||
|
use std::sync::Arc;
|
||||||
use winit::application::ApplicationHandler;
|
use winit::application::ApplicationHandler;
|
||||||
use winit::event::WindowEvent;
|
use winit::event::WindowEvent;
|
||||||
use winit::event_loop::ActiveEventLoop;
|
use winit::event_loop::ActiveEventLoop;
|
||||||
use winit::window::{self, Window, WindowId};
|
use winit::window::{Window, WindowId};
|
||||||
pub mod ctx;
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct App<'window> {
|
pub struct App<'window> {
|
||||||
window: Option<Arc<Window>>,
|
window: Option<Arc<Window>>,
|
||||||
|
@ -17,9 +18,11 @@ impl ApplicationHandler for App<'_> {
|
||||||
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
|
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
|
||||||
if self.window.is_none() {
|
if self.window.is_none() {
|
||||||
let win_attr = Window::default_attributes().with_title("Zenyx");
|
let win_attr = Window::default_attributes().with_title("Zenyx");
|
||||||
let window = Arc::new(event_loop
|
let window = Arc::new(
|
||||||
|
event_loop
|
||||||
.create_window(win_attr)
|
.create_window(win_attr)
|
||||||
.expect("create window err."));
|
.expect("create window err."),
|
||||||
|
);
|
||||||
self.window = Some(window.clone());
|
self.window = Some(window.clone());
|
||||||
let wgpu_ctx = WgpuCtx::new_blocking(window.clone()).unwrap();
|
let wgpu_ctx = WgpuCtx::new_blocking(window.clone()).unwrap();
|
||||||
self.ctx = Some(wgpu_ctx)
|
self.ctx = Some(wgpu_ctx)
|
||||||
|
@ -44,11 +47,11 @@ impl ApplicationHandler for App<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WindowEvent::Resized(size) => {
|
WindowEvent::Resized(size) => {
|
||||||
if let (Some(wgpu_ctx),Some(window)) = (&mut self.ctx, &self.window) {
|
if let (Some(wgpu_ctx), Some(window)) = (&mut self.ctx, &self.window) {
|
||||||
wgpu_ctx.resize(size.into());
|
wgpu_ctx.resize(size.into());
|
||||||
window.request_redraw();
|
window.request_redraw();
|
||||||
|
|
||||||
let size_str: String = size.height.to_string() + "x" + &size.width.to_string();
|
let size_str: String = size.height.to_string() + "x" + &size.width.to_string();
|
||||||
//self.window.as_ref().unwrap().set_title(&format!("you reszed the window to {size_str}"));
|
|
||||||
debug!("Window resized to {:?}", size_str);
|
debug!("Window resized to {:?}", size_str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +1,28 @@
|
||||||
use super::COMMAND_LIST;
|
use super::COMMAND_LIST;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use log2::{debug, info};
|
use log::debug;
|
||||||
|
|
||||||
pub(crate) fn say_hello() {
|
pub(crate) fn say_hello() {
|
||||||
println!("Hello, World!");
|
println!("Hello, World!");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn echo(args: Vec<String>) {
|
pub(crate) fn echo(args: Vec<String>) {
|
||||||
debug!("{}", args.join(" "));
|
|
||||||
println!("{}", args.join(" "))
|
println!("{}", args.join(" "))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn exit() {
|
pub(crate) fn exit() {
|
||||||
debug!("Exiting...");
|
println!("Exiting...");
|
||||||
std::process::exit(0)
|
std::process::exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn clear() {
|
pub(crate) fn clear() {
|
||||||
info!("Clearing screen..., running command");
|
println!("Clearing screen..., running command");
|
||||||
let _result = if cfg!(target_os = "windows") {
|
let _result = if cfg!(target_os = "windows") {
|
||||||
debug!("target_os is windows");
|
debug!("target_os is windows");
|
||||||
Command::new("cmd").args(["/c", "cls"]).spawn()
|
Command::new("cmd").args(["/c", "cls"]).spawn()
|
||||||
} else {
|
} else {
|
||||||
debug!("target_os is unix");
|
debug!("target_os is unix");
|
||||||
// "clear" or "tput reset"
|
Command::new("clear").spawn()
|
||||||
Command::new("tput").arg("reset").spawn()
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ pub mod commands;
|
||||||
pub mod repl;
|
pub mod repl;
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use log2::{debug, error, info};
|
use log::{debug, info};
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use std::{borrow::Borrow, collections::HashMap, sync::Arc};
|
use std::{borrow::Borrow, collections::HashMap, sync::Arc};
|
||||||
|
|
||||||
|
@ -26,11 +26,10 @@ pub struct Command {
|
||||||
|
|
||||||
impl Command {
|
impl Command {
|
||||||
pub fn execute(&self, args: Option<Vec<String>>) {
|
pub fn execute(&self, args: Option<Vec<String>>) {
|
||||||
//debug!("Executing command: {}", self.name);
|
|
||||||
match &self.function {
|
match &self.function {
|
||||||
Callable::Simple(f) => {
|
Callable::Simple(f) => {
|
||||||
if let Some(args) = args {
|
if let Some(args) = args {
|
||||||
error!(
|
eprintln!(
|
||||||
"Command expected 0 arguments but {} args were given. Ignoring..",
|
"Command expected 0 arguments but {} args were given. Ignoring..",
|
||||||
args.len()
|
args.len()
|
||||||
);
|
);
|
||||||
|
@ -39,7 +38,7 @@ impl Command {
|
||||||
}
|
}
|
||||||
Callable::WithArgs(f) => match args {
|
Callable::WithArgs(f) => match args {
|
||||||
Some(args) => f(args),
|
Some(args) => f(args),
|
||||||
None => error!("Command expected arguments but received 0"),
|
None => eprintln!("Command expected arguments but received 0"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,7 +75,7 @@ impl CommandList {
|
||||||
func: Callable,
|
func: Callable,
|
||||||
arg_count: Option<u8>,
|
arg_count: Option<u8>,
|
||||||
) {
|
) {
|
||||||
debug!("Adding command: {}", name);
|
info!("Adding command: {}", name);
|
||||||
let mut commands = self.commands.write();
|
let mut commands = self.commands.write();
|
||||||
|
|
||||||
commands.push(Command {
|
commands.push(Command {
|
||||||
|
@ -88,24 +87,22 @@ impl CommandList {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_alias(&self, name: String, alias: String) {
|
fn add_alias(&self, name: String, alias: String) {
|
||||||
//println!("Input alias: {}", alias);
|
|
||||||
if self.aliases.read().contains_key(&alias) {
|
if self.aliases.read().contains_key(&alias) {
|
||||||
error!("Alias: '{}' already exists", alias);
|
eprintln!("Alias: '{}' already exists", alias);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let mut commands = self.commands.write();
|
let mut commands = self.commands.write();
|
||||||
if let Some(command) = commands.iter_mut().find(|cmd| cmd.name == name) {
|
if let Some(command) = commands.iter_mut().find(|cmd| cmd.name == name) {
|
||||||
info!("Adding alias: {} for cmd: {}", alias, command.name);
|
debug!("Adding alias: {} for cmd: {}", alias, command.name);
|
||||||
self.aliases
|
self.aliases
|
||||||
.write()
|
.write()
|
||||||
.insert(alias.to_string(), name.to_string());
|
.insert(alias.to_string(), name.to_string());
|
||||||
} else {
|
} else {
|
||||||
error!("Command: '{}' was not found", name);
|
eprintln!("Command: '{}' was not found", name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn execute_command(&self, mut name: String, args: Option<Vec<String>>) {
|
fn execute_command(&self, mut name: String, args: Option<Vec<String>>) {
|
||||||
//info!("received input command: {}", name);
|
|
||||||
let commands = self.commands.borrow();
|
let commands = self.commands.borrow();
|
||||||
if self.aliases.read().contains_key(&name) {
|
if self.aliases.read().contains_key(&name) {
|
||||||
name = self
|
name = self
|
||||||
|
@ -116,7 +113,7 @@ impl CommandList {
|
||||||
.1
|
.1
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
debug!("changed to {}", name);
|
debug!("changed to {}", &name);
|
||||||
}
|
}
|
||||||
if let Some(command) = commands.read().iter().find(|cmd| cmd.name == name) {
|
if let Some(command) = commands.read().iter().find(|cmd| cmd.name == name) {
|
||||||
match (command.arg_count, args.as_ref()) {
|
match (command.arg_count, args.as_ref()) {
|
||||||
|
|
|
@ -2,7 +2,6 @@ use super::{commands, Callable, COMMAND_LIST};
|
||||||
use chrono::Local;
|
use chrono::Local;
|
||||||
use reedline::{Prompt, Reedline, Signal};
|
use reedline::{Prompt, Reedline, Signal};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::{borrow::Borrow, collections::HashMap, sync::Arc};
|
|
||||||
|
|
||||||
fn register_commands() {
|
fn register_commands() {
|
||||||
COMMAND_LIST.add_command(
|
COMMAND_LIST.add_command(
|
||||||
|
@ -42,7 +41,7 @@ fn register_commands() {
|
||||||
|
|
||||||
// EXAMPLE
|
// EXAMPLE
|
||||||
// Adding aliases for commands
|
// Adding aliases for commands
|
||||||
COMMAND_LIST.add_alias("cls".to_string(), "clear".to_string()); // Likely unintended; consider removing or renaming.
|
COMMAND_LIST.add_alias("clear".to_string(), "cls".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ZPrompt {
|
struct ZPrompt {
|
||||||
|
|
|
@ -1,46 +1,48 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use colored::Colorize;
|
use clap::Parser;
|
||||||
use log2::info;
|
use log::{info, warn, LevelFilter};
|
||||||
|
|
||||||
pub mod core;
|
pub mod core;
|
||||||
|
pub mod utils;
|
||||||
|
|
||||||
pub fn print_splash() {
|
use utils::{logger::LOGGER, splash::print_splash};
|
||||||
println!(
|
|
||||||
r#"
|
|
||||||
&&&&&&&&&&&
|
|
||||||
&&&&&&&&&&&&&&&&&
|
|
||||||
&&&&&&&&&&&&&&&&&&&&&
|
|
||||||
&& &&&&&&&&&
|
|
||||||
&& &&&&&&&&&
|
|
||||||
&&&&&&&&&&&& &&&&&&&&&&&
|
|
||||||
&&&&&&&&&&&&& &&&&&&&&&&&&
|
|
||||||
&&&&&&&&&&&&& &&&&&&&&&&&&&
|
|
||||||
&&&&&&&&&&&& &&&&&&&&&&&&&
|
|
||||||
&&&&&&&&&&& &&&&&&&&&&&&
|
|
||||||
&&&&&&&&& &&
|
|
||||||
&&&&&&&&& &&
|
|
||||||
&&&&&&&&&&&&&&&&&&&&&
|
|
||||||
&&&&&&&&&&&&&&&&&
|
|
||||||
&&&&&&&&&&&
|
|
||||||
|
|
||||||
Version: {}
|
#[derive(Parser)]
|
||||||
"#,
|
struct Cli {
|
||||||
env!("CARGO_PKG_VERSION").yellow().italic().underline()
|
#[arg(long, short, help = "Enable logging output")]
|
||||||
);
|
log: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
let _log2 = log2::open("z.log").tee(true).level("debug").start();
|
let cli = Cli::parse();
|
||||||
info!("Initalizing Engine");
|
|
||||||
|
log::set_logger(&*LOGGER).unwrap();
|
||||||
|
log::set_max_level(LevelFilter::Debug);
|
||||||
|
|
||||||
|
print_splash();
|
||||||
|
|
||||||
|
if cli.log {
|
||||||
|
info!("Initializing Engine with logging to stdout enabled");
|
||||||
|
warn!("REPL cannot be used with logging enabled due to ReedLine not supporting writing to stdout");
|
||||||
|
|
||||||
|
core::init_renderer()?;
|
||||||
|
} else {
|
||||||
|
LOGGER.write_to_stdout();
|
||||||
|
info!("Initializing Engine with logging to stdout disabled");
|
||||||
|
warn!("REPL cannot be used with logging enabled due to ReedLine not supporting writing to stdout");
|
||||||
|
info!("Writing all logs to file z.log");
|
||||||
|
|
||||||
|
LOGGER.write_to_file("z.log");
|
||||||
|
info!("Logging back to file z.log");
|
||||||
|
|
||||||
let shell_thread = tokio::task::spawn(async {
|
let shell_thread = tokio::task::spawn(async {
|
||||||
info!("Shell thread started");
|
|
||||||
core::repl::repl::handle_repl().await;
|
core::repl::repl::handle_repl().await;
|
||||||
});
|
});
|
||||||
|
|
||||||
print_splash();
|
|
||||||
info!("Engine Initalized");
|
|
||||||
core::init_renderer()?;
|
core::init_renderer()?;
|
||||||
shell_thread.await?;
|
shell_thread.await?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
72
engine/src/utils/logger.rs
Normal file
72
engine/src/utils/logger.rs
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
use colored::Colorize;
|
||||||
|
use log::{Level, Log, Metadata, Record};
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
|
use std::fs::OpenOptions;
|
||||||
|
use std::io::{self, Write};
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
pub static LOGGER: Lazy<DynamicLogger> = Lazy::new(DynamicLogger::new);
|
||||||
|
|
||||||
|
// A logger that dynamically switches between file and stdout
|
||||||
|
pub struct DynamicLogger {
|
||||||
|
pub writer: Arc<Mutex<Box<dyn Write + Send>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DynamicLogger {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
writer: Arc::new(Mutex::new(Box::new(io::stdout()))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write_to_file(&self, file_path: &str) {
|
||||||
|
let file = OpenOptions::new()
|
||||||
|
.create(true)
|
||||||
|
.write(true)
|
||||||
|
.append(true)
|
||||||
|
.open(file_path)
|
||||||
|
.expect("Failed to open log file");
|
||||||
|
|
||||||
|
*self.writer.lock().unwrap() = Box::new(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write_to_stdout(&self) {
|
||||||
|
*self.writer.lock().unwrap() = Box::new(io::stdout());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn colorize_level(level: Level) -> colored::ColoredString {
|
||||||
|
match level {
|
||||||
|
Level::Error => "ERROR".red(),
|
||||||
|
Level::Warn => "WARN".yellow(),
|
||||||
|
Level::Info => "INFO".green(),
|
||||||
|
Level::Debug => "DEBUG".blue(),
|
||||||
|
Level::Trace => "TRACE".cyan(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Log for DynamicLogger {
|
||||||
|
fn enabled(&self, metadata: &Metadata) -> bool {
|
||||||
|
metadata.level() <= Level::Debug
|
||||||
|
}
|
||||||
|
|
||||||
|
fn log(&self, record: &Record) {
|
||||||
|
if self.enabled(record.metadata()) {
|
||||||
|
let mut writer = self.writer.lock().unwrap();
|
||||||
|
let level = Self::colorize_level(record.level()); // Apply coloring
|
||||||
|
writeln!(
|
||||||
|
writer,
|
||||||
|
"{} [{}] - {}",
|
||||||
|
chrono::Local::now().format("%Y-%m-%d %H:%M:%S"),
|
||||||
|
level,
|
||||||
|
record.args()
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn flush(&self) {
|
||||||
|
let mut writer = self.writer.lock().unwrap();
|
||||||
|
writer.flush().unwrap();
|
||||||
|
}
|
||||||
|
}
|
2
engine/src/utils/mod.rs
Normal file
2
engine/src/utils/mod.rs
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
pub mod logger;
|
||||||
|
pub mod splash;
|
30
engine/src/utils/splash.rs
Normal file
30
engine/src/utils/splash.rs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
use colored::Colorize;
|
||||||
|
use log::info;
|
||||||
|
|
||||||
|
pub fn print_splash() {
|
||||||
|
info!(
|
||||||
|
"{}",
|
||||||
|
format!(
|
||||||
|
r#"
|
||||||
|
&&&&&&&&&&&
|
||||||
|
&&&&&&&&&&&&&&&&&
|
||||||
|
&&&&&&&&&&&&&&&&&&&&&
|
||||||
|
&& &&&&&&&&&
|
||||||
|
&&&&&&&&&&&& &&&&&&&&&&&
|
||||||
|
&&&&&&&&&&&&& &&&&&&&&&&&&
|
||||||
|
&&&&&&&&&&&&& &&&&&&&&&&&&&
|
||||||
|
&&&&&&&&&&&& &&&&&&&&&&&&&
|
||||||
|
&&&&&&&&&&& &&&&&&&&&&&&
|
||||||
|
&&&&&&&&& &&
|
||||||
|
&&&&&&&&& &&
|
||||||
|
&&&&&&&&&&&&&&&&&&&&&
|
||||||
|
&&&&&&&&&&&&&&&&&
|
||||||
|
&&&&&&&&&&&
|
||||||
|
|
||||||
|
Version: {}
|
||||||
|
"#,
|
||||||
|
env!("CARGO_PKG_VERSION").color("yellow")
|
||||||
|
)
|
||||||
|
.bright_black()
|
||||||
|
);
|
||||||
|
}
|
|
@ -1 +1,4 @@
|
||||||
pub fn build_editor() {}
|
pub fn build_editor() {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
use std::process::Stdio;
|
use std::process::Stdio;
|
||||||
|
|
||||||
|
|
||||||
pub fn build_engine() {
|
pub fn build_engine() {
|
||||||
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_core() {
|
pub fn build_core() {
|
||||||
let threads = format!("-j{}",std::thread::available_parallelism().unwrap().get());
|
let threads = format!("-j{}", std::thread::available_parallelism().unwrap().get());
|
||||||
|
|
||||||
let mut run = std::process::Command::new("cargo")
|
let mut run = std::process::Command::new("cargo")
|
||||||
.arg("run")
|
.arg("run")
|
||||||
|
|
||||||
.arg(threads)
|
.arg(threads)
|
||||||
.arg("--bin")
|
.arg("--bin")
|
||||||
.arg("zenyx")
|
.arg("zenyx")
|
||||||
|
@ -18,5 +17,7 @@ pub fn build_core() {
|
||||||
.stderr(Stdio::inherit())
|
.stderr(Stdio::inherit())
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
run.wait().unwrap();
|
run.wait().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
|
|
||||||
use clap::{CommandFactory, Parser, Subcommand, ValueEnum};
|
use clap::{CommandFactory, Parser, Subcommand, ValueEnum};
|
||||||
pub mod engine;
|
|
||||||
pub mod editor;
|
pub mod editor;
|
||||||
|
pub mod engine;
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(version, about, long_about = None,disable_version_flag = true,disable_help_flag = true)]
|
#[command(version, about, long_about = None,disable_version_flag = true,disable_help_flag = true)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
#[arg(short,long)]
|
#[arg(short, long)]
|
||||||
release: bool,
|
release: bool,
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
command: Option<Commands>,
|
command: Option<Commands>,
|
||||||
|
@ -16,12 +15,12 @@ struct Cli {
|
||||||
enum Commands {
|
enum Commands {
|
||||||
Run {
|
Run {
|
||||||
#[arg()]
|
#[arg()]
|
||||||
task: Task
|
task: Task,
|
||||||
},
|
},
|
||||||
Config,
|
Config,
|
||||||
|
|
||||||
}
|
}
|
||||||
#[derive(Clone,ValueEnum)]
|
|
||||||
|
#[derive(Clone, ValueEnum)]
|
||||||
enum Task {
|
enum Task {
|
||||||
Engine, // Builds both editor and core
|
Engine, // Builds both editor and core
|
||||||
Editor, // Builds editor only
|
Editor, // Builds editor only
|
||||||
|
@ -29,42 +28,35 @@ enum Task {
|
||||||
Help,
|
Help,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if cli.release {
|
if cli.release {
|
||||||
println!("Running in release mode")
|
println!("Running in release mode")
|
||||||
}
|
}
|
||||||
|
|
||||||
match &cli.command {
|
match &cli.command {
|
||||||
|
|
||||||
None => {
|
None => {
|
||||||
Cli::command().print_help().map_err(|e| {
|
Cli::command()
|
||||||
|
.print_help()
|
||||||
|
.map_err(|e| {
|
||||||
println!("Could not run Xtask: {e}");
|
println!("Could not run Xtask: {e}");
|
||||||
|
})
|
||||||
}).unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
Some(Commands::Run { task }) => {
|
Some(Commands::Run { task }) => match task {
|
||||||
match task {
|
|
||||||
Task::Engine => engine::build_engine(),
|
Task::Engine => engine::build_engine(),
|
||||||
Task::Editor => todo!("Editor is not being actively worked on"),
|
Task::Editor => todo!("Editor is not being actively worked on"),
|
||||||
Task::Core => {
|
Task::Core => {
|
||||||
engine::build_core();
|
engine::build_core();
|
||||||
},
|
}
|
||||||
Task::Help => {
|
Task::Help => {
|
||||||
println!("The following options are avalible to run");
|
println!("The following options are avalible to run");
|
||||||
todo!()
|
todo!()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
|
||||||
}
|
|
||||||
Some(Commands::Config) => {
|
Some(Commands::Config) => {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue