on master help sign in
Default log file to cache
commitd664d1dec066eb1bd237af61c22b62d93b48646b authorIvan Tham <pickfire@riseup.net> dateThu 3 Jun 2021, 00:19 (5 years ago) parent7e86032
2 files changed+23−9
helix-core/src/lib.rs+10−1 helix-term/src/main.rs+13−8
helix-core/src/lib.rs+10−1
@@ -58,13 +58,22 @@ pub fn runtime_dir() -> std::path::PathBuf {
5858
5959pub fn config_dir() -> std::path::PathBuf {
6060 // TODO: allow env var override
61− use etcetera::base_strategy::{choose_base_strategy, BaseStrategy};
6261 let strategy = choose_base_strategy().expect("Unable to find the config directory!");
6362 let mut path = strategy.config_dir();
6463 path.push("helix");
6564 path
6665}
6766
67+pub fn cache_dir() -> std::path::PathBuf {
68+ // TODO: allow env var override
69+ let strategy = choose_base_strategy().expect("Unable to find the config directory!");
70+ let mut path = strategy.cache_dir();
71+ path.push("helix");
72+ path
73+}
74+
75+use etcetera::base_strategy::{choose_base_strategy, BaseStrategy};
76+
6877pub use ropey::{Rope, RopeSlice};
6978
7079pub use tendril::StrTendril as Tendril;
helix-term/src/main.rs+13−8
@@ -8,13 +8,11 @@ mod ui;
88
99use application::Application;
1010
11−use helix_core::config_dir;
12−
1311use std::path::PathBuf;
1412
1513use anyhow::{Context, Error, Result};
1614
17−fn setup_logging(verbosity: u64) -> Result<()> {
15+fn setup_logging(logpath: PathBuf, verbosity: u64) -> Result<()> {
1816 let mut base_config = fern::Dispatch::new();
1917
2018 // Let's say we depend on something which whose "info" level messages are too
@@ -40,7 +38,7 @@ fn setup_logging(verbosity: u64) -> Result<()> {
4038 message
4139 ))
4240 })
43− .chain(fern::log_file(config_dir().join("helix.log"))?);
41+ .chain(fern::log_file(logpath)?);
4442
4543 base_config.chain(file_config).apply()?;
4644
@@ -96,6 +94,12 @@ fn parse_args(mut args: Args) -> Result<Args> {
9694
9795#[tokio::main]
9896async fn main() -> Result<()> {
97+ let cache_dir = helix_core::cache_dir();
98+ if !cache_dir.exists() {
99+ std::fs::create_dir(&cache_dir);
100+ }
101+
102+ let logpath = cache_dir.join("helix.log");
99103 let help = format!(
100104 "\
101105{} {}
@@ -111,12 +115,14 @@ ARGS:
111115FLAGS:
112116 -h, --help Prints help information
113117 -v Increases logging verbosity each use for up to 3 times
118+ (default file: {})
114119 -V, --version Prints version information
115120",
116121 env!("CARGO_PKG_NAME"),
117122 env!("CARGO_PKG_VERSION"),
118123 env!("CARGO_PKG_AUTHORS"),
119124 env!("CARGO_PKG_DESCRIPTION"),
125+ logpath.display(),
120126 );
121127
122128 let mut args: Args = Args {
@@ -139,19 +145,18 @@ FLAGS:
139145 std::process::exit(0);
140146 }
141147
142− let conf_dir = config_dir();
143−
148+ let conf_dir = helix_core::config_dir();
144149 if !conf_dir.exists() {
145150 std::fs::create_dir(&conf_dir);
146151 }
147152
148− setup_logging(args.verbosity).context("failed to initialize logging")?;
153+ setup_logging(logpath, args.verbosity).context("failed to initialize logging")?;
149154
150155 // initialize language registry
151156 use helix_core::syntax::{Loader, LOADER};
152157
153158 // load $HOME/.config/helix/languages.toml, fallback to default config
154− let config = std::fs::read(config_dir().join("languages.toml"));
159+ let config = std::fs::read(helix_core::config_dir().join("languages.toml"));
155160 let toml = config
156161 .as_deref()
157162 .unwrap_or(include_bytes!("../../languages.toml"));