Skip to content

Commit

Permalink
Merge branch 'release/0.9.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
nimaaskarian committed Apr 5, 2024
2 parents fa90622 + 6fa58ce commit a8aef1e
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 9 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 = "0.8.0"
version = "0.9.0"
edition = "2021"

[dependencies]
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ The default mode of the app is TUI mode. Keybinds are vim-like. Here they are:
| y | yank todo to clipboard |
| p | paste todo from clipboard |
| P | enable module |
| / | search todo |
| / | search current list for todo |
| ? | search the whole tree for todo |
| O | open nnn file picker for choosing a file to append to current list
| n | search next |
| N | search previous |
| w | write changes to file |
Expand Down
3 changes: 3 additions & 0 deletions src/cli_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ impl <'a>CliApp <'a>{
for message in app.args.prepend_todo.clone() {
app.prepend(message);
}
if let Some(path) = app.args.append_file.clone() {
app.append_list_from_path(path)
}
app.do_commands_on_selected();
if !app.args.append_todo.is_empty() || !app.args.prepend_todo.is_empty() || app.is_changed(){
let _ = app.write();
Expand Down
7 changes: 6 additions & 1 deletion src/fileio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ pub fn get_todo_path() -> io::Result<PathBuf> {

#[inline(always)]
pub fn temp_note_path() -> PathBuf{
temp_path("note")
}

#[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-note.{time}");
let filename = format!("c3-{name}.{time}");
let path = home_dir().unwrap().join(filename);
path.to_path_buf()
}
Expand Down
10 changes: 7 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,18 @@ pub struct Args {
#[command(flatten)]
display_args: DisplayArgs,

/// Append todo
/// A todo message to append
#[arg(short='a', long)]
append_todo: Vec<String>,

/// Prepend todo
/// 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>,

/// Minimal tree with no tree graphics
#[arg(short='M', long)]
minimal_tree: bool,
Expand All @@ -99,7 +103,7 @@ pub struct Args {
impl Args {
pub fn is_cli(&self) -> bool {
self.stdout || self.minimal_tree || self.list ||
!self.search_and_select.is_empty() || !self.prepend_todo.is_empty() || !self.append_todo.is_empty()
!self.search_and_select.is_empty() || !self.prepend_todo.is_empty() || !self.append_todo.is_empty() || self.append_file.is_some()
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/todo_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ impl App {
app
}

#[inline]
pub fn append_list_from_path(&mut self, path: PathBuf) {
let todo_list = TodoList::read(&path, !self.args.no_tree, true);
self.append_list(todo_list)
}

#[inline]
pub fn append_list(&mut self, todo_list: TodoList) {
self.mut_current_list().append_list(todo_list)
}

pub fn do_commands_on_selected(&mut self) {
let mut index_shift = 0;
for (iter_index, sel_index) in self.selected.clone().iter().enumerate() {
Expand Down
7 changes: 7 additions & 0 deletions src/todo_app/todo_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ impl TodoList {
}
}

pub fn append_list(&mut self, mut todo_list: TodoList) {
self.undone.todos.append(&mut todo_list.undone.todos);
self.done.todos.append(&mut todo_list.done.todos);
self.done.sort();
self.undone.sort();
}

pub fn remove(&mut self, index: usize) -> Todo {
let size = self.undone.len();

Expand Down
24 changes: 22 additions & 2 deletions src/tui_app.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// vim:fileencoding=utf-8:foldmethod=marker
// std {{{
use std::{io::{self, stdout}, rc::Rc};
use std::{fs::{read_to_string, remove_file}, io::{self, stdout}, path::PathBuf, rc::Rc};
use std::process::Command;
// }}}
// lib {{{
use crossterm::{
Expand All @@ -19,7 +20,7 @@ use modules::{
potato::Potato,
};
use super::todo_app::{App, Todo};
use crate::{date, todo_app::PriorityType};
use crate::{date, fileio::temp_path, todo_app::PriorityType};
// }}}

pub fn default_block<'a, T>(title: T) -> Block<'a>
Expand Down Expand Up @@ -197,6 +198,21 @@ impl<'a>TuiApp<'a>{
self.set_text_mode(Self::on_reminder, "Date reminder", "");
}

#[inline]
pub fn nnn_append_todo(&mut self) {
let path = temp_path("nnn-file-picker");
if Command::new("nnn").args(["-p", path.to_str().unwrap_or("")]).status().is_err(){
return
}
let mut output_str = match read_to_string(&path) {
Ok(value) => value,
Err(_) => return,
};
output_str.pop();
self.todo_app.append_list_from_path(PathBuf::from(output_str));
let _ = remove_file(path);
}

#[inline]
fn on_reminder(&mut self,str:String) {
if let Ok(date) = date::parse_user_input(&str) {
Expand Down Expand Up @@ -369,6 +385,10 @@ impl<'a>TuiApp<'a>{
Char('p') => self.todo_app.paste_todo(),
Char('i') => self.todo_app.increase_day_done(),
Char('o') => self.todo_app.decrease_day_done(),
Char('O') => {
self.nnn_append_todo();
return Ok(Operation::Restart)
}
KeyCode::Down | Char('j') => self.todo_app.increment(),
KeyCode::Up |Char('k') => self.todo_app.decrement(),
KeyCode::Right | Char('l') => self.todo_app.add_dependency_traverse_down(),
Expand Down

0 comments on commit a8aef1e

Please sign in to comment.