Add optional file logging and fix board offsets

Introduce --log CLI flag to enable logging to
war_in_tunnels.log via simplelog.
This commit is contained in:
2026-03-27 18:28:16 +01:00
parent b71130d3d6
commit a0186ea0cb
8 changed files with 74 additions and 2 deletions
+2 -2
View File
@@ -23,13 +23,13 @@ impl BoardWidget {
let rows: u16 = area_height / CELL_HIGHT;
let cols: u16 = area_width / CELL_WIDTH;
let h_max_offset: usize = if app.states.settings.map_height as u16 > rows {
let v_max_offset: usize = if app.states.settings.map_height as u16 > rows {
app.states.settings.map_height as u16 - rows
} else {
0
} as usize;
let v_max_offset: usize = if app.states.settings.map_width as u16 > cols {
let h_max_offset: usize = if app.states.settings.map_width as u16 > cols {
app.states.settings.map_width as u16 - cols
} else {
0
+7
View File
@@ -97,6 +97,13 @@ pub struct Cli {
default_value = "120"
)]
pub skill_points_limit: u16,
#[arg(
long,
help = "Enable logging to file (default: disabled)",
default_value_t = false
)]
pub log: bool,
}
pub fn get_args() -> Cli {
+1
View File
@@ -1,2 +1,3 @@
pub mod app;
pub mod cli;
pub mod logs;
+11
View File
@@ -0,0 +1,11 @@
use simplelog::{Config, LevelFilter, WriteLogger};
use std::fs::File;
pub fn init_logger() {
WriteLogger::init(
LevelFilter::Info,
Config::default(),
File::create("war_in_tunnels.log").expect("Failed to create log file"),
)
.expect("Failed to initialize logger");
}
+5
View File
@@ -7,10 +7,15 @@ use std::{
use war_in_tunnels::{
app::{App, Event, handle_input_events},
cli::{Cli, get_args},
logs::init_logger,
};
fn main() -> Result<()> {
let args: Cli = get_args();
if args.log {
init_logger();
}
let mut terminal: Terminal<CrosstermBackend<Stdout>> = ratatui::init();
let mut app: App = App::new(args);