on master help sign in
Default log file to cache
d664d1dIvan Tham
helix-core/src/lib.rs+10−1
@@ -58,13 +58,22 @@ pub fn runtime_dir() -> std::path::PathBuf {
58
58
59pub fn config_dir() -> std::path::PathBuf {
59pub fn config_dir() -> std::path::PathBuf {
60 // TODO: allow env var override
60 // TODO: allow env var override
61− use etcetera::base_strategy::{choose_base_strategy, BaseStrategy};
62 let strategy = choose_base_strategy().expect("Unable to find the config directory!");
61 let strategy = choose_base_strategy().expect("Unable to find the config directory!");
63 let mut path = strategy.config_dir();
62 let mut path = strategy.config_dir();
64 path.push("helix");
63 path.push("helix");
65 path
64 path
66}
65}
67
66
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+
68pub use ropey::{Rope, RopeSlice};
77pub use ropey::{Rope, RopeSlice};
69
78
70pub use tendril::StrTendril as Tendril;
79pub use tendril::StrTendril as Tendril;
helix-term/src/main.rs+13−8
@@ -8,13 +8,11 @@ mod ui;
8
8
9use application::Application;
9use application::Application;
10
10
11−use helix_core::config_dir;
12−
13use std::path::PathBuf;
11use std::path::PathBuf;
14
12
15use anyhow::{Context, Error, Result};
13use anyhow::{Context, Error, Result};
16
14
17−fn setup_logging(verbosity: u64) -> Result<()> {
15+fn setup_logging(logpath: PathBuf, verbosity: u64) -> Result<()> {
18 let mut base_config = fern::Dispatch::new();
16 let mut base_config = fern::Dispatch::new();
19
17
20 // Let's say we depend on something which whose "info" level messages are too
18 // Let's say we depend on something which whose "info" level messages are too
@@ -40,7 +38,7 @@ fn setup_logging(verbosity: u64) -> Result<()> {
40 message
38 message
41 ))
39 ))
42 })
40 })
43− .chain(fern::log_file(config_dir().join("helix.log"))?);
41+ .chain(fern::log_file(logpath)?);
44
42
45 base_config.chain(file_config).apply()?;
43 base_config.chain(file_config).apply()?;
46
44
@@ -96,6 +94,12 @@ fn parse_args(mut args: Args) -> Result<Args> {
96
94
97#[tokio::main]
95#[tokio::main]
98async fn main() -> Result<()> {
96async 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");
99 let help = format!(
103 let help = format!(
100 "\
104 "\
101{} {}
105{} {}
@@ -111,12 +115,14 @@ ARGS:
111FLAGS:
115FLAGS:
112 -h, --help Prints help information
116 -h, --help Prints help information
113 -v Increases logging verbosity each use for up to 3 times
117 -v Increases logging verbosity each use for up to 3 times
118+ (default file: {})
114 -V, --version Prints version information
119 -V, --version Prints version information
115",
120",
116 env!("CARGO_PKG_NAME"),
121 env!("CARGO_PKG_NAME"),
117 env!("CARGO_PKG_VERSION"),
122 env!("CARGO_PKG_VERSION"),
118 env!("CARGO_PKG_AUTHORS"),
123 env!("CARGO_PKG_AUTHORS"),
119 env!("CARGO_PKG_DESCRIPTION"),
124 env!("CARGO_PKG_DESCRIPTION"),
125+ logpath.display(),
120 );
126 );
121
127
122 let mut args: Args = Args {
128 let mut args: Args = Args {
@@ -139,19 +145,18 @@ FLAGS:
139 std::process::exit(0);
145 std::process::exit(0);
140 }
146 }
141
147
142− let conf_dir = config_dir();
148+ let conf_dir = helix_core::config_dir();
143−
144 if !conf_dir.exists() {
149 if !conf_dir.exists() {
145 std::fs::create_dir(&conf_dir);
150 std::fs::create_dir(&conf_dir);
146 }
151 }
147
152
148− setup_logging(args.verbosity).context("failed to initialize logging")?;
153+ setup_logging(logpath, args.verbosity).context("failed to initialize logging")?;
149
154
150 // initialize language registry
155 // initialize language registry
151 use helix_core::syntax::{Loader, LOADER};
156 use helix_core::syntax::{Loader, LOADER};
152
157
153 // load $HOME/.config/helix/languages.toml, fallback to default config
158 // 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"));
155 let toml = config
160 let toml = config
156 .as_deref()
161 .as_deref()
157 .unwrap_or(include_bytes!("../../languages.toml"));
162 .unwrap_or(include_bytes!("../../languages.toml"));