Skip to content

Commit

Permalink
Merge branch 'release/1.5.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
nimaaskarian committed Aug 20, 2024
2 parents 5ef043b + 3cc46f5 commit 8ff92cd
Show file tree
Hide file tree
Showing 10 changed files with 249 additions and 211 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
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]
Expand Down
58 changes: 55 additions & 3 deletions src/cli_app.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,62 @@
use super::todo_app::{App, Restriction, Todo, TodoList};
use crate::{Args, TodoDisplay};
use crate::{CliArgs, DisplayArgs, DoOnSelected};
use c3::todo_app::{App, Restriction, Todo, TodoList};
use clap_complete::Shell;
use crate::Args;
use c3::{DisplayArgs, TodoDisplay, DoOnSelected};
use clap::{Command, CommandFactory};
use clap_complete::{generate, Generator};
use std::io;
use std::process;
use std::path::PathBuf;
use clap::Parser;

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub 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>,
}

pub struct NotCli;
#[inline]
Expand Down
56 changes: 56 additions & 0 deletions src/lib.rs
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;
}

158 changes: 21 additions & 137 deletions src/main.rs
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;
}
Loading

0 comments on commit 8ff92cd

Please sign in to comment.