Show single entries
This commit is contained in:
parent
6365d2621b
commit
34a053cbe4
5 changed files with 81 additions and 5 deletions
15
src/cli/error.rs
Normal file
15
src/cli/error.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
use std::result;
|
||||
|
||||
use crate::{eval, files};
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
#[error("{0}")]
|
||||
Files(#[from] files::Error),
|
||||
#[error("{0}")]
|
||||
Eval(#[from] eval::Error),
|
||||
#[error("No entry with number {0}")]
|
||||
NoSuchEntry(usize),
|
||||
}
|
||||
|
||||
pub type Result<T> = result::Result<T, Error>;
|
||||
|
|
@ -11,6 +11,7 @@ use crate::eval::{Entry, EntryKind};
|
|||
use crate::files::primitives::Time;
|
||||
use crate::files::Files;
|
||||
|
||||
use super::super::error::{Error, Result};
|
||||
use super::day::{DayEntry, DayLayout};
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
|
|
@ -101,12 +102,13 @@ impl LineLayout {
|
|||
&self.numbers
|
||||
}
|
||||
|
||||
pub fn look_up_number(&self, number: usize) -> Option<usize> {
|
||||
pub fn look_up_number(&self, number: usize) -> Result<usize> {
|
||||
self.numbers
|
||||
.iter()
|
||||
.filter(|(_, n)| **n == number)
|
||||
.map(|(i, _)| *i)
|
||||
.next()
|
||||
.ok_or_else(|| Error::NoSuchEntry(number))
|
||||
}
|
||||
|
||||
fn render_layout_entry(&mut self, files: &Files, entries: &[Entry], l_entry: &DayEntry) {
|
||||
|
|
|
|||
|
|
@ -2,8 +2,11 @@ use std::cmp;
|
|||
|
||||
use chrono::{Datelike, NaiveDate};
|
||||
|
||||
use crate::eval::{Entry, EntryKind};
|
||||
use crate::files::primitives::{Time, Weekday};
|
||||
use crate::files::Files;
|
||||
|
||||
use super::error::{Error, Result};
|
||||
use super::layout::line::{LineEntry, LineLayout, SpanSegment};
|
||||
|
||||
struct ShowLines {
|
||||
|
|
@ -119,3 +122,55 @@ pub fn show_all(layout: &LineLayout) -> String {
|
|||
}
|
||||
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];
|
||||
let command = files.command(entry.source);
|
||||
|
||||
match entry.kind {
|
||||
EntryKind::Task => println!("TASK {}", command.title()),
|
||||
EntryKind::TaskDone(when) => {
|
||||
println!("DONE {}", command.title());
|
||||
println!("DONE AT {}", when);
|
||||
}
|
||||
EntryKind::Note => println!("NOTE {}", command.title()),
|
||||
EntryKind::Birthday(Some(age)) => {
|
||||
println!("BIRTHDAY {}", command.title());
|
||||
println!("AGE {}", age);
|
||||
}
|
||||
EntryKind::Birthday(None) => {
|
||||
println!("BIRTHDAY {}", command.title());
|
||||
println!("AGE UNKNOWN");
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(dates) = entry.dates {
|
||||
let (start, end) = dates.start_end();
|
||||
if start == end {
|
||||
match dates.start_end_time() {
|
||||
Some((s, e)) if s == e => println!("DATE {} {}", start, s),
|
||||
Some((s, e)) => println!("DATE {} {} -- {}", start, s, e),
|
||||
None => println!("DATE {}", start),
|
||||
}
|
||||
} else {
|
||||
match dates.start_end_time() {
|
||||
Some((s, e)) => println!("DATE {} {} -- {} {}", start, s, end, e),
|
||||
None => println!("DATE {} -- {}", start, end),
|
||||
}
|
||||
}
|
||||
} else {
|
||||
println!("NO DATE");
|
||||
};
|
||||
|
||||
for line in command.desc() {
|
||||
println!("# {}", line);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue