-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
249 additions
and
211 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "c3" | ||
version = "1.5.0" | ||
version = "1.5.1" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use clap::{Parser, ValueEnum}; | ||
use todo_app::SortMethod; | ||
use std::path::PathBuf; | ||
use fileio::get_todo_path; | ||
use std::fmt; | ||
|
||
pub mod date; | ||
pub mod fileio; | ||
pub mod todo_app; | ||
|
||
#[derive(ValueEnum, Clone, Debug)] | ||
pub enum DoOnSelected { | ||
Delete, | ||
Done, | ||
} | ||
|
||
|
||
#[derive(Parser, Debug, Default)] | ||
#[command(author, version, about, long_about = None)] | ||
pub struct AppArgs { | ||
/// Performance mode, don't read dependencies | ||
#[arg(short = 'n', long)] | ||
pub no_tree: bool, | ||
|
||
#[command(flatten)] | ||
pub display_args: DisplayArgs, | ||
|
||
/// Path to todo file (and notes sibling directory) | ||
#[arg(default_value=get_todo_path().unwrap().into_os_string())] | ||
pub todo_path: PathBuf, | ||
|
||
/// Sort method, how sortings are done in the app | ||
#[arg(long, default_value = "normal")] | ||
pub sort_method: SortMethod, | ||
} | ||
|
||
#[derive(Parser, Debug, Default)] | ||
#[command(author, version, about, long_about = None)] | ||
pub struct DisplayArgs { | ||
/// Show done todos too | ||
#[arg(short = 'd', long, default_value_t = false)] | ||
show_done: bool, | ||
|
||
/// String before done todos | ||
#[arg(long, default_value_t=String::from("[x] "))] | ||
done_string: String, | ||
|
||
/// String before undone todos | ||
#[arg(long, default_value_t=String::from("[ ] "))] | ||
undone_string: String, | ||
} | ||
|
||
pub trait TodoDisplay: fmt::Display { | ||
fn display_with_args(&self, args: &DisplayArgs) -> String; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,155 +1,39 @@ | ||
// vim:fileencoding=utf-8:foldmethod=marker | ||
use clap::{Parser, ValueEnum}; | ||
use clap_complete::Shell; | ||
use std::{fmt, io}; | ||
use std::io; | ||
use clap::Parser; | ||
pub(crate) mod cli_app; | ||
pub(crate) mod date; | ||
pub(crate) mod fileio; | ||
pub(crate) mod todo_app; | ||
pub(crate) mod tui_app; | ||
use crate::fileio::get_todo_path; | ||
use std::path::PathBuf; | ||
use todo_app::App; | ||
|
||
fn main() -> io::Result<()> { | ||
let args = Args::parse(); | ||
let mut app = App::new(args.app_args); | ||
|
||
if cli_app::run(&mut app, args.cli_args).is_err() { | ||
let result = tui_app::run(&mut app, args.tui_args); | ||
tui_app::shutdown()?; | ||
result | ||
} else { | ||
Ok(()) | ||
} | ||
} | ||
use c3::{ | ||
todo_app::App, | ||
AppArgs, | ||
}; | ||
use cli_app::CliArgs; | ||
use tui_app::TuiArgs; | ||
|
||
/// A tree-like todo application that makes you smile | ||
#[derive(Parser, Debug)] | ||
#[command(author, version, about, long_about = None)] | ||
pub struct Args { | ||
#[command(flatten)] | ||
app_args: AppArgs, | ||
|
||
#[command(flatten)] | ||
cli_args: CliArgs, | ||
pub app_args: AppArgs, | ||
|
||
#[command(flatten)] | ||
tui_args: TuiArgs, | ||
} | ||
|
||
#[derive(ValueEnum, Clone, Debug)] | ||
pub enum DoOnSelected { | ||
Delete, | ||
Done, | ||
} | ||
|
||
#[derive(Parser, Debug)] | ||
#[command(author, version, about, long_about = None)] | ||
struct CliArgs { | ||
/// Search and select todo. Used for batch change operations | ||
#[arg(short = 'S', long)] | ||
search_and_select: Vec<String>, | ||
|
||
#[arg(long)] | ||
do_on_selected: Option<DoOnSelected>, | ||
|
||
#[arg(short = 'b', long, default_value_t = false)] | ||
batch_edit: bool, | ||
|
||
/// A todo message to append | ||
#[arg(short = 'a', long)] | ||
append_todo: Vec<String>, | ||
|
||
/// A todo message to prepend | ||
#[arg(short = 'A', long)] | ||
prepend_todo: Vec<String>, | ||
|
||
/// A todo file to append to current list | ||
#[arg(long)] | ||
append_file: Option<PathBuf>, | ||
|
||
/// A todo file to output to | ||
#[arg(short = 'o', long)] | ||
output_file: Option<PathBuf>, | ||
|
||
#[arg(short = 'p', long, default_value_t = false)] | ||
print_path: bool, | ||
|
||
/// Minimal tree with no tree graphics | ||
#[arg(short = 'M', long)] | ||
minimal_tree: bool, | ||
|
||
/// List todos (non interactive) | ||
#[arg(short = 'l', long)] | ||
list: bool, | ||
|
||
/// Write contents of todo file in the stdout (non interactive) | ||
#[arg(short = 's', long)] | ||
stdout: bool, | ||
|
||
/// Generate completion for a certain shell | ||
#[arg(short = 'c', long)] | ||
completion: Option<Shell>, | ||
} | ||
|
||
#[derive(Parser, Debug)] | ||
#[command(author, version, about, long_about = None)] | ||
struct TuiArgs { | ||
/// Alternative way of rendering, render minimum amount of todos | ||
#[arg(long)] | ||
minimal_render: bool, | ||
|
||
/// String behind highlighted todo in TUI mode | ||
#[arg(short='H', long, default_value_t=String::from(">>"))] | ||
highlight_string: String, | ||
|
||
/// Enable TUI module at startup | ||
#[arg(short = 'm', long)] | ||
enable_module: bool, | ||
} | ||
|
||
#[derive(ValueEnum, Clone, Debug, PartialEq)] | ||
pub enum SortMethod { | ||
AbandonedFirst, | ||
Normal, | ||
} | ||
|
||
#[derive(Parser, Debug)] | ||
#[command(author, version, about, long_about = None)] | ||
struct AppArgs { | ||
/// Performance mode, don't read dependencies | ||
#[arg(short = 'n', long)] | ||
no_tree: bool, | ||
pub cli_args: CliArgs, | ||
|
||
#[command(flatten)] | ||
display_args: DisplayArgs, | ||
|
||
/// Path to todo file (and notes sibling directory) | ||
#[arg(default_value=get_todo_path().unwrap().into_os_string())] | ||
todo_path: PathBuf, | ||
|
||
/// Sort method, how sortings are done in the app | ||
#[arg(long, default_value = "normal")] | ||
sort_method: SortMethod, | ||
pub tui_args: TuiArgs, | ||
} | ||
|
||
#[derive(Parser, Debug)] | ||
#[command(author, version, about, long_about = None)] | ||
pub struct DisplayArgs { | ||
/// Show done todos too | ||
#[arg(short = 'd', long, default_value_t = false)] | ||
show_done: bool, | ||
|
||
/// String before done todos | ||
#[arg(long, default_value_t=String::from("[x] "))] | ||
done_string: String, | ||
fn main() -> io::Result<()> { | ||
let args = Args::parse(); | ||
let mut app = App::new(args.app_args); | ||
|
||
/// String before undone todos | ||
#[arg(long, default_value_t=String::from("[ ] "))] | ||
undone_string: String, | ||
if cli_app::run(&mut app, args.cli_args).is_err() { | ||
let result = tui_app::run(&mut app, args.tui_args); | ||
tui_app::shutdown()?; | ||
result | ||
} else { | ||
Ok(()) | ||
} | ||
} | ||
|
||
trait TodoDisplay: fmt::Display { | ||
fn display_with_args(&self, args: &DisplayArgs) -> String; | ||
} |
Oops, something went wrong.