added opening files

This commit is contained in:
WanderingPenwing 2024-03-27 09:41:27 +01:00
parent 358fd4c983
commit 787cf5cd34
2 changed files with 17 additions and 2 deletions

View file

@ -66,7 +66,7 @@ impl Calcifer {
}
}
pub fn from_app_state(app_state: core::AppState) -> Self {
pub fn from_app_state(app_state: core::AppState, file_to_open: Option<PathBuf>) -> Self {
let mut new = Self {
theme: DEFAULT_THEMES[min(app_state.theme, DEFAULT_THEMES.len() - 1)],
tabs: Vec::new(),
@ -86,6 +86,10 @@ impl Calcifer {
new.open_file(Some(&path));
}
}
if let Some(path) = file_to_open {
new.open_file(Some(&path));
}
if new.tabs == vec![] {
new.open_file(None);

View file

@ -5,6 +5,7 @@ use egui::{
};
use homedir::get_my_home;
use std::{ops::Range, path::PathBuf, sync::Arc, thread, time};
use std::env;
mod core;
mod editor;
@ -50,11 +51,21 @@ fn main() -> Result<(), eframe::Error> {
} else {
core::AppState::default()
};
let args: Vec<String> = env::args().collect();
let file_to_open = if args.len() > 1 {
println!("Opening file: {}", args[1].clone());
let mut path = env::current_dir().unwrap_or_default();
path.push(args[1].clone());
Some(path)
} else {
None
};
eframe::run_native(
&format!("Calcifer{}", TITLE),
options,
Box::new(move |_cc| Box::from(Calcifer::from_app_state(app_state))),
Box::new(move |_cc| Box::from(Calcifer::from_app_state(app_state, file_to_open))),
)
}