Config
This commit is contained in:
Generated
+32
@@ -3888,8 +3888,10 @@ dependencies = [
|
||||
"pulse-ui",
|
||||
"pulse-wire",
|
||||
"rand 0.8.7",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
"toml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4729,6 +4731,15 @@ dependencies = [
|
||||
"zmij",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_spanned"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_urlencoded"
|
||||
version = "0.7.1"
|
||||
@@ -5240,6 +5251,21 @@ dependencies = [
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "1.1.3+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53c96ecdfa941c8fc4fcaed14f99ada8ebed502eef533015095a07e3301d4c3c"
|
||||
dependencies = [
|
||||
"indexmap 2.14.0",
|
||||
"serde_core",
|
||||
"serde_spanned",
|
||||
"toml_datetime",
|
||||
"toml_parser",
|
||||
"toml_writer",
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "1.1.1+spec-1.1.0"
|
||||
@@ -5270,6 +5296,12 @@ dependencies = [
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_writer"
|
||||
version = "1.1.2+spec-1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7d56353a2a665ad0f41a421187180aab746c8c325620617ad883a99a1cbe66d2"
|
||||
|
||||
[[package]]
|
||||
name = "tonic"
|
||||
version = "0.14.6"
|
||||
|
||||
@@ -20,6 +20,8 @@ crossterm = { workspace = true }
|
||||
hypersdk = "0.2.14"
|
||||
serde_json = "1"
|
||||
rand = "0.8.7"
|
||||
toml = "1.1.3"
|
||||
serde = { version = "1.0.229", features = ["serde_derive"] }
|
||||
|
||||
[workspace]
|
||||
members = ["pulse-macros", "pulse-ui", "pulse-wire"]
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub fn home_dir() -> tokio::io::Result<PathBuf> {
|
||||
std::env::home_dir().ok_or_else(|| {
|
||||
tokio::io::Error::new(std::io::ErrorKind::NotFound, "Unable to get home directory")
|
||||
})
|
||||
}
|
||||
|
||||
pub fn pulse_directory() -> tokio::io::Result<PathBuf> {
|
||||
Ok(home_dir()?.join(".config/pulse-trader"))
|
||||
}
|
||||
|
||||
pub fn pulse_config_directory() -> tokio::io::Result<PathBuf> {
|
||||
Ok(home_dir()?.join(".config/pulse-trader/config.toml"))
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, serde::Serialize, serde::Deserialize)]
|
||||
pub struct WatchList {
|
||||
symbols: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, serde::Serialize, serde::Deserialize)]
|
||||
pub struct Config {
|
||||
watchlist: WatchList,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub async fn new() -> tokio::io::Result<Self> {
|
||||
let path = pulse_config_directory()?;
|
||||
|
||||
if !path.exists() {
|
||||
let default = Self::default();
|
||||
|
||||
tokio::fs::create_dir_all(path.parent().unwrap()).await?;
|
||||
tokio::fs::write(&path, default.to_string()?).await?;
|
||||
|
||||
return Ok(default);
|
||||
}
|
||||
|
||||
let output = tokio::fs::read_to_string(path).await?;
|
||||
|
||||
Self::from_str(&output)
|
||||
}
|
||||
|
||||
pub fn from_str(s: &str) -> tokio::io::Result<Self> {
|
||||
toml::from_str(s)
|
||||
.map_err(|v| tokio::io::Error::new(std::io::ErrorKind::InvalidInput, v.to_string()))
|
||||
}
|
||||
|
||||
pub fn to_string(&self) -> tokio::io::Result<String> {
|
||||
toml::to_string(self)
|
||||
.map_err(|v| tokio::io::Error::new(std::io::ErrorKind::Other, v.to_string()))
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod config;
|
||||
pub mod engine;
|
||||
pub mod fetch;
|
||||
pub mod terminal;
|
||||
|
||||
Reference in New Issue
Block a user