jj/src
Martin von Zweigbergk a061ac022e formatter: add a with_label() helper
There's a risk of forgetting to call `remove_label()` and I've wanted
to reduce that risk for a long time. I considered creating RAII
adapters that implement `Drop`, but I didn't like that that would
ignore errors (such as `BrokenPipe`) that can happen while emitting an
escape sequence in `remove_label()`. I would ideally have liked
Python's context managers here, but Rust doesn't have that. Instead,
we get to use closures. That works pretty well, except that we can't
return other errors than `io::Error` inside the closures. Even with
that limitation, we can use the new `with_label()` method in all but a
few cases.

We can't define the `with_label()` method directly in the trait
because `&mut self` is not a trait object, so we can't pass it on to
the closure (which expects a trait object). The solution is to use
`impl dyn Formatter` (thanks to @kupiakos for figuring that
out!). That unfortunately means that we can *only* call the function
on trait objects, so if `f` is a concrete formatter type
(e.g. `PlainTextFormatter`), then `f.with_label()` won't
compile. Since we only ever access the formatters as trait objects,
that's not really a problem, however.
2022-10-13 19:27:18 -07:00
..
cli_util.rs cli: remove early return after merging operations 2022-10-12 06:22:38 -07:00
commands.rs formatter: add a with_label() helper 2022-10-13 19:27:18 -07:00
config.rs Fix typo in error message 2022-09-14 15:29:53 -07:00
diff_edit.rs working_copy: remove return value from TreeState::snapshot() 2022-10-02 15:15:18 +09:00
formatter.rs formatter: add a with_label() helper 2022-10-13 19:27:18 -07:00
graphlog.rs graphlog: use usize::from(:bool) to convert boolean to integer 2022-10-09 12:20:15 -07:00
lib.rs cli: extract new cli_util module 2022-09-24 07:28:10 -07:00
main.rs cli: don't call process::exit() in create_ui() 2022-09-25 19:43:47 -07:00
template.pest import commit 0f15be02bf4012c116636913562691a0aaa7aed2 from my hg repo 2020-12-12 00:23:38 -08:00
template_parser.rs backend: allow negative timestamps in commits and operations 2022-09-30 00:50:17 -07:00
templater.rs cli: pass formatter label by reference 2022-10-08 00:52:33 +09:00
ui.rs cli: fix --color=auto to not test isatty() unless initialized for terminal 2022-10-09 09:08:46 +09:00