From 5002c9f6c2ad01bee55c810397779c5a16cde278 Mon Sep 17 00:00:00 2001 From: moo Date: Fri, 13 Feb 2026 14:57:27 -0800 Subject: [PATCH] maintainer --- PKGBUILD | 2 + src/main.rs | 161 ---------------------------------------------------- 2 files changed, 2 insertions(+), 161 deletions(-) delete mode 100644 src/main.rs diff --git a/PKGBUILD b/PKGBUILD index a7d9792..21e5820 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,3 +1,5 @@ +# Maintainer: Moogoesmeow moogoesmeow123@gmail.com + pkgname="dibble" pkgver="0.1.1" pkgrel="1" diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index 47f50c8..0000000 --- a/src/main.rs +++ /dev/null @@ -1,161 +0,0 @@ -use anyhow::Result; -use clap::Parser; -use color_print::cprintln; -use directories::ProjectDirs; -use serde::{Deserialize, Serialize}; -use serde_json::from_str; -use std::{ - collections::hash_map::HashMap, - fs::File, - io::Read, - path::{Path, PathBuf}, -}; - -#[derive(Parser)] -#[command(name = "dibble")] -#[command(version = "1.0")] -#[command(about = "Quick and local word definitions", long_about = None)] -struct Cli { - /// The word to define - word: String, - - /// Don't show example sentences - #[arg(action, long, short)] - no_examples: bool, -} - -fn main() -> Result<()> { - let cli = Cli::parse(); - - let mut chars = cli.word.chars().clone(); - let first = chars.next().unwrap(); - - let target: PathBuf = if let Some(second) = chars.next() { - let mut path = PathBuf::from(String::from(first)); - path.push(format!("{}{}", String::from(first), String::from(second))); - path - } else { - let path = PathBuf::from(String::from(first)); - path.into() - }; - - dbg!(&target); - - let contents = read_data(target.into())?; - - let data: DictionaryFile = from_str(&contents)?; - - if let Some(f) = data.get(&cli.word) { - f.print_colored(); - } else { - cprintln!("Word not found: {}", cli.word); - } - - Ok(()) -} - -fn read_data(path: PathBuf) -> Result { - let dirs: ProjectDirs = ProjectDirs::from("com.taranathan.dibble", "taran", "dibble").unwrap(); - - let mut user_target = dirs.data_dir().to_path_buf(); - user_target.push(Path::new("dict")); - user_target.push(&path); - user_target.set_extension("json"); - - let mut system_target = PathBuf::from("/usr/share/dibble/dict"); - system_target.push(&path); - system_target.set_extension("json"); - - if let Ok(mut file) = File::open(&user_target) { - let mut contents = String::new(); - file.read_to_string(&mut contents)?; - return Ok(contents); - } - - // system installation fallback - if let Ok(mut file) = File::open(&system_target) { - let mut contents = String::new(); - file.read_to_string(&mut contents)?; - return Ok(contents); - } - - // If both failed, return a helpful error - anyhow::bail!( - "Dictionary file not found. Searched:\n - {}\n - {}", - user_target.display(), - system_target.display() - ) -} - -pub type DictionaryFile = HashMap; - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Definition { - /// The word being defined - pub word: String, - /// Array of Etymology objects, representing different meanings or origins of the word - pub etymologies: Vec, -} - -/// Represents a particular etymology or origin of a word -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Etymology { - /// Array of Part of Speech objects within this etymology - #[serde(rename = "partsOfSpeech")] - pub parts_of_speech: Vec, -} - -/// Represents a specific part of speech for a word -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct PartOfSpeech { - /// The part of speech (e.g., "Noun", "Verb", "Adjective") - #[serde(rename = "partOfSpeech")] - pub part_of_speech: String, - /// Array of Sense objects representing different meanings - pub senses: Vec, -} - -/// Represents a specific sense or meaning of a word -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Sense { - /// The specific sense or meaning - pub sense: String, - /// Optional: Time period or usage context - #[serde(skip_serializing_if = "Option::is_none")] - pub date: Option, - #[serde(default)] - pub examples: Vec, -} - -impl Definition { - pub fn print_colored(&self) { - //header - cprintln!("{}", self.word); - - for (etym_idx, etymology) in self.etymologies.iter().enumerate() { - if self.etymologies.len() > 1 { - cprintln!("Etymology {}:", etym_idx + 1); - } - - for pos in &etymology.parts_of_speech { - cprintln!(" {}", pos.part_of_speech); - - for (sense_idx, sense) in pos.senses.iter().enumerate() { - cprintln!(" {}. {}", sense_idx + 1, sense.sense); - - if let Some(date) = &sense.date { - if date.len() > 0 { - cprintln!(" [{}]", date); - } - } - - // Print examples if available - for example in &sense.examples { - cprintln!(" \"{}\"", example); - } - } - cprintln!(); - } - } - } -} -- 2.47.3