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