Skip to content

Commit

Permalink
Changed app structure into a (i hope) better one
Browse files Browse the repository at this point in the history
  • Loading branch information
nimaaskarian committed Feb 3, 2024
1 parent 1e5b9fb commit 7adf694
Show file tree
Hide file tree
Showing 21 changed files with 1,046 additions and 1,032 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ratatui = "0.25.0"
crossterm = "0.27.0"
tui-textarea = "0.4.0"
chrono = "0.4.31"
clap = { version = "4.4.18", features = ["derive"] }
clap = { version = "4.4.18", features = ["derive", "string"] }

[profile.release]
codegen-units = 1
Expand Down
3 changes: 3 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub(crate) mod todo;
pub(crate) mod cli;
pub(crate) mod tui;
44 changes: 19 additions & 25 deletions src/cli/app.rs → src/app/cli.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,40 @@
use std::io;
use super::todo::{App ,TodoList};

use crate::fileio::todo_path;
use crate::todo_list::TodoList;
use crate::Args;

pub struct App {
todo_list: TodoList,
args: Args,
#[inline]
pub fn run(app: &mut App) -> io::Result<()>{
let app = CliApp::new(app);
app.print()?;
Ok(())
}

impl App {
pub struct CliApp<'a> {
todo_app: &'a mut App,
}

impl <'a>CliApp <'a>{
#[inline]
pub fn new(args: Args) -> Self {
let todo_list = match &args.todo_path {
Some(value) => TodoList::read(value, args.tree, true),
None => {
let todo_path = todo_path().unwrap();
TodoList::read(&todo_path, args.tree, true)
}
};
App {
args,
todo_list,
pub fn new(app: &'a mut App) -> Self {
CliApp {
todo_app: app,
}
}

#[inline]
fn print_list(&self) {
for todo_str in self.todo_list.display(self.args.show_done) {
println!("{}", todo_str);
for display in self.todo_app.display() {
println!("{}", display);
}
}

#[inline]
pub fn print(&self) -> io::Result<()>{
if self.args.stdout {
self.todo_list.print()?;
if self.todo_app.args.stdout {
self.todo_app.print()?;
return Ok(())
}
if self.args.tree {
Self::print_tree(&self.todo_list, self.args.show_done, 0, vec![false])
if self.todo_app.is_tree() {
Self::print_tree(&self.todo_app.todo_list, self.todo_app.args.show_done, 0, vec![false])
} else {
self.print_list()
}
Expand Down
Loading

0 comments on commit 7adf694

Please sign in to comment.