1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use aurora_core::{AuroraResult, Pipeline, Value};
use std::fs;
use std::io::Write;
use std::path::PathBuf;
use std::time::{SystemTime, UNIX_EPOCH};
fn notes_path() -> PathBuf {
let home = std::env::var("HOME").unwrap_or_else(|_| "/tmp".into());
PathBuf::from(home).join(".cache").join("aurora").join("notes.txt")
}
fn ensure_dir(path: &PathBuf) -> AuroraResult<()> {
if let Some(parent) = path.parent() {
fs::create_dir_all(parent)
.map_err(|e| aurora_core::AuroraError::Io(e))?;
}
Ok(())
}
pub fn note_add(text: &[String]) -> AuroraResult<Pipeline> {
let path = notes_path();
ensure_dir(&path)?;
let timestamp = SystemTime::now()
.duration_since(UNIX_EPOCH)
.map(|d| d.as_secs())
.unwrap_or(0);
let line = format!("[{}] {}\n", timestamp, text.join(" "));
let mut file = fs::OpenOptions::new()
.create(true)
.append(true)
.open(&path)
.map_err(|e| aurora_core::AuroraError::Io(e))?;
file.write_all(line.as_bytes())
.map_err(|e| aurora_core::AuroraError::Io(e))?;
Ok(Pipeline::table(
vec!["action".into(), "note".into(), "file".into()],
vec![vec![
Value::String("add".into()),
Value::String(text.join(" ")),
Value::String(path.to_string_lossy().into()),
]],
))
}