🏡 index : ~doyle/rgit.git

author Jordan Doyle <jordan@doyle.la> 2022-07-16 10:52:38.0 +01:00:00
committer Jordan Doyle <jordan@doyle.la> 2022-07-16 10:52:38.0 +01:00:00
commit
e59308f1d70c660c45d68e92e52993963a61ae24 [patch]
tree
261f4fa56be442a319edc5a6a4b4bd9c2c004cf9
parent
2cbafe165bc89b914b80bea1dd81fbb2ac49e290
download
e59308f1d70c660c45d68e92e52993963a61ae24.tar.gz

Add line count to tree view



Diff

 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!("<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>");
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 {