diff --git a/.config/config.kdl b/.config/config.kdl new file mode 100644 index 0000000..9991a9c --- /dev/null +++ b/.config/config.kdl @@ -0,0 +1,50 @@ +scroll_offset 4 + +keybindings { + Explorer { + "" Quit // Quit the application + "" Quit // Another way to quit + "" Quit // Yet another way to quit + "" Suspend // Suspend the application + "<2>" switch-to="TodoList" + "<3>" switch-to="Inspector" + f ToggleShowFinished + x Delete + t NewTask + g NewSubGroup + "" NewGroup + j MoveDown + k MoveUp + l MoveInto + h MoveOutOf + } + + TodoList { + "" Quit // Quit the application + "" Quit // Another way to quit + "" Quit // Yet another way to quit + "" Suspend // Suspend the application + "<1>" switch-to="Explorer" + "<3>" switch-to="Inspector" + j MoveDown + k MoveUp + } + + Inspector { + "" Quit // Quit the application + "" Quit // Another way to quit + "" Quit // Yet another way to quit + "" Suspend // Suspend the application + "<1>" switch-to="Explorer" + "<2>" switch-to="TodoList" + r RandomColor + n EditName + c EditColor + p EditPriority + u EditDue + d EditDescription + f ToggleFinishTask + t NewTask + g NewSubGroup + } +} diff --git a/Cargo.lock b/Cargo.lock index 4e4caa5..38d1335 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -415,6 +415,27 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "directories" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16f5094c54661b38d03bd7e50df373292118db60b585c08a411c6d840017fe7d" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.61.2", +] + [[package]] name = "document-features" version = "0.2.12" @@ -488,11 +509,14 @@ dependencies = [ "better-panic", "color-eyre", "crossterm", + "directories", "futures", "human-panic", + "lazy_static", "ratatui", "serde", "signal-hook 0.4.3", + "strum 0.28.0", "tokio", "tokio-util", "tracing", @@ -637,6 +661,17 @@ dependencies = [ "version_check", ] +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "getrandom" version = "0.3.4" @@ -834,6 +869,15 @@ version = "0.2.182" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112" +[[package]] +name = "libredox" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1744e39d1d6a9948f4f388969627434e31128196de472883b39f148769bfe30a" +dependencies = [ + "libc", +] + [[package]] name = "line-clipping" version = "0.3.5" @@ -1044,6 +1088,12 @@ version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + [[package]] name = "ordered-float" version = "4.6.0" @@ -1277,7 +1327,7 @@ dependencies = [ "itertools", "kasuari", "lru", - "strum", + "strum 0.27.2", "thiserror 2.0.18", "unicode-segmentation", "unicode-truncate", @@ -1329,7 +1379,7 @@ dependencies = [ "itertools", "line-clipping", "ratatui-core", - "strum", + "strum 0.27.2", "time", "unicode-segmentation", "unicode-width", @@ -1344,6 +1394,17 @@ dependencies = [ "bitflags 2.11.0", ] +[[package]] +name = "redox_users" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4e608c6638b9c18977b00b475ac1f28d14e84b27d8d42f70e0bf1e3dec127ac" +dependencies = [ + "getrandom 0.2.17", + "libredox", + "thiserror 2.0.18", +] + [[package]] name = "regex" version = "1.12.3" @@ -1584,7 +1645,16 @@ version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af23d6f6c1a224baef9d3f61e287d2761385a5b88fdab4eb4c6f11aeb54c4bcf" dependencies = [ - "strum_macros", + "strum_macros 0.27.2", +] + +[[package]] +name = "strum" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9628de9b8791db39ceda2b119bbe13134770b56c138ec1d3af810d045c04f9bd" +dependencies = [ + "strum_macros 0.28.0", ] [[package]] @@ -1599,6 +1669,18 @@ dependencies = [ "syn 2.0.117", ] +[[package]] +name = "strum_macros" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab85eea0270ee17587ed4156089e10b9e6880ee688791d45a905f5b1ca36f664" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.117", +] + [[package]] name = "syn" version = "1.0.109" diff --git a/Cargo.toml b/Cargo.toml index ae9375d..74dbe2a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,7 +51,10 @@ better-panic = "0.3.0" crossterm = { version = "0.29.0", features = ["event-stream"] } futures = "0.3.32" ratatui = "0.30.0" -serde = "1.0.228" +serde = { version = "1.0.228", features = ["derive"] } tokio = { version = "1.50.0", features = ["full"] } tokio-util = "0.7.18" signal-hook = "0.4.3" +strum = { version = "0.28.0", features = ["derive"] } +lazy_static = "1.5.0" +directories = "6.0.0" diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..2cbc554 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,71 @@ +use directories::ProjectDirs; +use lazy_static::lazy_static; +use serde::Deserialize; +use std::{env, path::PathBuf}; + +lazy_static! { + /// Filaments + pub static ref PROJECT_NAME: String = env!("CARGO_CRATE_NAME").to_uppercase().to_string(); + /// Data folder override if user has manually set FILAMENTS_DATA to a directory. + pub static ref DATA_FOLDER: Option = + env::var(format!("{}_DATA", PROJECT_NAME.clone())) + .ok() + .map(PathBuf::from); + /// Config folder override if user has manually set FILAMENTS_CONFIG to a directory. + pub static ref CONFIG_FOLDER: Option = + env::var(format!("{}_CONFIG", PROJECT_NAME.clone())) + .ok() + .map(PathBuf::from); +} + +/// The App Config and Data locations. +#[derive(Clone, Debug, Deserialize, Default)] + +pub struct AppDirs { + #[serde(default)] + pub data_dir: PathBuf, + #[serde(default)] + pub config_dir: PathBuf, +} + +/// Configuration for the App +pub struct Config { + pub app_dirs: AppDirs, // pub data_dir: PathBuf, + // pub keybindings: KeyBindings, + + // pub styles: Styles, +} + +impl Config { + pub fn new() -> Self { + todo!() + } +} + +/// Returns the path to the OS-agnostic data directory. +pub fn get_data_dir() -> PathBuf { + let directory = if let Some(s) = DATA_FOLDER.clone() { + s + } else if let Some(proj_dirs) = project_directory() { + proj_dirs.data_local_dir().to_path_buf() + } else { + PathBuf::from(".").join(".data") + }; + directory +} + +/// Returns the path to the OS-agnostic config directory. +pub fn get_config_dir() -> PathBuf { + let directory = if let Some(s) = CONFIG_FOLDER.clone() { + s + } else if let Some(proj_dirs) = project_directory() { + proj_dirs.config_local_dir().to_path_buf() + } else { + PathBuf::from(".").join(".config") + }; + directory +} + +fn project_directory() -> Option { + ProjectDirs::from("com", "suri-codes", env!("CARGO_PKG_NAME")) +} diff --git a/src/main.rs b/src/main.rs index 34698bd..1f04c26 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,9 @@ //! My (suri.codes) personal-knowledge-system, with deeply integrated task tracking and long term goal planning capabilities. //! +mod config; mod errors; +mod signal; mod tui; fn main() -> color_eyre::Result<()> { diff --git a/src/signal.rs b/src/signal.rs new file mode 100644 index 0000000..bcaef38 --- /dev/null +++ b/src/signal.rs @@ -0,0 +1,17 @@ +use strum::Display; + +use serde::{Deserialize, Serialize}; + +/// The varying signals that can be emitted. +#[derive(Debug, Clone, PartialEq, Eq, Display, Serialize, Deserialize)] +pub enum Signal { + Tick, + Render, + Resize(u16, u16), + Suspend, + Resume, + Quit, + ClearScreen, + Error(String), + Help, +}