mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-27 06:27:43 +00:00
cli: format single revset resolution hint with reused template instance
I'm going to introduce two changes: 1. indent commit summary, 2. colorize output. The former can be implemented without using the templater API, but the latter can't.
This commit is contained in:
parent
96e0bc0bdd
commit
65ef700f94
1 changed files with 14 additions and 5 deletions
|
@ -795,11 +795,20 @@ impl WorkspaceCommandHelper {
|
|||
let mut iter = [commit0, commit1].into_iter().chain(iter);
|
||||
let commits: Vec<_> = iter.by_ref().take(5).try_collect()?;
|
||||
let elided = iter.next().is_some();
|
||||
let commits_summary = commits
|
||||
.iter()
|
||||
.map(|c| self.format_commit_summary(c))
|
||||
.join("\n")
|
||||
+ elided.then_some("\n...").unwrap_or_default();
|
||||
let commits_summary = {
|
||||
let template = self.commit_summary_template();
|
||||
let mut output = Vec::new();
|
||||
let mut formatter = PlainTextFormatter::new(&mut output);
|
||||
for commit in &commits {
|
||||
template.format(commit, &mut formatter).unwrap();
|
||||
writeln!(formatter).unwrap();
|
||||
}
|
||||
if elided {
|
||||
writeln!(formatter, "...").unwrap();
|
||||
}
|
||||
output.pop(); // drop last newline
|
||||
String::from_utf8(output).expect("template output should be utf-8 bytes")
|
||||
};
|
||||
if commits[0].change_id() == commits[1].change_id() {
|
||||
// Separate hint if there's commits with same change id
|
||||
cmd_err.add_hint(format!(
|
||||
|
|
Loading…
Reference in a new issue