Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove etcetera dependency #132

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/pipes-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version = "1.6.2"

[dependencies]
anyhow = "1.0.70"
etcetera = "0.8.0"
home = "0.5.5"
mimalloc = { version = "0.1.36", default-features = false }
model = { path = "../model" }
rng = { path = "../rng" }
Expand Down
26 changes: 16 additions & 10 deletions crates/pipes-rs/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use anyhow::Context;
use etcetera::app_strategy::{AppStrategy, AppStrategyArgs, Xdg};
use model::pipe::{ColorMode, Kind, KindSet, Palette};
use serde::{Deserialize, Serialize};
use std::fs;
use std::path::PathBuf;
use std::time::Duration;
use std::{env, fs};

#[derive(Serialize, Deserialize, Default)]
pub struct Config {
Expand Down Expand Up @@ -40,14 +39,21 @@ impl Config {
}

fn path() -> anyhow::Result<PathBuf> {
let path = Xdg::new(AppStrategyArgs {
top_level_domain: "io.github".to_string(),
author: "lhvy".to_string(),
app_name: "pipes-rs".to_string(),
})?
.in_config_dir("config.toml");

Ok(path)
let config_dir = 'config_dir: {
if let Ok(d) = env::var("XDG_CONFIG_HOME") {
let d = PathBuf::from(d);
if d.is_absolute() {
break 'config_dir d;
}
}

match home::home_dir() {
Some(d) => d.join(".config/"),
None => anyhow::bail!("could not determine home directory"),
}
};

Ok(config_dir.join("pipes-rs/config.toml"))
}

fn read_from_disk(path: PathBuf) -> anyhow::Result<Self> {
Expand Down