Skip to content

Commit

Permalink
(master) load config relative to home
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPicklePinosaur committed Dec 31, 2022
1 parent 6c9da27 commit 628d8d7
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 13 deletions.
32 changes: 32 additions & 0 deletions Cargo.lock

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

4 changes: 0 additions & 4 deletions matsuba_common/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pub static REPEATABLE_CHARACTERS: &[char] = &[
];

pub static CONVERSION_TABLE: &[(&str, &str, &str)] = &[

// monographs
("a", "あ", "ア"),
("i", "い", "イ"),
Expand Down Expand Up @@ -81,7 +80,6 @@ pub static CONVERSION_TABLE: &[(&str, &str, &str)] = &[
("pu", "ぷ", "プ"),
("pe", "ぺ", "ペ"),
("po", "ぽ", "ポ"),

// digraphs
("kya", "きゃ", "キャ"),
("kyu", "きゅ", "キュ"),
Expand Down Expand Up @@ -116,7 +114,6 @@ pub static CONVERSION_TABLE: &[(&str, &str, &str)] = &[
("pya", "ぴゃ", "ピャ"),
("pyu", "ぴゅ", "ピュ"),
("pyo", "ぴょ", "ピョ"),

// small characters
("xa", "ぁ", "ァ"),
("xi", "ぃ", "ィ"),
Expand All @@ -130,6 +127,5 @@ pub static CONVERSION_TABLE: &[(&str, &str, &str)] = &[
("xwa", "ゎ", "ヮ"),
("xka", "ヵ", "ヵ"),
("xke", "ヶ", "ヶ"),

// (hentaigana for fun?) + extended katakana etc チェ + halfwidth?
];
2 changes: 1 addition & 1 deletion matsuba_default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ completion_bg = "#AAAAAA"
completion_fg = "#333333"

[database]
cache_dir = "/home/pinosaur/.config/matsuba"
cache_dir = "/usr/share/matsuba"
1 change: 1 addition & 0 deletions matsuba_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ pino_utils = "0.1.0"
env_logger = "0.9"
log = "0.4"
lazy_static = "1.4"
dirs = "4.0"
20 changes: 15 additions & 5 deletions matsuba_server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,22 @@ impl<'de> Visitor<'de> for KeybindingVisitor {

impl Settings {
pub fn load() -> Result<Self, ConfigError> {
let conf = Config::builder()
.add_source(File::with_name("matsuba_default.toml"))
// .add_source(File::with_name("matsuba.toml"))
.build()?;
use std::path::Path;

conf.try_deserialize()
let mut conf = Config::builder()
.add_source(File::with_name("/usr/share/matsuba/matsuba_default.toml"));

if let Some(home) = dirs::home_dir() {
let mut path = home.clone();
path.push(Path::new(".config/matsuba/matsuba.toml"));
if let Some(path) = path.to_str() {
conf = conf.add_source(File::with_name(path).required(false));
}
}

let conf_built = conf.build()?;

conf_built.try_deserialize()
}
}

Expand Down
3 changes: 2 additions & 1 deletion matsuba_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod xmlparse;
use log::info;
use tonic::transport::Server;

use crate::config::SETTINGS;
use crate::service::{MatsubaServer, MatsubaService};

#[tokio::main]
Expand All @@ -17,7 +18,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

tokio::spawn(async move {
// manually trigger lazy static call (sorta hacky)
let listen_address = &config::SETTINGS.server.listen_address;
let listen_address = &SETTINGS.server.listen_address;

info!("starting tonic server at {}", listen_address);

Expand Down
3 changes: 1 addition & 2 deletions services/matsuba.service
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ Description=matsuba - the lightweight japanese ime

[Service]
Type=simple
User=root
WorkingDirectory=
ExecStart=matsuba run
ExecStart=matsud
Restart=always

[Install]
Expand Down

0 comments on commit 628d8d7

Please sign in to comment.