Use new format syntax in most places
This commit is contained in:
parent
a3a0e0b9cf
commit
f82b368fe1
10 changed files with 120 additions and 127 deletions
|
|
@ -45,8 +45,8 @@ where
|
|||
Error::Eval(e) => e.eprint(files, config),
|
||||
Error::ArgumentParse { file, error } => error.eprint(file, config),
|
||||
Error::ArgumentEval { file, error } => error.eprint(file, config),
|
||||
Error::NoSuchEntry(n) => eprintln!("No entry with number {}", n),
|
||||
Error::NoSuchLog(date) => eprintln!("No log for {}", date),
|
||||
Error::NoSuchEntry(n) => eprintln!("No entry with number {n}"),
|
||||
Error::NoSuchLog(date) => eprintln!("No log for {date}"),
|
||||
Error::NotATask(ns) => {
|
||||
if ns.is_empty() {
|
||||
eprintln!("Not a task.");
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ impl LineLayout {
|
|||
let extra = if *d == 1 {
|
||||
"yesterday".to_string()
|
||||
} else {
|
||||
format!("{} days ago", d)
|
||||
format!("{d} days ago")
|
||||
};
|
||||
self.line_entry(entries, *i, Times::Untimed, Some(extra));
|
||||
}
|
||||
|
|
@ -194,7 +194,7 @@ impl LineLayout {
|
|||
}
|
||||
DayEntry::ReminderWhile(i, d) => {
|
||||
let plural = if *d == 1 { "" } else { "s" };
|
||||
let extra = format!("{} day{} left", d, plural);
|
||||
let extra = format!("{d} day{plural} left");
|
||||
self.line_entry(entries, *i, Times::Untimed, Some(extra));
|
||||
}
|
||||
DayEntry::Undated(i) => {
|
||||
|
|
@ -208,7 +208,7 @@ impl LineLayout {
|
|||
let extra = if *d == 1 {
|
||||
"tomorrow".to_string()
|
||||
} else {
|
||||
format!("in {} days", d)
|
||||
format!("in {d} days")
|
||||
};
|
||||
self.line_entry(entries, *i, Times::Untimed, Some(extra));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,28 +63,25 @@ impl ShowLines {
|
|||
};
|
||||
|
||||
// '=' symbols before the spans start
|
||||
let p1 = format!("{:=<w$}=", "", w = self.num_width);
|
||||
let p1 = styled(&format!("{:=<w$}=", "", w = self.num_width));
|
||||
|
||||
// Spans and filler '=' symbols
|
||||
let p2 = self.display_spans(spans, styled("="));
|
||||
|
||||
// The rest of the line until after the date
|
||||
let p3 = format!("=== {:9} {}", weekday, date,);
|
||||
let p3 = styled(&format!("=== {weekday:9} {date}"));
|
||||
|
||||
// The "has log" marker (if any)
|
||||
let p4 = Self::display_marker(has_log, " ");
|
||||
|
||||
// The rest of the line
|
||||
let p5 = format!(" ===={:=<w$}", "", w = self.num_width + self.span_width);
|
||||
|
||||
self.push(&format!(
|
||||
"{}{}{}{}{}\n",
|
||||
styled(&p1),
|
||||
p2,
|
||||
styled(&p3),
|
||||
p4,
|
||||
styled(&p5)
|
||||
let p5 = styled(&format!(
|
||||
" ===={:=<w$}",
|
||||
"",
|
||||
w = self.num_width + self.span_width
|
||||
));
|
||||
|
||||
self.push(&format!("{p1}{p2}{p3}{p4}{p5}\n"));
|
||||
}
|
||||
|
||||
fn display_line_now(&mut self, spans: &[Option<SpanSegment>], time: Time) {
|
||||
|
|
@ -109,7 +106,7 @@ impl ShowLines {
|
|||
extra: &Option<String>,
|
||||
) {
|
||||
let num = match number {
|
||||
Some(n) => format!("{}", n),
|
||||
Some(n) => format!("{n}"),
|
||||
None => "".to_string(),
|
||||
};
|
||||
|
||||
|
|
@ -137,9 +134,9 @@ impl ShowLines {
|
|||
SpanSegment::Middle(SpanStyle::Dotted) => "┊".bright_black(),
|
||||
SpanSegment::End(_) => "└".bright_black(),
|
||||
};
|
||||
result.push_str(&format!("{}", colored_str));
|
||||
result.push_str(&format!("{colored_str}"));
|
||||
} else {
|
||||
result.push_str(&format!("{}", empty));
|
||||
result.push_str(&format!("{empty}"));
|
||||
}
|
||||
}
|
||||
result
|
||||
|
|
@ -148,8 +145,8 @@ impl ShowLines {
|
|||
fn display_time(time: Times) -> ColoredString {
|
||||
match time {
|
||||
Times::Untimed => "".into(),
|
||||
Times::At(t) => format!(" {}", t).bright_black(),
|
||||
Times::FromTo(t1, t2) => format!(" {}--{}", t1, t2).bright_black(),
|
||||
Times::At(t) => format!(" {t}").bright_black(),
|
||||
Times::FromTo(t1, t2) => format!(" {t1}--{t2}").bright_black(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -164,7 +161,7 @@ impl ShowLines {
|
|||
fn display_extra(extra: &Option<String>) -> ColoredString {
|
||||
match extra {
|
||||
None => "".into(),
|
||||
Some(extra) => format!(" ({})", extra).bright_black(),
|
||||
Some(extra) => format!(" ({extra})").bright_black(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@ fn fmt_where(files: &Files, command: &Sourced<'_, Spanned<Command>>) -> String {
|
|||
let line = files
|
||||
.line_index(command.source.file(), command.value.span.start)
|
||||
.expect("file exists and line is valid");
|
||||
format!("Line {} in {}", line + 1, name)
|
||||
let line = line + 1; // 1-indexed for human consumption
|
||||
format!("Line {line} in {name}")
|
||||
}
|
||||
|
||||
fn print_desc(command: &Sourced<'_, Spanned<Command>>) {
|
||||
|
|
@ -42,11 +43,11 @@ fn show_entry(files: &Files, entry: &Entry) {
|
|||
|
||||
let what = match entry.kind {
|
||||
EntryKind::Task => "Task".to_string(),
|
||||
EntryKind::TaskDone(date) => format!("Task, done {}", date),
|
||||
EntryKind::TaskCanceled(date) => format!("Task, canceled {}", date),
|
||||
EntryKind::TaskDone(date) => format!("Task, done {date}"),
|
||||
EntryKind::TaskCanceled(date) => format!("Task, canceled {date}"),
|
||||
EntryKind::Note => "Note".to_string(),
|
||||
EntryKind::Birthday(None) => "Birthday, age unknown".to_string(),
|
||||
EntryKind::Birthday(Some(age)) => format!("Birthday, age {}", age),
|
||||
EntryKind::Birthday(Some(age)) => format!("Birthday, age {age}"),
|
||||
};
|
||||
println!("{} {}", "What:".bright_black(), what);
|
||||
|
||||
|
|
@ -76,7 +77,7 @@ fn show_ident(files: &Files, entries: &[Entry], layout: &LineLayout, ident: Iden
|
|||
match ident {
|
||||
Ident::Number(n) => match layout.look_up_number(n) {
|
||||
Ok(index) => show_entry(files, &entries[index]),
|
||||
Err(e) => println!("{}", e),
|
||||
Err(e) => println!("{e}"),
|
||||
},
|
||||
Ident::Date(date) => match files.log(date) {
|
||||
Some(log) => show_log(files, log),
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ pub trait Eprint<'a, F: Files<'a>> {
|
|||
) {
|
||||
let mut out = StandardStream::stderr(termcolor::ColorChoice::Auto);
|
||||
if let Err(e) = term::emit(&mut out, config, files, diagnostic) {
|
||||
panic!("Error while reporting error: {}", e);
|
||||
panic!("Error while reporting error: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -391,7 +391,7 @@ mod tests {
|
|||
if let Ok(result) = expr.eval((), date) {
|
||||
assert_eq!(result, target);
|
||||
} else {
|
||||
panic!("formula produced error for day {}", date);
|
||||
panic!("formula produced error for day {date}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -106,8 +106,8 @@ impl<'a, F: Files<'a>> Eprint<'a, F> for Error<F::FileId> {
|
|||
Label::primary(*index, span).with_message("At this step")
|
||||
])
|
||||
.with_notes(vec![
|
||||
format!("Date before applying delta: {}", start_str),
|
||||
format!("Date before applying this step: {}", prev_str),
|
||||
format!("Date before applying delta: {start_str}"),
|
||||
format!("Date before applying this step: {prev_str}"),
|
||||
])
|
||||
}
|
||||
Error::DeltaNoTime {
|
||||
|
|
@ -121,8 +121,8 @@ impl<'a, F: Files<'a>> Eprint<'a, F> for Error<F::FileId> {
|
|||
Label::primary(*index, span).with_message("At this step")
|
||||
])
|
||||
.with_notes(vec![
|
||||
format!("Date before applying delta: {}", start),
|
||||
format!("Date before applying this step: {}", prev),
|
||||
format!("Date before applying delta: {start}"),
|
||||
format!("Date before applying this step: {prev}"),
|
||||
]),
|
||||
Error::RepeatDidNotMoveForwards {
|
||||
index,
|
||||
|
|
@ -132,7 +132,7 @@ impl<'a, F: Files<'a>> Eprint<'a, F> for Error<F::FileId> {
|
|||
} => Diagnostic::error()
|
||||
.with_message("Repeat delta did not move forwards")
|
||||
.with_labels(vec![Label::primary(*index, span).with_message("This delta")])
|
||||
.with_notes(vec![format!("Moved from {} to {}", from, to)]),
|
||||
.with_notes(vec![format!("Moved from {from} to {to}")]),
|
||||
Error::RemindDidNotMoveBackwards {
|
||||
index,
|
||||
span,
|
||||
|
|
@ -141,7 +141,7 @@ impl<'a, F: Files<'a>> Eprint<'a, F> for Error<F::FileId> {
|
|||
} => Diagnostic::error()
|
||||
.with_message("Remind delta did not move backwards")
|
||||
.with_labels(vec![Label::primary(*index, span).with_message("This delta")])
|
||||
.with_notes(vec![format!("Moved from {} to {}", from, to)]),
|
||||
.with_notes(vec![format!("Moved from {from} to {to}")]),
|
||||
Error::MoveWithoutSource { index, span } => Diagnostic::error()
|
||||
.with_message("Tried to move nonexistent entry")
|
||||
.with_labels(vec![Label::primary(*index, span).with_message("Here")]),
|
||||
|
|
@ -153,13 +153,13 @@ impl<'a, F: Files<'a>> Eprint<'a, F> for Error<F::FileId> {
|
|||
.with_labels(vec![
|
||||
Label::primary(*index, span).with_message("This expression")
|
||||
])
|
||||
.with_notes(vec![format!("At date: {}", date)]),
|
||||
.with_notes(vec![format!("At date: {date}")]),
|
||||
Error::ModByZero { index, span, date } => Diagnostic::error()
|
||||
.with_message("Tried to modulo by zero")
|
||||
.with_labels(vec![
|
||||
Label::primary(*index, span).with_message("This expression")
|
||||
])
|
||||
.with_notes(vec![format!("At date: {}", date)]),
|
||||
.with_notes(vec![format!("At date: {date}")]),
|
||||
Error::Easter {
|
||||
index,
|
||||
span,
|
||||
|
|
@ -170,10 +170,7 @@ impl<'a, F: Files<'a>> Eprint<'a, F> for Error<F::FileId> {
|
|||
.with_labels(vec![
|
||||
Label::primary(*index, span).with_message("This expression")
|
||||
])
|
||||
.with_notes(vec![
|
||||
format!("At date: {}", date),
|
||||
format!("Reason: {}", msg),
|
||||
]),
|
||||
.with_notes(vec![format!("At date: {date}"), format!("Reason: {msg}")]),
|
||||
};
|
||||
Self::eprint_diagnostic(files, config, &diagnostic);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ impl<S> ParseError<S> {
|
|||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
let last = Self::rule_name(rules[n - 1]);
|
||||
format!("{} or {}", except_last, last)
|
||||
format!("{except_last} or {last}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -76,7 +76,7 @@ where
|
|||
};
|
||||
let name = files.name(self.file).expect("file exists");
|
||||
let diagnostic = Diagnostic::error()
|
||||
.with_message(format!("Could not parse {}", name))
|
||||
.with_message(format!("Could not parse {name}"))
|
||||
.with_labels(vec![Label::primary(self.file, range)])
|
||||
.with_notes(self.notes());
|
||||
Self::eprint_diagnostic(files, config, &diagnostic);
|
||||
|
|
@ -135,16 +135,16 @@ impl<'a> Eprint<'a, Files> for Error {
|
|||
fn eprint<'f: 'a>(&self, files: &'f Files, config: &Config) {
|
||||
match self {
|
||||
Error::ResolvePath { path, error } => {
|
||||
eprintln!("Could not resolve path {:?}:", path);
|
||||
eprintln!(" {}", error);
|
||||
eprintln!("Could not resolve path {path:?}:");
|
||||
eprintln!(" {error}");
|
||||
}
|
||||
Error::ReadFile { file, error } => {
|
||||
eprintln!("Could not read file {:?}:", file);
|
||||
eprintln!(" {}", error);
|
||||
eprintln!("Could not read file {file:?}:");
|
||||
eprintln!(" {error}");
|
||||
}
|
||||
Error::WriteFile { file, error } => {
|
||||
eprintln!("Could not write file {:?}:", file);
|
||||
eprintln!(" {}", error);
|
||||
eprintln!("Could not write file {file:?}:");
|
||||
eprintln!(" {error}");
|
||||
}
|
||||
Error::ResolveTz {
|
||||
file,
|
||||
|
|
@ -153,16 +153,16 @@ impl<'a> Eprint<'a, Files> for Error {
|
|||
error,
|
||||
} => {
|
||||
let diagnostic = Diagnostic::error()
|
||||
.with_message(format!("Could not resolve time zone {}", tz))
|
||||
.with_message(format!("Could not resolve time zone {tz}"))
|
||||
.with_labels(vec![
|
||||
Label::primary(*file, span).with_message("Time zone defined here")
|
||||
])
|
||||
.with_notes(vec![format!("{}", error)]);
|
||||
.with_notes(vec![format!("{error}")]);
|
||||
Self::eprint_diagnostic(files, config, &diagnostic);
|
||||
}
|
||||
Error::LocalTz { error } => {
|
||||
eprintln!("Could not determine local timezone:");
|
||||
eprintln!(" {}", error);
|
||||
eprintln!(" {error}");
|
||||
}
|
||||
Error::Parse { file, error } => {
|
||||
ParseError::new(*file, error.clone()).eprint(files, config)
|
||||
|
|
@ -176,7 +176,7 @@ impl<'a> Eprint<'a, Files> for Error {
|
|||
tz2,
|
||||
} => {
|
||||
let diagnostic = Diagnostic::error()
|
||||
.with_message(format!("Time zone conflict between {} and {}", tz1, tz2))
|
||||
.with_message(format!("Time zone conflict between {tz1} and {tz2}"))
|
||||
.with_labels(vec![
|
||||
Label::primary(*file1, span1).with_message("Time zone defined here"),
|
||||
Label::primary(*file2, span2).with_message("Time zone defined here"),
|
||||
|
|
@ -211,7 +211,7 @@ impl<'a> Eprint<'a, Files> for Error {
|
|||
date,
|
||||
} => {
|
||||
let diagnostic = Diagnostic::error()
|
||||
.with_message(format!("Duplicate log entries for {}", date))
|
||||
.with_message(format!("Duplicate log entries for {date}"))
|
||||
.with_labels(vec![
|
||||
Label::primary(*file1, span1).with_message("Log defined here"),
|
||||
Label::primary(*file2, span2).with_message("Log defined here"),
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ fn format_desc(f: &mut fmt::Formatter<'_>, desc: &[String]) -> fmt::Result {
|
|||
if line.is_empty() {
|
||||
writeln!(f, "#")?;
|
||||
} else {
|
||||
writeln!(f, "# {}", line)?;
|
||||
writeln!(f, "# {line}")?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
@ -76,29 +76,29 @@ impl fmt::Display for DateSpec {
|
|||
// Start
|
||||
write!(f, "{}", self.start)?;
|
||||
for delta in &self.start_delta {
|
||||
write!(f, " {}", delta)?;
|
||||
write!(f, " {delta}")?;
|
||||
}
|
||||
for time in &self.start_time {
|
||||
write!(f, " {}", time)?;
|
||||
write!(f, " {time}")?;
|
||||
}
|
||||
|
||||
// End
|
||||
if self.end.is_some() || self.end_delta.is_some() || self.end_time.is_some() {
|
||||
write!(f, " --")?;
|
||||
if let Some(date) = self.end {
|
||||
write!(f, " {}", date)?;
|
||||
write!(f, " {date}")?;
|
||||
}
|
||||
if let Some(delta) = &self.end_delta {
|
||||
write!(f, " {}", delta)?;
|
||||
write!(f, " {delta}")?;
|
||||
}
|
||||
if let Some(time) = &self.end_time {
|
||||
write!(f, " {}", time)?;
|
||||
write!(f, " {time}")?;
|
||||
}
|
||||
}
|
||||
|
||||
// Repeat
|
||||
if let Some(repeat) = &self.repeat {
|
||||
write!(f, "; {}", repeat)?;
|
||||
write!(f, "; {repeat}")?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
@ -110,20 +110,20 @@ impl fmt::Display for WeekdaySpec {
|
|||
// Start
|
||||
write!(f, "{}", self.start)?;
|
||||
for time in &self.start_time {
|
||||
write!(f, " {}", time)?;
|
||||
write!(f, " {time}")?;
|
||||
}
|
||||
|
||||
// End
|
||||
if self.end.is_some() || self.end_delta.is_some() || self.end_time.is_some() {
|
||||
write!(f, " --")?;
|
||||
if let Some(wd) = self.end {
|
||||
write!(f, " {}", wd)?;
|
||||
write!(f, " {wd}")?;
|
||||
}
|
||||
if let Some(delta) = &self.end_delta {
|
||||
write!(f, " {}", delta)?;
|
||||
write!(f, " {delta}")?;
|
||||
}
|
||||
if let Some(time) = &self.end_time {
|
||||
write!(f, " {}", time)?;
|
||||
write!(f, " {time}")?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -140,25 +140,25 @@ impl fmt::Display for Var {
|
|||
impl fmt::Display for Expr {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Expr::Lit(i) => write!(f, "{}", i),
|
||||
Expr::Var(v) => write!(f, "{}", v),
|
||||
Expr::Paren(e) => write!(f, "({})", e),
|
||||
Expr::Neg(e) => write!(f, "-{}", e),
|
||||
Expr::Add(a, b) => write!(f, "{} + {}", a, b),
|
||||
Expr::Sub(a, b) => write!(f, "{} - {}", a, b),
|
||||
Expr::Mul(a, b) => write!(f, "{} * {}", a, b),
|
||||
Expr::Div(a, b) => write!(f, "{} / {}", a, b),
|
||||
Expr::Mod(a, b) => write!(f, "{} % {}", a, b),
|
||||
Expr::Eq(a, b) => write!(f, "{} = {}", a, b),
|
||||
Expr::Neq(a, b) => write!(f, "{} != {}", a, b),
|
||||
Expr::Lt(a, b) => write!(f, "{} < {}", a, b),
|
||||
Expr::Lte(a, b) => write!(f, "{} <= {}", a, b),
|
||||
Expr::Gt(a, b) => write!(f, "{} > {}", a, b),
|
||||
Expr::Gte(a, b) => write!(f, "{} >= {}", a, b),
|
||||
Expr::Not(e) => write!(f, "!{}", e),
|
||||
Expr::And(a, b) => write!(f, "{} & {}", a, b),
|
||||
Expr::Or(a, b) => write!(f, "{} | {}", a, b),
|
||||
Expr::Xor(a, b) => write!(f, "{} ^ {}", a, b),
|
||||
Expr::Lit(i) => write!(f, "{i}"),
|
||||
Expr::Var(v) => write!(f, "{v}"),
|
||||
Expr::Paren(e) => write!(f, "({e})"),
|
||||
Expr::Neg(e) => write!(f, "-{e}"),
|
||||
Expr::Add(a, b) => write!(f, "{a} + {b}"),
|
||||
Expr::Sub(a, b) => write!(f, "{a} - {b}"),
|
||||
Expr::Mul(a, b) => write!(f, "{a} * {b}"),
|
||||
Expr::Div(a, b) => write!(f, "{a} / {b}"),
|
||||
Expr::Mod(a, b) => write!(f, "{a} % {b}"),
|
||||
Expr::Eq(a, b) => write!(f, "{a} = {b}"),
|
||||
Expr::Neq(a, b) => write!(f, "{a} != {b}"),
|
||||
Expr::Lt(a, b) => write!(f, "{a} < {b}"),
|
||||
Expr::Lte(a, b) => write!(f, "{a} <= {b}"),
|
||||
Expr::Gt(a, b) => write!(f, "{a} > {b}"),
|
||||
Expr::Gte(a, b) => write!(f, "{a} >= {b}"),
|
||||
Expr::Not(e) => write!(f, "!{e}"),
|
||||
Expr::And(a, b) => write!(f, "{a} & {b}"),
|
||||
Expr::Or(a, b) => write!(f, "{a} | {b}"),
|
||||
Expr::Xor(a, b) => write!(f, "{a} ^ {b}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -167,25 +167,25 @@ impl fmt::Display for FormulaSpec {
|
|||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
// Start
|
||||
if let Some(expr) = &self.start {
|
||||
write!(f, "({})", expr)?;
|
||||
write!(f, "({expr})")?;
|
||||
} else {
|
||||
write!(f, "*")?;
|
||||
}
|
||||
for delta in &self.start_delta {
|
||||
write!(f, " {}", delta)?;
|
||||
write!(f, " {delta}")?;
|
||||
}
|
||||
for time in &self.start_time {
|
||||
write!(f, " {}", time)?;
|
||||
write!(f, " {time}")?;
|
||||
}
|
||||
|
||||
// End
|
||||
if self.end_delta.is_some() || self.end_time.is_some() {
|
||||
write!(f, " --")?;
|
||||
if let Some(delta) = &self.end_delta {
|
||||
write!(f, " {}", delta)?;
|
||||
write!(f, " {delta}")?;
|
||||
}
|
||||
if let Some(time) = &self.end_time {
|
||||
write!(f, " {}", time)?;
|
||||
write!(f, " {time}")?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -196,9 +196,9 @@ impl fmt::Display for FormulaSpec {
|
|||
impl fmt::Display for Spec {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Spec::Date(spec) => write!(f, "{}", spec),
|
||||
Spec::Weekday(spec) => write!(f, "{}", spec),
|
||||
Spec::Formula(spec) => write!(f, "{}", spec),
|
||||
Spec::Date(spec) => write!(f, "{spec}"),
|
||||
Spec::Weekday(spec) => write!(f, "{spec}"),
|
||||
Spec::Formula(spec) => write!(f, "{spec}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -216,22 +216,22 @@ impl fmt::Display for BirthdaySpec {
|
|||
impl fmt::Display for Statement {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Statement::Date(spec) => writeln!(f, "DATE {}", spec),
|
||||
Statement::BDate(spec) => writeln!(f, "BDATE {}", spec),
|
||||
Statement::From(Some(date)) => writeln!(f, "FROM {}", date),
|
||||
Statement::Date(spec) => writeln!(f, "DATE {spec}"),
|
||||
Statement::BDate(spec) => writeln!(f, "BDATE {spec}"),
|
||||
Statement::From(Some(date)) => writeln!(f, "FROM {date}"),
|
||||
Statement::From(None) => writeln!(f, "FROM *"),
|
||||
Statement::Until(Some(date)) => writeln!(f, "UNTIL {}", date),
|
||||
Statement::Until(Some(date)) => writeln!(f, "UNTIL {date}"),
|
||||
Statement::Until(None) => writeln!(f, "UNTIL *"),
|
||||
Statement::Except(date) => writeln!(f, "EXCEPT {}", date),
|
||||
Statement::Except(date) => writeln!(f, "EXCEPT {date}"),
|
||||
Statement::Move {
|
||||
from, to, to_time, ..
|
||||
} => match (to, to_time) {
|
||||
(None, None) => unreachable!(),
|
||||
(Some(to), None) => writeln!(f, "MOVE {} TO {}", from, to),
|
||||
(None, Some(to_time)) => writeln!(f, "MOVE {} TO {}", from, to_time),
|
||||
(Some(to), Some(to_time)) => writeln!(f, "MOVE {} TO {} {}", from, to, to_time),
|
||||
(Some(to), None) => writeln!(f, "MOVE {from} TO {to}"),
|
||||
(None, Some(to_time)) => writeln!(f, "MOVE {from} TO {to_time}"),
|
||||
(Some(to), Some(to_time)) => writeln!(f, "MOVE {from} TO {to} {to_time}"),
|
||||
},
|
||||
Statement::Remind(Some(delta)) => writeln!(f, "REMIND {}", delta),
|
||||
Statement::Remind(Some(delta)) => writeln!(f, "REMIND {delta}"),
|
||||
Statement::Remind(None) => writeln!(f, "REMIND *"),
|
||||
}
|
||||
}
|
||||
|
|
@ -240,20 +240,20 @@ impl fmt::Display for Statement {
|
|||
impl fmt::Display for DoneDate {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self.simplified() {
|
||||
DoneDate::Date { root } => write!(f, "{}", root),
|
||||
DoneDate::DateTime { root, root_time } => write!(f, "{} {}", root, root_time),
|
||||
DoneDate::DateToDate { root, other } => write!(f, "{} -- {}", root, other),
|
||||
DoneDate::Date { root } => write!(f, "{root}"),
|
||||
DoneDate::DateTime { root, root_time } => write!(f, "{root} {root_time}"),
|
||||
DoneDate::DateToDate { root, other } => write!(f, "{root} -- {other}"),
|
||||
DoneDate::DateTimeToTime {
|
||||
root,
|
||||
root_time,
|
||||
other_time,
|
||||
} => write!(f, "{} {} -- {}", root, root_time, other_time),
|
||||
} => write!(f, "{root} {root_time} -- {other_time}"),
|
||||
DoneDate::DateTimeToDateTime {
|
||||
root,
|
||||
root_time,
|
||||
other,
|
||||
other_time,
|
||||
} => write!(f, "{} {} -- {} {}", root, root_time, other, other_time),
|
||||
} => write!(f, "{root} {root_time} -- {other} {other_time}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -264,9 +264,9 @@ impl fmt::Display for Done {
|
|||
DoneKind::Done => "DONE",
|
||||
DoneKind::Canceled => "CANCELED",
|
||||
};
|
||||
write!(f, "{} [{}]", kind, self.done_at)?;
|
||||
write!(f, "{kind} [{}]", self.done_at)?;
|
||||
if let Some(date) = &self.date {
|
||||
write!(f, " {}", date)?;
|
||||
write!(f, " {date}")?;
|
||||
}
|
||||
writeln!(f)
|
||||
}
|
||||
|
|
@ -276,10 +276,10 @@ impl fmt::Display for Task {
|
|||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
writeln!(f, "TASK {}", self.title)?;
|
||||
for statement in &self.statements {
|
||||
write!(f, "{}", statement)?;
|
||||
write!(f, "{statement}")?;
|
||||
}
|
||||
for done in &self.done {
|
||||
write!(f, "{}", done)?;
|
||||
write!(f, "{done}")?;
|
||||
}
|
||||
format_desc(f, &self.desc)?;
|
||||
Ok(())
|
||||
|
|
@ -290,26 +290,13 @@ impl fmt::Display for Note {
|
|||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
writeln!(f, "NOTE {}", self.title)?;
|
||||
for statement in &self.statements {
|
||||
write!(f, "{}", statement)?;
|
||||
write!(f, "{statement}")?;
|
||||
}
|
||||
format_desc(f, &self.desc)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Command {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Command::Include(name) => writeln!(f, "INCLUDE {}", name),
|
||||
Command::Timezone(name) => writeln!(f, "TIMEZONE {}", name),
|
||||
Command::Capture => writeln!(f, "CAPTURE"),
|
||||
Command::Task(task) => write!(f, "{}", task),
|
||||
Command::Note(note) => write!(f, "{}", note),
|
||||
Command::Log(log) => write!(f, "{}", log),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Log {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
writeln!(f, "LOG {}", self.date)?;
|
||||
|
|
@ -318,6 +305,19 @@ impl fmt::Display for Log {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Command {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Command::Include(name) => writeln!(f, "INCLUDE {name}"),
|
||||
Command::Timezone(name) => writeln!(f, "TIMEZONE {name}"),
|
||||
Command::Capture => writeln!(f, "CAPTURE"),
|
||||
Command::Task(task) => write!(f, "{task}"),
|
||||
Command::Note(note) => write!(f, "{note}"),
|
||||
Command::Log(log) => write!(f, "{log}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl File {
|
||||
fn sort(commands: &mut Vec<&Command>) {
|
||||
// Order of commands in a file:
|
||||
|
|
@ -372,7 +372,7 @@ impl File {
|
|||
let curr = &commands[i];
|
||||
let next = commands.get(i + 1);
|
||||
|
||||
result.push_str(&format!("{}", curr));
|
||||
result.push_str(&format!("{curr}"));
|
||||
|
||||
match (curr, next) {
|
||||
(Command::Include(_), Some(Command::Include(_))) => {}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
#![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