Add line count to tree view
Diff
src/git.rs | 22 ++++++++++++++--------
statics/style.css | 39 +++++++++++++++++++++++++++++++++++++++
2 files changed, 50 insertions(+), 11 deletions(-)
@@ -1,9 +1,10 @@
use std::{
borrow::Cow,
collections::BTreeMap,
path::{Path, PathBuf},
sync::Arc,
time::Duration,
fmt::Write,
};
use arc_swap::ArcSwapOption;
@@ -580,7 +581,7 @@
.unwrap();
}
html_generator.finalize()
format!("<code>{}</code>", html_generator.finalize().replace('\n', "</code>\n<code>"))
}
#[instrument(skip(diff, syntax_set))]
@@ -588,14 +589,14 @@
let mut diff_output = String::new();
diff.print(DiffFormat::Patch, |delta, _diff_hunk, diff_line| {
let (class, prefix, should_highlight_as_source) = match diff_line.origin_value() {
DiffLineType::Addition => (Some("add-line"), "+", true),
DiffLineType::Deletion => (Some("remove-line"), "-", true),
DiffLineType::Context => (None, " ", true),
DiffLineType::AddEOFNL => (Some("remove-line"), "", false),
DiffLineType::DeleteEOFNL => (Some("add-line"), "", false),
DiffLineType::FileHeader => (Some("file-header"), "", false),
_ => (None, "", false),
let (class, should_highlight_as_source) = match diff_line.origin_value() {
DiffLineType::Addition => (Some("add-line"), true),
DiffLineType::Deletion => (Some("remove-line"), true),
DiffLineType::Context => (Some("context"), true),
DiffLineType::AddEOFNL => (Some("remove-line"), false),
DiffLineType::DeleteEOFNL => (Some("add-line"), false),
DiffLineType::FileHeader => (Some("file-header"), false),
_ => (None, false),
};
let line = std::str::from_utf8(diff_line.content()).unwrap();
@@ -618,9 +619,8 @@
.parse_html_for_line_which_includes_newline(line)
.unwrap();
if let Some(class) = class {
diff_output.push_str(&format!("<span class=\"diff-{class}\">"));
write!(diff_output, r#"<span class="diff-{class}">"#).unwrap();
}
diff_output.push_str(prefix);
diff_output.push_str(&html_generator.finalize());
if class.is_some() {
diff_output.push_str("</span>");
@@ -96,23 +96,62 @@
font-weight: bold;
}
pre {
height: 100%;
width: 100%;
margin: 0;
overflow: auto;
counter-reset: line;
}
code {
counter-increment: line;
}
code::before {
content: counter(line);
display: inline-block;
width: 2em;
padding: 0 1em 0.3em 0;
margin-right: .5em;
color: #888;
-webkit-user-select: none;
}
.diff-file-header {
font-weight: bold;
}
.diff-file-header > span > span {
font-weight: normal;
}
.diff-add-line::before, .diff-remove-line::before, .diff-context::before {
display: inline-block;
color: #888;
-webkit-user-select: none;
}
.diff-add-line {
background: #e6ffec;
display: block;
}
.diff-add-line::before {
content: '+ ';
}
.diff-remove-line {
background: #ffebe9;
display: block;
}
.diff-remove-line::before {
content: '- ';
}
.diff-context::before {
content: ' ';
}
.nested-tree {