gdritter repos knurling / fa25f23
Automatically find the config in XDG_CONFIG or whatever Getty Ritter 5 years ago
4 changed file(s) with 17 addition(s) and 1 deletion(s). Collapse all Expand all
141141 "pangocairo 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
142142 "toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
143143 "x11 2.18.1 (registry+https://github.com/rust-lang/crates.io-index)",
144 "xdg 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
144145 ]
145146
146147 [[package]]
327328 "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)",
328329 "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
329330 ]
331
332 [[package]]
333 name = "xdg"
334 version = "2.2.0"
335 source = "registry+https://github.com/rust-lang/crates.io-index"
330336
331337 [metadata]
332338 "checksum autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a6d640bee2da49f60a4068a7fae53acde8982514ab7bae8b8cea9e88cbcfd799"
366372 "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
367373 "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
368374 "checksum x11 2.18.1 (registry+https://github.com/rust-lang/crates.io-index)" = "39697e3123f715483d311b5826e254b6f3cfebdd83cf7ef3358f579c3d68e235"
375 "checksum xdg 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d089681aa106a86fade1b0128fb5daf07d5867a509ab036d99988dec80429a57"
1212 libc = "0.2"
1313 failure = "*"
1414 toml = "0.5"
15 xdg = "*"
1516
1617 [dependencies.cairo-sys-rs]
1718 version = "0.8"
2121 _ => (),
2222 }
2323 }
24 conf.right.reverse();
2425 Ok(conf)
2526 }
2627
2829 let body = std::fs::read_to_string(path)?;
2930 let val = body.parse::<toml::Value>()?;
3031 Config::from_toml(val)
32 }
33
34 pub fn find_config() -> Result<Config, failure::Error> {
35 if let Some(p) = xdg::BaseDirectories::new()?.find_config_file("knurling/knurling.toml") {
36 return Config::from_file(p);
37 }
38 Err(format_err!("Unable to find `knurling.toml`"))
3139 }
3240
3341 pub fn draw(&self, ctx: &cairo::Context, layout: &pango::Layout, stdin: &str, size: w::Size) -> Result<(), failure::Error>{
1313
1414 fn main() -> Result<(), failure::Error> {
1515 // set up the display and the window
16 let config = config::Config::from_file("sample.toml")?;
16 let config = config::Config::find_config()?;
1717 let mut d = Display::create()?;
1818 let mut ws = Vec::new();
1919 for (x_off, wd) in d.get_widths()? {