Automatically find the config in XDG_CONFIG or whatever
Getty Ritter
5 years ago
141 | 141 |
"pangocairo 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
142 | 142 |
"toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
143 | 143 |
"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)",
|
144 | 145 |
]
|
145 | 146 |
|
146 | 147 |
[[package]]
|
|
327 | 328 |
"libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)",
|
328 | 329 |
"pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
329 | 330 |
]
|
| 331 |
|
| 332 |
[[package]]
|
| 333 |
name = "xdg"
|
| 334 |
version = "2.2.0"
|
| 335 |
source = "registry+https://github.com/rust-lang/crates.io-index"
|
330 | 336 |
|
331 | 337 |
[metadata]
|
332 | 338 |
"checksum autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a6d640bee2da49f60a4068a7fae53acde8982514ab7bae8b8cea9e88cbcfd799"
|
|
366 | 372 |
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
367 | 373 |
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
368 | 374 |
"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"
|
21 | 21 |
_ => (),
|
22 | 22 |
}
|
23 | 23 |
}
|
| 24 |
conf.right.reverse();
|
24 | 25 |
Ok(conf)
|
25 | 26 |
}
|
26 | 27 |
|
|
28 | 29 |
let body = std::fs::read_to_string(path)?;
|
29 | 30 |
let val = body.parse::<toml::Value>()?;
|
30 | 31 |
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`"))
|
31 | 39 |
}
|
32 | 40 |
|
33 | 41 |
pub fn draw(&self, ctx: &cairo::Context, layout: &pango::Layout, stdin: &str, size: w::Size) -> Result<(), failure::Error>{
|
13 | 13 |
|
14 | 14 |
fn main() -> Result<(), failure::Error> {
|
15 | 15 |
// set up the display and the window
|
16 | |
let config = config::Config::from_file("sample.toml")?;
|
| 16 |
let config = config::Config::find_config()?;
|
17 | 17 |
let mut d = Display::create()?;
|
18 | 18 |
let mut ws = Vec::new();
|
19 | 19 |
for (x_off, wd) in d.get_widths()? {
|