Skip to content

Commit

Permalink
ICB_PATH env variable can now be used to set icy board home directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrueger committed Feb 2, 2025
1 parent 99bad1c commit fa3ffb0
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 34 deletions.
13 changes: 3 additions & 10 deletions crates/icbsetup/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,11 @@ fn main() -> Result<()> {
}
_ => {}
}
let mut file = arguments.file.clone().unwrap_or(PathBuf::from("."));
if file.is_dir() {
file = file.join("icyboard.toml");
}

let file = file.with_extension("toml");
if !file.exists() {
let mut map: HashMap<String, String> = HashMap::new();
map.insert("name".to_string(), file.display().to_string());
let Some(file) = icy_board_engine::lookup_icyboard_file(&arguments.file) else {
let map = HashMap::new();
print_error(get_text_args("file_not_found", map));
exit(1);
}
};

match IcyBoard::load(&file) {
Ok(icy_board) => {
Expand Down
17 changes: 5 additions & 12 deletions crates/icbsysmgr/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ struct Cli {
#[argh(switch, short = 'f')]
full_screen: bool,

#[argh(option)]
/// file[.toml] to edit/create
#[argh(positional)]
/// path/file name of the icyboard.toml configuration file
file: Option<PathBuf>,
}

Expand Down Expand Up @@ -55,18 +55,11 @@ fn main() -> Result<()> {

let arguments: Cli = argh::from_env();

let mut file = arguments.file.clone().unwrap_or(PathBuf::from("."));
if file.is_dir() {
file = file.join("icyboard.toml");
}

let file = file.with_extension("toml");
if !file.exists() {
let mut map: HashMap<String, String> = HashMap::new();
map.insert("name".to_string(), file.display().to_string());
let Some(file) = icy_board_engine::lookup_icyboard_file(&arguments.file) else {
let map = HashMap::new();
print_error(get_text_args("file_not_found", map));
exit(1);
}
};

match IcyBoard::load(&file) {
Ok(icy_board) => {
Expand Down
21 changes: 11 additions & 10 deletions crates/icy_board/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::{
collections::HashMap,
fmt::Display,
io::stdout,
path::{Path, PathBuf},
process::{self, Command},
path::PathBuf,
process::{self, exit, Command},
sync::Arc,
};

Expand All @@ -21,6 +22,7 @@ use icy_board_engine::{
Res,
};

use icy_board_tui::get_text_args;
use node_monitoring_screen::NodeMonitoringScreenMessage;
use ratatui::{backend::Backend, Terminal};
use semver::Version;
Expand Down Expand Up @@ -69,19 +71,18 @@ lazy_static::lazy_static! {
#[tokio::main]
async fn main() -> Res<()> {
let arguments: Cli = argh::from_env();
let file = arguments.file.clone().unwrap_or(PathBuf::from("."));
start_icy_board(&arguments, &file).await?;
let Some(file) = icy_board_engine::lookup_icyboard_file(&arguments.file) else {
let map = HashMap::new();
print_error(get_text_args("file_not_found", map));
exit(1);
};
start_icy_board(&arguments, file).await?;
Ok(())
}

async fn start_icy_board<P: AsRef<Path>>(arguments: &Cli, config_file: &P) -> Res<()> {
async fn start_icy_board(arguments: &Cli, file: PathBuf) -> Res<()> {
let stuffed = arguments.key.clone().unwrap_or_default();

let mut file = config_file.as_ref().to_path_buf();
if file.is_dir() {
file = file.join("icyboard.toml");
}

let config_file = file.with_extension("toml");

let log_file = config_file.with_extension("log");
Expand Down
1 change: 0 additions & 1 deletion crates/icy_board_engine/src/icy_board/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,6 @@ impl IcyBoardState {
let mut user_bytes = Vec::new();
let mut sysop_bytes = Vec::new();
for c in data {
let y = self.user_screen.caret.get_position().y;
if target != TerminalTarget::Sysop || self.session.is_sysop || self.session.current_user.is_none() {
let _ = self.user_screen.print_char(*c);
if let Some(&cp437) = UNICODE_TO_CP437.get(&c) {
Expand Down
24 changes: 23 additions & 1 deletion crates/icy_board_engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
clippy::module_name_repetitions
)]

use std::error::Error;
use std::{env, error::Error, path::PathBuf};

use semver::Version;

Expand All @@ -34,3 +34,25 @@ pub type Res<T> = Result<T, Box<dyn Error + Send + Sync>>;
lazy_static::lazy_static! {
static ref VERSION: Version = Version::parse(env!("CARGO_PKG_VERSION")).unwrap();
}

pub fn lookup_icyboard_file(file: &Option<PathBuf>) -> Option<PathBuf> {
let mut file = file.clone().unwrap_or(PathBuf::from("."));
if file.is_dir() {
file = file.join("icyboard.toml");
}

let file = file.with_extension("toml");
if file.exists() {
return Some(file);
}

if let Ok(var) = env::var("ICB_PATH") {
let mut path = PathBuf::from(var);
path.push("icyboard.toml");
if path.exists() {
return Some(path);
}
}

None
}

0 comments on commit fa3ffb0

Please sign in to comment.