Prepare string editing for 'today new'
This commit is contained in:
parent
82affe39a1
commit
fe1bf309b8
4 changed files with 20 additions and 9 deletions
|
|
@ -28,8 +28,8 @@ pub enum Error {
|
|||
NoSuchLog(NaiveDate),
|
||||
#[error("Not a task")]
|
||||
NotATask(Vec<usize>),
|
||||
#[error("Error editing log for {date}: {error}")]
|
||||
EditingLog { date: NaiveDate, error: io::Error },
|
||||
#[error("Error editing: {0}")]
|
||||
EditingIo(io::Error),
|
||||
}
|
||||
|
||||
pub type Result<T> = result::Result<T, Error>;
|
||||
|
|
@ -55,9 +55,9 @@ where
|
|||
eprintln!("{} are not tasks.", ns.join(", "));
|
||||
}
|
||||
}
|
||||
Error::EditingLog { date, error } => {
|
||||
eprintln!("Error editing log for {}", date);
|
||||
eprintln!(" {}", error);
|
||||
Error::EditingIo(error) => {
|
||||
eprintln!("Error while editing:");
|
||||
eprintln!(" {error}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ use chrono::NaiveDate;
|
|||
use crate::files::Files;
|
||||
|
||||
use super::error::Error;
|
||||
use super::util;
|
||||
|
||||
pub fn log(files: &mut Files, date: NaiveDate) -> Result<(), Error> {
|
||||
let desc = files
|
||||
|
|
@ -10,10 +11,7 @@ pub fn log(files: &mut Files, date: NaiveDate) -> Result<(), Error> {
|
|||
.map(|log| log.value.desc.join("\n"))
|
||||
.unwrap_or_default();
|
||||
|
||||
let mut builder = edit::Builder::new();
|
||||
builder.suffix(".md");
|
||||
let edited = edit::edit_with_builder(desc, &builder)
|
||||
.map_err(|error| Error::EditingLog { date, error })?;
|
||||
let edited = util::edit_with_suffix(&desc, ".md")?;
|
||||
|
||||
let edited = edited
|
||||
.lines()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use colored::{ColoredString, Colorize};
|
||||
|
||||
use super::error::{Error, Result};
|
||||
use super::layout::line::LineKind;
|
||||
|
||||
pub fn display_kind(kind: LineKind) -> ColoredString {
|
||||
|
|
@ -11,3 +12,13 @@ pub fn display_kind(kind: LineKind) -> ColoredString {
|
|||
LineKind::Birthday => "B".yellow().bold(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn edit(input: &str) -> Result<String> {
|
||||
edit::edit(input).map_err(Error::EditingIo)
|
||||
}
|
||||
|
||||
pub fn edit_with_suffix(input: &str, suffix: &str) -> Result<String> {
|
||||
let mut builder = edit::Builder::new();
|
||||
builder.suffix(suffix);
|
||||
edit::edit_with_builder(input, &builder).map_err(Error::EditingIo)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
#![warn(clippy::all)]
|
||||
#![warn(clippy::use_self)]
|
||||
|
||||
// TODO Switch to new format syntax project-wide
|
||||
|
||||
mod cli;
|
||||
mod error;
|
||||
mod eval;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue