diff --git a/src/main.rs b/src/main.rs index e867e24..3a41e13 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ use rnote::{app, process}; mod rnote; +/// Check if variable `EDITOR` is set. fn check() -> Result<()> { let editor = std::env::var("EDITOR").unwrap_or("".to_owned()); if editor.is_empty() { diff --git a/src/rnote/app.rs b/src/rnote/app.rs index 7292229..183f664 100644 --- a/src/rnote/app.rs +++ b/src/rnote/app.rs @@ -1,5 +1,6 @@ pub use clap::{App, AppSettings, Arg, SubCommand}; +/// Initialize all possible arguments. pub fn make_app() -> App<'static, 'static> { App::new("rnote") .version("0.0.1") diff --git a/src/rnote/notes.rs b/src/rnote/notes.rs index 1e3d838..448bd4a 100644 --- a/src/rnote/notes.rs +++ b/src/rnote/notes.rs @@ -58,7 +58,7 @@ pub fn create(header: &str, category: &str) -> Result<()> { Ok(()) } -/// Checks if potentially new note name already exists. +/// Check if potentially new note name already exists. fn is_duplicate(header: &str, category: &str) -> Result<()> { let file = format!("{}{}.md", get_path(category)?, header); let path = format!("{}", get_path(category)?); @@ -77,7 +77,7 @@ fn is_duplicate(header: &str, category: &str) -> Result<()> { Ok(()) } -/// Finds a path to desired note. +/// Find a path to desired note. pub fn find_path(header: &str) -> Result> { let mut paths: Vec = Vec::new(); let base = get_base_path()?; @@ -115,7 +115,7 @@ pub fn find_path(header: &str) -> Result> { } } -/// Deletes a note. +/// Delete a note. pub fn remove(header: &str) -> Result<()> { let path = find_path(header)?; if Confirm::with_theme(&ColorfulTheme::default()) @@ -150,6 +150,7 @@ pub fn modify(header: &str) -> Result<()> { } } +/// Search all notes that contain a given string. pub fn search_by_word(word: &str) -> Result<()> { extern crate fstream; let path = get_base_path()?; @@ -188,6 +189,7 @@ pub fn search_by_word(word: &str) -> Result<()> { Ok(()) } +/// Show all notes. pub fn show_all() -> Result<()> { let path = get_base_path()?; let mut files: Vec = Vec::new(); @@ -206,6 +208,7 @@ pub fn show_all() -> Result<()> { Ok(()) } +/// Show one note. pub fn show(header: &str) -> Result<()> { let path = find_path(header)?; match path { @@ -219,6 +222,7 @@ pub fn show(header: &str) -> Result<()> { } } +/// Show all notes in the given category. pub fn show_category(category: &str) -> Result<()> { let base = get_base_path()?; let path = format!("{}{}", base, category); @@ -240,6 +244,7 @@ pub fn show_category(category: &str) -> Result<()> { Ok(()) } +/// List all notes and optionally open one. pub fn list_all() -> Result<()> { let path = get_base_path()?; let mut files: Vec = Vec::new(); @@ -269,6 +274,7 @@ pub fn list_all() -> Result<()> { Ok(()) } +/// List all notes in the given category and optionally open one. pub fn list_category(category: &str) -> Result<()> { let base = get_base_path()?; let path = format!("{}{}", base, category); @@ -301,6 +307,7 @@ pub fn list_category(category: &str) -> Result<()> { Ok(()) } +/// Remove all notes created at the given date in format `YYYY-MM-dd`. pub fn wipe_date(date: &str) -> Result<()> { let base = get_base_path()?; for (_, file) in WalkDir::new(base) @@ -320,6 +327,7 @@ pub fn wipe_date(date: &str) -> Result<()> { Ok(()) } +/// Remove empty directories. fn remove_empty_dirs() -> Result<()> { let base = get_base_path()?; for (_, file) in WalkDir::new(base) diff --git a/src/rnote/process.rs b/src/rnote/process.rs index 74c3ff4..05b83e1 100644 --- a/src/rnote/process.rs +++ b/src/rnote/process.rs @@ -3,6 +3,7 @@ use anyhow::{anyhow, Result}; use clap::ArgMatches; use dialoguer::{theme::ColorfulTheme, Input}; +/// Process argument `new`. pub fn new(matches: &ArgMatches) -> Result<()> { let header = match matches.value_of("header") { Some(s) => s.to_owned(), @@ -16,6 +17,7 @@ pub fn new(matches: &ArgMatches) -> Result<()> { Ok(()) } +/// Process argument `remove`. pub fn remove(matches: &ArgMatches) -> Result<()> { match matches.value_of("header") { Some(s) => notes::remove(s)?, @@ -38,6 +40,7 @@ pub fn remove(matches: &ArgMatches) -> Result<()> { Ok(()) } +/// Process argument `remove`. pub fn edit(matches: &ArgMatches) -> Result<()> { let header = match matches.value_of("header") { Some(s) => s.to_owned(), @@ -50,6 +53,7 @@ pub fn edit(matches: &ArgMatches) -> Result<()> { Ok(()) } +/// Process argument `list`. pub fn list(matches: &ArgMatches) -> Result<()> { match matches.is_present("category") { true => { @@ -63,6 +67,7 @@ pub fn list(matches: &ArgMatches) -> Result<()> { Ok(()) } +/// Process argument `search`. pub fn search(matches: &ArgMatches) -> Result<()> { match matches.value_of("header") { Some(s) => { @@ -88,6 +93,7 @@ pub fn search(matches: &ArgMatches) -> Result<()> { Ok(()) } +/// Process argument `show`. pub fn show(matches: &ArgMatches) -> Result<()> { match matches.value_of("header") { Some(s) => notes::show(s)?, @@ -107,6 +113,7 @@ pub fn show(matches: &ArgMatches) -> Result<()> { Ok(()) } +/// Process argument `panic`. pub fn panic() -> Result<()> { let base = notes::get_base_path()?; std::fs::remove_dir_all(base)?; diff --git a/src/rnote/show.rs b/src/rnote/show.rs index 40e991c..588afa8 100644 --- a/src/rnote/show.rs +++ b/src/rnote/show.rs @@ -8,12 +8,14 @@ use crossterm::{ use std::io::{stderr, Write}; use termimad::*; +/// Set view area. pub fn view_area() -> Area { let mut area = Area::full_screen(); area.pad_for_max_width(120); // we don't want a too wide text column area } +/// Display the given markdown string `md` in a Scrollable TextView in a raw terminal. pub fn run_app(skin: MadSkin, md: &str) -> Result<()> { let mut w = stderr(); // we could also have used stdout queue!(w, EnterAlternateScreen)?; @@ -45,6 +47,7 @@ pub fn run_app(skin: MadSkin, md: &str) -> Result<()> { Ok(()) } +/// Set MadSkin. pub fn make_skin() -> MadSkin { let mut skin = MadSkin::default(); skin.table.align = Alignment::Center;