Implement done command
This commit is contained in:
parent
0de89bd424
commit
b476a95afb
6 changed files with 67 additions and 20 deletions
16
src/cli/done.rs
Normal file
16
src/cli/done.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
use chrono::NaiveDateTime;
|
||||
|
||||
use crate::eval::Entry;
|
||||
use crate::files::commands::Done;
|
||||
use crate::files::Files;
|
||||
|
||||
use super::error::Result;
|
||||
|
||||
pub fn mark_done(files: &mut Files, entry: &Entry, now: NaiveDateTime) -> Result<()> {
|
||||
let done = Done {
|
||||
date: entry.dates.map(|dates| dates.into()),
|
||||
done_at: now.date(),
|
||||
};
|
||||
files.add_done(entry.source, done)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
use std::result;
|
||||
|
||||
use crate::files::Source;
|
||||
use crate::{eval, files};
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
@ -8,6 +9,8 @@ pub enum Error {
|
|||
Files(#[from] files::Error),
|
||||
#[error("{0}")]
|
||||
Eval(#[from] eval::Error),
|
||||
#[error("No number specified")]
|
||||
NoNumber,
|
||||
#[error("No entry with number {0}")]
|
||||
NoSuchEntry(usize),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,23 +115,16 @@ impl ShowLines {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn show_all(layout: &LineLayout) -> String {
|
||||
pub fn show_all(layout: &LineLayout) {
|
||||
let num_width = cmp::max(layout.num_width(), 3); // `now` is 3 chars wide
|
||||
let mut show_lines = ShowLines::new(num_width, layout.span_width());
|
||||
for line in layout.lines() {
|
||||
show_lines.display_line(line);
|
||||
}
|
||||
show_lines.result()
|
||||
print!("{}", show_lines.result());
|
||||
}
|
||||
|
||||
pub fn show_entry(
|
||||
files: &Files,
|
||||
entries: &[Entry],
|
||||
layout: &LineLayout,
|
||||
number: usize,
|
||||
) -> Result<()> {
|
||||
let index = layout.look_up_number(number)?;
|
||||
let entry = &entries[index];
|
||||
pub fn show_entry(files: &Files, entry: &Entry) -> Result<()> {
|
||||
let command = files.command(entry.source);
|
||||
|
||||
match entry.kind {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue