jrnl: put modules in its own respective files
This commit is contained in:
parent
78bb79e258
commit
df13761fc8
5 changed files with 101 additions and 105 deletions
20
programs/jrnl/src/commands/list_entries.rs
Normal file
20
programs/jrnl/src/commands/list_entries.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
use owo_colors::OwoColorize;
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
use crate::md::Doc;
|
||||
|
||||
pub fn list_entries(path: PathBuf) {
|
||||
let file = fs::read_to_string(path).unwrap();
|
||||
let doc = Doc::new(&file);
|
||||
|
||||
for (i, entry) in doc.entries.into_iter().enumerate() {
|
||||
let n = format!("{:>2}", i + 1);
|
||||
let r = format!(". {}", entry.title,);
|
||||
let l = format!(" {} ", crate::utils::format_datetime(entry.timestamp));
|
||||
let termsize::Size { cols, .. } = termsize::get().unwrap();
|
||||
|
||||
let padding = " ".repeat(cols as usize - (n.len() + r.len() + l.len()));
|
||||
|
||||
println!("{}{r}{padding}{}", n.cyan(), l.white())
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue