Show logs in addition to entries
This commit is contained in:
parent
badc0d7a9f
commit
3e2fa54213
5 changed files with 90 additions and 41 deletions
|
|
@ -1,9 +1,18 @@
|
|||
use chrono::NaiveDate;
|
||||
|
||||
use crate::eval::{Entry, EntryKind};
|
||||
use crate::files::Files;
|
||||
use crate::files::commands::{Command, Log};
|
||||
use crate::files::{Files, Sourced};
|
||||
|
||||
use super::error::Error;
|
||||
use super::layout::line::LineLayout;
|
||||
|
||||
fn show_command(command: &Command) {
|
||||
for line in format!("{}", command).lines() {
|
||||
println!("| {}", line);
|
||||
}
|
||||
}
|
||||
|
||||
fn show_entry(files: &Files, entry: &Entry) {
|
||||
let command = files.command(entry.source);
|
||||
|
||||
|
|
@ -28,32 +37,46 @@ fn show_entry(files: &Files, entry: &Entry) {
|
|||
}
|
||||
|
||||
println!("FROM COMMAND");
|
||||
for line in format!("{}", command.command).lines() {
|
||||
println!("| {}", line);
|
||||
show_command(command.value);
|
||||
}
|
||||
|
||||
fn show_log(files: &Files, log: Sourced<'_, Log>) {
|
||||
let command = files.command(log.source);
|
||||
|
||||
println!("LOG {}", log.value.date);
|
||||
|
||||
println!("FROM COMMAND");
|
||||
show_command(command.value);
|
||||
}
|
||||
|
||||
fn show_ident(files: &Files, entries: &[Entry], layout: &LineLayout, ident: Ident) {
|
||||
match ident {
|
||||
Ident::Number(n) => match layout.look_up_number::<()>(n) {
|
||||
Ok(index) => show_entry(files, &entries[index]),
|
||||
Err(e) => println!("{}", e),
|
||||
},
|
||||
Ident::Date(date) => match files.log(date) {
|
||||
Some(log) => show_log(files, log),
|
||||
None => println!("{}", Error::NoSuchLog::<()>(date)),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn show<S>(
|
||||
files: &Files,
|
||||
entries: &[Entry],
|
||||
layout: &LineLayout,
|
||||
numbers: &[usize],
|
||||
) -> Result<(), Error<S>> {
|
||||
if numbers.is_empty() {
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum Ident {
|
||||
Number(usize),
|
||||
Date(NaiveDate),
|
||||
}
|
||||
|
||||
pub fn show(files: &Files, entries: &[Entry], layout: &LineLayout, idents: &[Ident]) {
|
||||
if idents.is_empty() {
|
||||
// Nothing to do
|
||||
return Ok(());
|
||||
return;
|
||||
}
|
||||
|
||||
let indices = numbers
|
||||
.iter()
|
||||
.map(|n| layout.look_up_number(*n))
|
||||
.collect::<Result<Vec<usize>, _>>()?;
|
||||
|
||||
show_entry(files, &entries[indices[0]]);
|
||||
for &index in indices.iter().skip(1) {
|
||||
show_ident(files, entries, layout, idents[0]);
|
||||
for &ident in idents.iter().skip(1) {
|
||||
println!();
|
||||
show_entry(files, &entries[index]);
|
||||
show_ident(files, entries, layout, ident);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue