Fossil Forum
Post: patch: fossil diff --webpage makes filename stick to top of page
Small CSS-only feature that helps when scrolling through a long diff, and one forgets which file is looked at. - Both bright/dark mode CSS added. - Slight transparency in filename background, to know if we are at top of diff or somewhere inbetween (where text behind shows through) - Now this is hardcoded in --webpage mode, but could be further flag-gated if would bother someone (don't think worth the effort, but your call)
Index: src/diffcmd.c
==================================================================
--- src/diffcmd.c
+++ src/diffcmd.c
@@ -148,10 +148,30 @@
DIFF_WEBPAGE|DIFF_TCL))==0
){
blob_appendf(pOut, "Index: %s\n%.66c\n", zFile, '=');
}
}
+
+void diff_print_file_intro(
+ DiffConfig *pCfg, /* Diff configuration */
+ Blob *pOut /* Write to this blob, or stdout if this is NULL */
+){
+ u64 diffFlags = pCfg->diffFlags;
+ if( diffFlags & DIFF_WEBPAGE ){
+ blob_appendf(pOut,"<div>\n");
+ }
+}
+
+void diff_print_file_outro(
+ DiffConfig *pCfg, /* Diff configuration */
+ Blob *pOut /* Write to this blob, or stdout if this is NULL */
+){
+ u64 diffFlags = pCfg->diffFlags;
+ if( diffFlags & DIFF_WEBPAGE ){
+ blob_appendf(pOut,"</div>\n");
+ }
+}
/*
** Print the +++/--- filename lines or whatever filename information
** is appropriate for the output format.
**
@@ -158,11 +178,11 @@
*/
void diff_print_filenames(
const char *zLeft, /* Name of the left file */
const char *zRight, /* Name of the right file */
DiffConfig *pCfg, /* Diff configuration */
- Blob *pOut /* Write to this blob, or stdout of this is NULL */
+ Blob *pOut /* Write to this blob, or stdout if this is NULL */
){
u64 diffFlags = pCfg->diffFlags;
/* Standardize on /dev/null, regardless of platform. */
if( pCfg->diffFlags & DIFF_FILE_ADDED ) zLeft = "/dev/null";
if( pCfg->diffFlags & DIFF_FILE_DELETED ) zRight = "/dev/null";
@@ -231,10 +251,13 @@
@ body {
@ background-color: white;
@ }
@ h1 {
@ font-size: 150%;
+@ background-color: #ffffffe0;
+@ position: sticky;
+@ top: 0em;
@ }
@
@ table.diff {
@ width: 100%;
@ border-spacing: 0;
@@ -316,10 +339,13 @@
@ background-color: #c0c0ff;
@ text-decoration: none;
@ font-weight: bold;
@ }
@ @media (prefers-color-scheme: dark) {
+@ h1 {
+@ background-color: #353535e0;
+@ }
@ body {
@ background-color: #353535;
@ color: #ffffff;
@ }
@ td.diffln ins {
@@ -361,10 +387,13 @@
@ background-color: #353535;
@ color: #ffffff;
@ }
@ h1 {
@ font-size: 150%;
+@ background-color: #353535e0;
+@ position: sticky;
+@ top: 0em;
@ }
@
@ table.diff {
@ width: 100%;
@ border-spacing: 0;
@@ -600,12 +629,14 @@
if( pCfg->diffFlags & DIFF_NUMSTAT ){
if( !(pCfg->diffFlags & DIFF_BRIEF) ){
blob_appendf(pOut, "%s %s\n", blob_str(&out), zName);
}
}else{
+ diff_print_file_intro(pCfg, pOut);
diff_print_filenames(zName, zName2, pCfg, pOut);
blob_appendf(pOut, "%s\n", blob_str(&out));
+ diff_print_file_outro(pCfg, pOut);
}
}
blob_reset(&out);
}
@@ -708,12 +739,14 @@
if( pCfg->diffFlags & DIFF_NUMSTAT ){
if( !(pCfg->diffFlags & DIFF_BRIEF) ){
fossil_print("%s %s\n", blob_str(&out), zName);
}
}else{
+ diff_print_file_intro(pCfg, 0);
diff_print_filenames(zName, zName, pCfg, 0);
fossil_print("%s\n", blob_str(&out));
+ diff_print_file_outro(pCfg, 0);
}
/* Release memory resources */
blob_reset(&out);
}else{
@@ -912,11 +945,13 @@
}
if( showDiff ){
Blob content;
if( !isLink != !file_islink(zFullName) ){
diff_print_index(zPathname, pCfg, 0);
+ diff_print_file_intro(pCfg, 0);
diff_print_filenames(zPathname, zPathname, pCfg, 0);
+ diff_print_file_outro(pCfg, 0);
fossil_print("%s",DIFF_CANNOT_COMPUTE_SYMLINK);
continue;
}
if( srcid>0 ){
content_get(srcid, &content);
Against current checkout 63826bf8a4ce7300cf45ff16fe82bcd0b132fdb2. Tested by running --webpage with/without -y.
(Note: Was looking how to run all tests, accidentally ran tclsh ./test/many-www.tcl which turns out was bombing this site with requests?)
filename stick to top of page
Thank you! We can't accept your patch verbatim but we have two options:
- A developer (with an account) itched by this can go reimplement it, using yours as a blueprint.
- You can become such a developer and check it in.
:-?
You can become such a developer and check it in.
Might be interested, but wow, should the CLA really be snail-mailed to the US?
Might be interested, but wow, should the CLA really be snail-mailed to the US?
Richard has been known to accept scanned PDFs (or maybe photographed physical copies?) from non-US participants. If interested, please email him (drh sqlite org) such a copy, referring to the CLA in the subject and this thread in the body. Please CC me to help ensure it doesn't get lost in drh's day to day noise (stephan wanderinghorse net) and if he's okay with that copy then we'll get you set up (apropos: we'd use the name "robinp" unless you give us another name in the email).
Might be interested, but wow, should the CLA really be snail-mailed to the US?
Richard has been known to accept scanned PDFs (or maybe photographed physical copies?) from non-US participants. If interested, please email him (drh sqlite org) such a copy, referring to the CLA in the subject and this thread in the body. Please CC me to help ensure it doesn't get lost in drh's day to day noise (stephan wanderinghorse net) and if he's okay with that copy then we'll get you set up (apropos: we'd use the name "robinp" unless you give us another name in the email).
Edit: please, if at all possible, email it from the email account attached to this forum. Both Richard and myself can see that one and use it to verify that it's really you sending the CLA.
Will get back about this. On first read, the legal department objected that
The terms "contribution" and "contributed material" mean any source code, object code, patch, tool, sample, graphic, specification, manual, documentation, or any other material posted, submitted, or uploaded by you to the Fossil project.
does not have some additional scope restriction (like for extending/amending the existing Fossil project, phrasing mine not a lawyer's) that avoids CLA holder taking blanket copyright on random leaked/accidentally-uploaded non-related source code (low chance, but...).
If I can get legal to draft up some suggested sentence they would be happy with, will send it over, but in the meantime I'm happy with the reimplemented-based-on. But in any case, not urgent.