jrnl: adding entries now works!!
This commit is contained in:
parent
b967f6e90e
commit
aaec1f1f78
5 changed files with 89 additions and 13 deletions
|
@ -1,22 +1,23 @@
|
|||
use owo_colors::OwoColorize;
|
||||
use std::{fs, path::PathBuf};
|
||||
use std::{fs, io, path::PathBuf};
|
||||
|
||||
use crate::md::Doc;
|
||||
|
||||
pub fn list_entries(path: PathBuf) {
|
||||
let file = fs::read_to_string(path).unwrap();
|
||||
pub fn list_entries(path: PathBuf) -> io::Result<()> {
|
||||
let file = fs::read_to_string(path)?;
|
||||
|
||||
if let Some(doc) = Doc::new(&file) {
|
||||
let termsize::Size { cols, .. } = termsize::get().unwrap();
|
||||
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())
|
||||
}
|
||||
Ok(())
|
||||
} else {
|
||||
eprintln!("Parsing error...");
|
||||
std::process::exit(1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue