From e59308f1d70c660c45d68e92e52993963a61ae24 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Sat, 16 Jul 2022 10:52:38 +0100 Subject: [PATCH] Add line count to tree view --- src/git.rs | 22 ++++++++++++++-------- statics/style.css | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/git.rs b/src/git.rs index 65d5fc2..95c6259 100644 --- a/src/git.rs +++ a/src/git.rs @@ -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!("{}", html_generator.finalize().replace('\n', "\n")) } #[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!("")); + write!(diff_output, r#""#).unwrap(); } - diff_output.push_str(prefix); diff_output.push_str(&html_generator.finalize()); if class.is_some() { diff_output.push_str(""); diff --git a/statics/style.css b/statics/style.css index 77321c2..5854b40 100644 --- a/statics/style.css +++ a/statics/style.css @@ -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 { -- rgit 0.1.3