2024-04-20 20:11:04 +02:00
|
|
|
use owo_colors::OwoColorize;
|
2025-04-25 17:09:58 +02:00
|
|
|
use std::{
|
|
|
|
fs, io,
|
|
|
|
path::{Path, PathBuf},
|
|
|
|
};
|
2024-04-20 20:11:04 +02:00
|
|
|
|
|
|
|
use crate::md::Doc;
|
|
|
|
|
2025-04-25 17:09:58 +02:00
|
|
|
pub fn list_entries(path: &Path) -> io::Result<()> {
|
2024-04-22 21:25:29 +02:00
|
|
|
let file = fs::read_to_string(path)?;
|
2024-04-20 20:11:04 +02:00
|
|
|
|
2024-04-22 11:15:45 +02:00
|
|
|
if let Some(doc) = Doc::new(&file) {
|
2024-10-11 08:49:54 +02:00
|
|
|
// TODO: testing, so this shit doesn't blow the fuck up in our face anymore
|
2024-04-22 21:25:29 +02:00
|
|
|
let termsize::Size { cols, .. } = termsize::get().unwrap();
|
2024-10-11 08:49:54 +02:00
|
|
|
assert!(cols > 0, "we don't have a terminal width.");
|
|
|
|
|
2024-04-22 11:15:45 +02:00
|
|
|
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));
|
2024-04-20 20:11:04 +02:00
|
|
|
|
2024-10-11 08:49:54 +02:00
|
|
|
let fuck_you_debugging = cols as usize - (n.len() + r.chars().count() + l.len());
|
|
|
|
let padding = " ".repeat(fuck_you_debugging);
|
2024-04-20 20:11:04 +02:00
|
|
|
|
2024-04-22 11:15:45 +02:00
|
|
|
println!("{}{r}{padding}{}", n.cyan(), l.white())
|
|
|
|
}
|
2024-04-22 21:25:29 +02:00
|
|
|
Ok(())
|
2024-04-22 11:15:45 +02:00
|
|
|
} else {
|
|
|
|
eprintln!("Parsing error...");
|
|
|
|
std::process::exit(1);
|
2024-04-20 20:11:04 +02:00
|
|
|
}
|
|
|
|
}
|