Skip to content

Commit

Permalink
Merge branch 'release/1.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
nimaaskarian committed Aug 18, 2024
2 parents add5e08 + 8e87449 commit 5ef043b
Show file tree
Hide file tree
Showing 14 changed files with 776 additions and 691 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.4.0"
version = "1.5.0"
edition = "2021"

[dependencies]
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ The default mode of the app is TUI mode. Keybinds are vim-like. Here they are:
| o | open nnn file picker to choose a file to append to current list |
| O | open nnn file picker to choose a file to output current list to |
| Ctrl+o | open nnn file picker to choose a file to open |
| Ctrl+d | sort by todo's abandonment (how hasn't been done compared to their schedule) |
| w | write changes to file |
| R | read from file (discard changes)|
#### Modules
Expand All @@ -87,3 +88,7 @@ Keybinds that modules can use are **C, c, H, L, comma, period, +, -, s, r**

### Non interactive mode
For command line arguments and such, run `c3 -h` to see full usage.

## Performance
If you're experiencing performance issues on very large todo lists (I begin to experience it with 500k todos, which can seem like a lot),
you can use `--minimal-render` and `--no-tree` cli options. Also use `?` (tree) search instead of the normal search.
45 changes: 22 additions & 23 deletions src/cli_app.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use clap::{Command, CommandFactory};
use super::todo_app::{App, RestrictionFunction, Todo, TodoList};
use super::todo_app::{App, Restriction, Todo, TodoList};
use crate::{Args, TodoDisplay};
use crate::{CliArgs, DisplayArgs, DoOnSelected};
use crate::Args;
use clap::{Command, CommandFactory};
use clap_complete::{generate, Generator};
use std::io;
use std::process;

pub struct NotCli;
#[inline]
pub fn run(app: &mut App, args: CliArgs) -> Result<(),NotCli> {
pub fn run(app: &mut App, args: CliArgs) -> Result<(), NotCli> {
if !args.search_and_select.is_empty() {
for query in args.search_and_select {
app.set_query_restriction(query, None)
Expand All @@ -19,9 +19,10 @@ pub fn run(app: &mut App, args: CliArgs) -> Result<(),NotCli> {
let restriction = app.restriction().clone();
if let Some(do_on_selected) = args.do_on_selected {
match do_on_selected {
DoOnSelected::Delete => {
app.current_list_mut().todos.retain(|todo| !restriction(todo))
}
DoOnSelected::Delete => app
.current_list_mut()
.todos
.retain(|todo| !restriction(todo)),
DoOnSelected::Done => {
for todo in app.current_list_mut().todos_mut(&restriction) {
todo.set_done(true);
Expand All @@ -30,7 +31,7 @@ pub fn run(app: &mut App, args: CliArgs) -> Result<(),NotCli> {
}
} else {
print_todos(app);
return Ok(())
return Ok(());
}
}
if args.batch_edit {
Expand All @@ -45,33 +46,29 @@ pub fn run(app: &mut App, args: CliArgs) -> Result<(),NotCli> {
if notes.is_dir() {
println!("{}", notes.to_str().unwrap_or(""));
}
return Ok(())
return Ok(());
}
if let Some(generator) = args.completion {
print_completions(generator, &mut Args::command());
return Ok(())
return Ok(());
}

if args.stdout {
app.write_to_stdout();
return Ok(())
return Ok(());
}
if args.minimal_tree || args.list {
if app.args.no_tree {
print_todos(app);
} else {
let mut print_todo = PrintTodoTree::new(args.minimal_tree);
print_todo.print_list(
&app.todo_list,
&app.args.display_args,
app.restriction(),
)
print_todo.print_list(&app.todo_list, &app.args.display_args, app.restriction())
}
return Ok(())
return Ok(());
}
if let Some(path) = args.output_file.as_ref() {
app.output_list_to_path(path);
return Ok(())
return Ok(());
}
Err(NotCli)
}
Expand Down Expand Up @@ -123,12 +120,14 @@ impl PrintTodoTree {
&mut self,
todo_list: &TodoList,
display_args: &DisplayArgs,
restriction: &RestrictionFunction,
restriction: &Restriction,
) {
let todos = todo_list.todos(restriction);
let mut iter = todo_list.todos(restriction);
let mut next = iter.next();

for (index, todo) in todos.iter().enumerate() {
self.is_last = index == todos.len() - 1;
while let Some(todo) = next {
next = iter.next();
self.is_last = next.is_none();
if !self.last_stack.is_empty() {
self.print_indention();
}
Expand All @@ -145,7 +144,7 @@ impl PrintTodoTree {

#[inline]
fn print_todo(&self, todo: &Todo, display_args: &DisplayArgs) {
println!("{}", todo.display(display_args));
println!("{}", todo.display_with_args(display_args));
}

#[inline]
Expand Down
17 changes: 5 additions & 12 deletions src/fileio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,11 @@ pub fn get_todo_path() -> io::Result<PathBuf> {

#[inline(always)]
pub fn temp_path(name: &str) -> PathBuf {
let time = match SystemTime::now().duration_since(UNIX_EPOCH) {
Err(_) => 12345,
Ok(some) => some.as_secs(),
};
let filename = format!("c3-{name}.{time}");
let tmpdir = PathBuf::from("/tmp");
let path = if tmpdir.is_dir() {
tmpdir.join(filename)
} else {
home_dir().unwrap().join(filename)
};
path.to_path_buf()
let time = SystemTime::now()
.duration_since(UNIX_EPOCH)
.map_or(String::new(), |time| time.as_secs().to_string());
let tmpdir = env::temp_dir();
tmpdir.join(format!("c3-{name}-{time}"))
}

#[inline(always)]
Expand Down
30 changes: 21 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// vim:fileencoding=utf-8:foldmethod=marker
use clap::{Parser, ValueEnum};
use clap_complete::Shell;
use std::io;
use std::{fmt, io};
pub(crate) mod cli_app;
pub(crate) mod date;
pub(crate) mod fileio;
Expand All @@ -16,11 +16,9 @@ fn main() -> io::Result<()> {
let mut app = App::new(args.app_args);

if cli_app::run(&mut app, args.cli_args).is_err() {
let output = tui_app::run(&mut app, args.tui_args);
{
tui_app::shutdown()?;
output
}
let result = tui_app::run(&mut app, args.tui_args);
tui_app::shutdown()?;
result
} else {
Ok(())
}
Expand Down Expand Up @@ -56,7 +54,7 @@ struct CliArgs {
#[arg(long)]
do_on_selected: Option<DoOnSelected>,

#[arg(short='b',long, default_value_t=false)]
#[arg(short = 'b', long, default_value_t = false)]
batch_edit: bool,

/// A todo message to append
Expand All @@ -72,10 +70,10 @@ struct CliArgs {
append_file: Option<PathBuf>,

/// A todo file to output to
#[arg(short='o', long)]
#[arg(short = 'o', long)]
output_file: Option<PathBuf>,

#[arg(short='p', long, default_value_t=false)]
#[arg(short = 'p', long, default_value_t = false)]
print_path: bool,

/// Minimal tree with no tree graphics
Expand Down Expand Up @@ -111,6 +109,12 @@ struct TuiArgs {
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 {
Expand All @@ -124,6 +128,10 @@ struct AppArgs {
/// 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,
}

#[derive(Parser, Debug)]
Expand All @@ -141,3 +149,7 @@ pub struct DisplayArgs {
#[arg(long, default_value_t=String::from("[ ] "))]
undone_string: String,
}

trait TodoDisplay: fmt::Display {
fn display_with_args(&self, args: &DisplayArgs) -> String;
}
Loading

0 comments on commit 5ef043b

Please sign in to comment.