generated from GarandPLG/rust-flake-template
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:
@@ -1,2 +1,4 @@
|
||||
/target
|
||||
/result
|
||||
|
||||
war_in_tunnels.log
|
||||
|
||||
Generated
+43
@@ -1245,6 +1245,17 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "simplelog"
|
||||
version = "0.12.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "16257adbfaef1ee58b1363bdc0664c9b8e1e30aed86049635fb5f147d065a9c0"
|
||||
dependencies = [
|
||||
"log",
|
||||
"termcolor",
|
||||
"time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "1.0.2"
|
||||
@@ -1312,6 +1323,15 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "terminfo"
|
||||
version = "0.9.0"
|
||||
@@ -1422,12 +1442,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c"
|
||||
dependencies = [
|
||||
"deranged",
|
||||
"itoa",
|
||||
"libc",
|
||||
"num-conv",
|
||||
"num_threads",
|
||||
"powerfmt",
|
||||
"serde_core",
|
||||
"time-core",
|
||||
"time-macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1436,6 +1458,16 @@ version = "0.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca"
|
||||
|
||||
[[package]]
|
||||
name = "time-macros"
|
||||
version = "0.2.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2e70e4c5a0e0a8a4823ad65dfe1a6930e4f4d756dcd9dd7939022b5e8c501215"
|
||||
dependencies = [
|
||||
"num-conv",
|
||||
"time-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.19.0"
|
||||
@@ -1521,7 +1553,9 @@ name = "war_in_tunnels"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"log",
|
||||
"ratatui",
|
||||
"simplelog",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1715,6 +1749,15 @@ version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-util"
|
||||
version = "0.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
|
||||
dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
|
||||
@@ -12,3 +12,6 @@ strip = true
|
||||
[dependencies]
|
||||
clap = { version = "4.5.53", features = ["derive"] }
|
||||
ratatui = "0.30.0"
|
||||
|
||||
log = "0.4.29"
|
||||
simplelog = "0.12.2"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,2 +1,3 @@
|
||||
pub mod app;
|
||||
pub mod cli;
|
||||
pub mod logs;
|
||||
|
||||
+11
@@ -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");
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user