user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 00/37] viewvcs: diff highlighting and more
@ 2019-01-21 20:52  7% Eric Wong
  2019-01-21 20:52  6% ` [PATCH 24/37] $INBOX/_/text/color/ and sample user-side CSS Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2019-01-21 20:52 UTC (permalink / raw)
  To: meta

Still working on VCS integration and I'm not comfortable deploying
this on the main public-inbox.org because of performance/fairness
concerns, yet.

But, perfect is the enemy of good and I figure it's worth
publishing at the moment.  It's also on a Tor mirror:

    http://hjrcffqmbrq6wope.onion/meta/
    http://hjrcffqmbrq6wope.onion/git/

It looks great to me in Netsurf and dillo :>

People with machines powerful enough to run Firefox
(or Tor Browser Bundle) can use "View -> Page Style" to adjust
colors.

Performance considerations:

* diff highlighting alone adds 10-20% overhead to message rendering
  Maybe I can speed it up with some less-readable Perl...

* blob reconstruction is horribly unfair to other clients at the
  moment.  Fixing this is a priority for me.

I haven't hooked up highlight to blob viewing, yet; but that's
coming; too.

Thinking about it more, the blob lookups is so specific to git
that I'm not sure other VCSes can be supported...

The following changes since commit 55db8a2a51c13aec813ac56bbaac1505791fd262:
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                   TODO: autolinkify that(!)

  t/git.t: do not pass "-b" to git-repack(1) (2019-01-18 22:00:33 +0000)

are available in the Git repository at:

  https://public-inbox.org/ viewvcs

for you to fetch changes up to c440c879d38e67f62bdbb74f616dc84d20899c33:

  t/check-www-inbox: trap SIGINT for File::Temp destruction (2019-01-21 06:53:35 +0000)

----------------------------------------------------------------
Eric Wong (37):
      view: disable bold in topic display
      hval: force monospace for <form> elements, too
      t/perf-msgview: add test to check msg_html performance
      solver: initial Perl implementation
      git: support multiple URL endpoints
      git: add git_quote
      git: check saves error on disambiguation
      solver: various bugfixes and cleanups
      view: wire up diff and vcs viewers with solver
      git: disable abbreviations with cat-file hints
      solver: operate directly on git index
      view: enable naming hints for raw blob downloads
      git: support 'ambiguous' result from --batch-check
      solver: more verbose blob resolution
      solver: break up patch application steps
      solver: switch patch application to use a callback
      solver: simplify control flow for initial loop
      solver: break @todo loop into a callback
      solver: note the synchronous nature of index preparation
      solver: add a TODO note about making this fully evented
      view: enforce trailing slash for /$INBOX/$OID/s/ endpoints
      solver: restore diagnostics and deal with CRLF
      www: admin-configurable CSS via "publicinbox.css"
      $INBOX/_/text/color/ and sample user-side CSS
      viewdiff: support diff-highlighting w/o coderepo
      viewdiff: cleanup state transitions a bit
      viewdiff: quote attributes for Atom feed
      t/check-www-inbox: use xmlstarlet to validate Atom if available
      viewdiff: do not link to 0{7,40} blobs (again)
      viewvcs: disable white-space prewrap in blob view
      solver: force quoted-printable bodies to LF
      solver: remove extra "^index $OID..$OID" line
      config: each_inbox iteration preserves config order
      t/check-www-inbox: warn on missing Content-Type
      highlight: initial wrapper and PSGI service
      hval: split out escape sequences to a separate table
      t/check-www-inbox: trap SIGINT for File::Temp destruction

 Documentation/design_www.txt                 |   6 +-
 MANIFEST                                     |  15 +
 Makefile.PL                                  |   3 +
 TODO                                         |   2 -
 contrib/css/216dark.css                      |  26 ++
 contrib/css/216light.css                     |  25 ++
 contrib/css/README                           |  41 +++
 examples/highlight.psgi                      |  13 +
 examples/public-inbox.psgi                   |   2 +-
 lib/PublicInbox/Config.pm                    |  96 +++++-
 lib/PublicInbox/Git.pm                       |  87 ++++-
 lib/PublicInbox/HlMod.pm                     | 126 ++++++++
 lib/PublicInbox/Hval.pm                      |  38 +--
 lib/PublicInbox/SolverGit.pm                 | 454 +++++++++++++++++++++++++++
 lib/PublicInbox/UserContent.pm               |  78 +++++
 lib/PublicInbox/View.pm                      |  51 ++-
 lib/PublicInbox/ViewDiff.pm                  | 161 ++++++++++
 lib/PublicInbox/ViewVCS.pm                   | 110 +++++++
 lib/PublicInbox/WWW.pm                       | 152 ++++++++-
 lib/PublicInbox/WwwHighlight.pm              |  73 +++++
 lib/PublicInbox/WwwStream.pm                 |   4 +-
 lib/PublicInbox/WwwText.pm                   |  35 +++
 script/public-inbox-httpd                    |   2 +-
 t/check-www-inbox.perl                       |  26 +-
 t/config.t                                   |  19 ++
 t/git.t                                      |   7 +-
 t/hl_mod.t                                   |  54 ++++
 t/perf-msgview.t                             |  50 +++
 t/solve/0001-simple-mod.patch                |  20 ++
 t/solve/0002-rename-with-modifications.patch |  37 +++
 t/solver_git.t                               |  91 ++++++
 t/view.t                                     |   2 +
 32 files changed, 1841 insertions(+), 65 deletions(-)
 create mode 100644 contrib/css/216dark.css
 create mode 100644 contrib/css/216light.css
 create mode 100644 contrib/css/README
 create mode 100644 examples/highlight.psgi
 create mode 100644 lib/PublicInbox/HlMod.pm
 create mode 100644 lib/PublicInbox/SolverGit.pm
 create mode 100644 lib/PublicInbox/UserContent.pm
 create mode 100644 lib/PublicInbox/ViewDiff.pm
 create mode 100644 lib/PublicInbox/ViewVCS.pm
 create mode 100644 lib/PublicInbox/WwwHighlight.pm
 create mode 100644 t/hl_mod.t
 create mode 100644 t/perf-msgview.t
 create mode 100644 t/solve/0001-simple-mod.patch
 create mode 100644 t/solve/0002-rename-with-modifications.patch
 create mode 100644 t/solver_git.t

Eric Wong (37):
  view: disable bold in topic display
  hval: force monospace for <form> elements, too
  t/perf-msgview: add test to check msg_html performance
  solver: initial Perl implementation
  git: support multiple URL endpoints
  git: add git_quote
  git: check saves error on disambiguation
  solver: various bugfixes and cleanups
  view: wire up diff and vcs viewers with solver
  git: disable abbreviations with cat-file hints
  solver: operate directly on git index
  view: enable naming hints for raw blob downloads
  git: support 'ambiguous' result from --batch-check
  solver: more verbose blob resolution
  solver: break up patch application steps
  solver: switch patch application to use a callback
  solver: simplify control flow for initial loop
  solver: break @todo loop into a callback
  solver: note the synchronous nature of index preparation
  solver: add a TODO note about making this fully evented
  view: enforce trailing slash for /$INBOX/$OID/s/ endpoints
  solver: restore diagnostics and deal with CRLF
  www: admin-configurable CSS via "publicinbox.css"
  $INBOX/_/text/color/ and sample user-side CSS
  viewdiff: support diff-highlighting w/o coderepo
  viewdiff: cleanup state transitions a bit
  viewdiff: quote attributes for Atom feed
  t/check-www-inbox: use xmlstarlet to validate Atom if available
  viewdiff: do not link to 0{7,40} blobs (again)
  viewvcs: disable white-space prewrap in blob view
  solver: force quoted-printable bodies to LF
  solver: remove extra "^index $OID..$OID" line
  config: each_inbox iteration preserves config order
  t/check-www-inbox: warn on missing Content-Type
  highlight: initial wrapper and PSGI service
  hval: split out escape sequences to a separate table
  t/check-www-inbox: trap SIGINT for File::Temp destruction

 Documentation/design_www.txt                 |   6 +-
 MANIFEST                                     |  15 +
 Makefile.PL                                  |   3 +
 TODO                                         |   2 -
 contrib/css/216dark.css                      |  26 ++
 contrib/css/216light.css                     |  25 +
 contrib/css/README                           |  41 ++
 examples/highlight.psgi                      |  13 +
 examples/public-inbox.psgi                   |   2 +-
 lib/PublicInbox/Config.pm                    |  96 +++-
 lib/PublicInbox/Git.pm                       |  87 +++-
 lib/PublicInbox/HlMod.pm                     | 126 +++++
 lib/PublicInbox/Hval.pm                      |  38 +-
 lib/PublicInbox/SolverGit.pm                 | 454 +++++++++++++++++++
 lib/PublicInbox/UserContent.pm               |  78 ++++
 lib/PublicInbox/View.pm                      |  51 ++-
 lib/PublicInbox/ViewDiff.pm                  | 161 +++++++
 lib/PublicInbox/ViewVCS.pm                   | 110 +++++
 lib/PublicInbox/WWW.pm                       | 152 ++++++-
 lib/PublicInbox/WwwHighlight.pm              |  73 +++
 lib/PublicInbox/WwwStream.pm                 |   4 +-
 lib/PublicInbox/WwwText.pm                   |  35 ++
 script/public-inbox-httpd                    |   2 +-
 t/check-www-inbox.perl                       |  26 +-
 t/config.t                                   |  19 +
 t/git.t                                      |   7 +-
 t/hl_mod.t                                   |  54 +++
 t/perf-msgview.t                             |  50 ++
 t/solve/0001-simple-mod.patch                |  20 +
 t/solve/0002-rename-with-modifications.patch |  37 ++
 t/solver_git.t                               |  91 ++++
 t/view.t                                     |   2 +
 32 files changed, 1841 insertions(+), 65 deletions(-)
 create mode 100644 contrib/css/216dark.css
 create mode 100644 contrib/css/216light.css
 create mode 100644 contrib/css/README
 create mode 100644 examples/highlight.psgi
 create mode 100644 lib/PublicInbox/HlMod.pm
 create mode 100644 lib/PublicInbox/SolverGit.pm
 create mode 100644 lib/PublicInbox/UserContent.pm
 create mode 100644 lib/PublicInbox/ViewDiff.pm
 create mode 100644 lib/PublicInbox/ViewVCS.pm
 create mode 100644 lib/PublicInbox/WwwHighlight.pm
 create mode 100644 t/hl_mod.t
 create mode 100644 t/perf-msgview.t
 create mode 100644 t/solve/0001-simple-mod.patch
 create mode 100644 t/solve/0002-rename-with-modifications.patch
 create mode 100644 t/solver_git.t

^ permalink raw reply	[relevance 7%]

* [PATCH 24/37] $INBOX/_/text/color/ and sample user-side CSS
  2019-01-21 20:52  7% [PATCH 00/37] viewvcs: diff highlighting and more Eric Wong
@ 2019-01-21 20:52  6% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2019-01-21 20:52 UTC (permalink / raw)
  To: meta

Since we now support more CSS classes for coloring,
give this feature more visibility.
---
 Documentation/design_www.txt   |  6 +--
 MANIFEST                       |  1 +
 Makefile.PL                    |  3 ++
 TODO                           |  2 -
 lib/PublicInbox/UserContent.pm | 78 ++++++++++++++++++++++++++++++++++
 lib/PublicInbox/WWW.pm         | 17 ++++++--
 lib/PublicInbox/WwwStream.pm   |  2 +
 lib/PublicInbox/WwwText.pm     | 35 +++++++++++++++
 8 files changed, 134 insertions(+), 10 deletions(-)
 create mode 100644 lib/PublicInbox/UserContent.pm

diff --git a/Documentation/design_www.txt b/Documentation/design_www.txt
index 514f8ff..c7d7fcb 100644
--- a/Documentation/design_www.txt
+++ b/Documentation/design_www.txt
@@ -107,8 +107,6 @@ browsers default to.
 
 CSS classes (for user-supplied CSS)
 -----------------------------------
-span.q	- quoted text in email messages
 
-TODO: consider using highlight(1) via libhighlight-perl in Debian,
-      optionally
-...
+See examples in contrib/css/ and lib/PublicInbox/WwwText.pm
+(or https://public-inbox.org/meta/_/text/color/ soon)
diff --git a/MANIFEST b/MANIFEST
index 1db7bd1..53d51b2 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -110,6 +110,7 @@ lib/PublicInbox/Spamcheck/Spamc.pm
 lib/PublicInbox/Spawn.pm
 lib/PublicInbox/SpawnPP.pm
 lib/PublicInbox/Unsubscribe.pm
+lib/PublicInbox/UserContent.pm
 lib/PublicInbox/V2Writable.pm
 lib/PublicInbox/View.pm
 lib/PublicInbox/ViewDiff.pm
diff --git a/Makefile.PL b/Makefile.PL
index c134ff9..e00c015 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -56,5 +56,8 @@ check-manifest :: MANIFEST
 check:: pure_all check-manifest
 	\$(EATMYDATA) prove -lv -j\$(N)
 
+lib/PublicInbox/UserContent.pm :: contrib/css/216dark.css
+	@\$(PERL) -I lib \$@ \$<
+
 EOF
 }
diff --git a/TODO b/TODO
index 374d8df..57ea8c4 100644
--- a/TODO
+++ b/TODO
@@ -66,8 +66,6 @@ all need to be considered for everything we introduce)
 * linkify thread skeletons better
   https://public-inbox.org/git/6E3699DEA672430CAEA6DEFEDE6918F4@PhilipOakley/
 
-* generate sample CSS for use with userContent.css/dillo/etc
-
 * streaming Email::MIME replacement: currently we generate many
   allocations/strings for headers we never look at and slurp
   entire message bodies into memory.
diff --git a/lib/PublicInbox/UserContent.pm b/lib/PublicInbox/UserContent.pm
new file mode 100644
index 0000000..b34ebf9
--- /dev/null
+++ b/lib/PublicInbox/UserContent.pm
@@ -0,0 +1,78 @@
+# Copyright (C) 2019 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+
+# Self-updating module containing a sample CSS for client-side
+# customization by users of public-inbox.  Used by Makefile.PL
+package PublicInbox::UserContent;
+use strict;
+use warnings;
+
+# this sub is updated automatically:
+sub CSS () {
+	<<'_'
+	/*
+	 * Dark color scheme using 216 web-safe colors, inspired
+	 * somewhat by the default color scheme in mutt.
+	 * It reduces eyestrain for me, and energy usage for all:
+	 * https://en.wikipedia.org/wiki/Light-on-dark_color_scheme
+	 */
+	* { background:#000; color:#ccc }
+
+	/*
+	 * Underlined links add visual noise which make them hard-to-read.
+	 * Use colors to make them stand out, instead.
+	 */
+	a { color:#69f; text-decoration:none }
+	a:visited { color:#96f }
+
+	/* quoted text gets a different color */
+	*.q { color:#09f }
+
+	/*
+	 * these may be used with cgit, too
+	 * (cgit uses <div>, public-inbox uses <span>)
+	 */
+	*.add { color:#0ff }
+	*.del { color:#f0f }
+	*.head { color:#fff }
+	*.hunk { color:#c93 }
+_
+}
+# end of auto-updated sub
+
+# return a sample CSS
+sub sample ($$) {
+	my ($ibx, $env) = @_;
+	my $url_prefix = $ibx->base_url($env);
+	my $preamble = <<"";
+/*
+ * Firefox users: this goes in \$PROFILE_FOLDER/chrome/userContent.css
+ * where \$PROFILE_FOLDER is platform-specific
+ *
+ * cf. http://kb.mozillazine.org/UserContent.css
+ *     http://kb.mozillazine.org/Profile_folder_-_Firefox
+ *
+ * Users of dillo can remove the entire lines with "moz-only"
+ * in them and place the resulting file in ~/.dillo/style.css
+ */
+\@-moz-document url-prefix($url_prefix) { /* moz-only */
+
+	$preamble . CSS() . "\n} /* moz-only */\n";
+}
+
+# Auto-update this file based on the contents of a CSS file:
+# usage: perl -I lib __FILE__ contrib/css/216dark.css
+# (See Makefile.PL)
+if (scalar(@ARGV) == 1 && -r __FILE__) {
+	use autodie;
+	open my $ro, '<', $ARGV[0];
+	my $css = do { local $/; <$ro> };
+	$css =~ s/^([ \t]*\S)/\t$1/smg;
+	open my $rw, '+<', __FILE__;
+	my $out = do { local $/; <$rw> };
+	$out =~ s/^sub CSS.*^_\n\}/sub CSS () {\n\t<<'_'\n${css}_\n}/sm;
+	seek $rw, 0, 0;
+	print $rw $out;
+}
+
+1;
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index 863da85..406802a 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -20,6 +20,7 @@ use URI::Escape qw(uri_unescape);
 use PublicInbox::MID qw(mid_escape);
 require PublicInbox::Git;
 use PublicInbox::GitHTTPBackend;
+use PublicInbox::UserContent;
 
 # TODO: consider a routing tree now that we have more endpoints:
 our $INBOX_RE = qr!\A/([\w\-][\w\.\-]*)!;
@@ -120,7 +121,7 @@ sub call {
 	} elsif ($path_info =~ m!$INBOX_RE/_/text(?:/(.*))?\z!o) {
 		get_text($ctx, $1, $2);
 	} elsif ($path_info =~ m!$INBOX_RE/([\w\-\.]+)\.css\z!o) {
-		get_css($self, $2);
+		get_css($ctx, $1, $2);
 	} elsif ($path_info =~ m!$INBOX_RE/($OID_RE)/s/\z!o) {
 		get_vcs_object($ctx, $1, $2);
 	} elsif ($path_info =~ m!$INBOX_RE/($OID_RE)/s/([\w\.\-]+)\z!o) {
@@ -577,10 +578,18 @@ sub style {
 # CSS is configured globally for all inboxes, but we access them on
 # a per-inbox basis.  This allows administrators to setup per-inbox
 # static routes to intercept the request before it hits PSGI
-sub get_css ($$) {
-	my ($self, $key) = @_;
+sub get_css ($$$) {
+	my ($ctx, $inbox, $key) = @_;
+	my $r404 = invalid_inbox($ctx, $inbox);
+	return $r404 if $r404;
+	my $self = $ctx->{www};
 	my $css_map = $self->{-css_map} || stylesheets_prepare($self, '');
-	defined(my $css = $css_map->{$key}) or return r404();
+	my $css = $css_map->{$key};
+	if (!defined($css) && $key eq 'userContent') {
+		my $env = $ctx->{env};
+		$css = PublicInbox::UserContent::sample($ctx->{-inbox}, $env);
+	}
+	defined $css or return r404();
 	my $h = [ 'Content-Length', bytes::length($css),
 		'Content-Type', 'text/css' ];
 	PublicInbox::GitHTTPBackend::cache_one_year($h);
diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm
index c3aeb6b..8ae35c7 100644
--- a/lib/PublicInbox/WwwStream.pm
+++ b/lib/PublicInbox/WwwStream.pm
@@ -38,10 +38,12 @@ sub _html_top ($) {
 	my $title = $ctx->{-title_html} || $desc;
 	my $upfx = $ctx->{-upfx} || '';
 	my $help = $upfx.'_/text/help';
+	my $color = $upfx.'_/text/color';
 	my $atom = $ctx->{-atom} || $upfx.'new.atom';
 	my $tip = $ctx->{-html_tip} || '';
 	my $top = "<b>$desc</b>";
 	my $links = "<a\nhref=\"$help\">help</a> / ".
+			"<a\nhref=\"$color\">color</a> / ".
 			"<a\nhref=\"$atom\">Atom feed</a>";
 	if ($obj->search) {
 		my $q_val = $ctx->{-q_value_html};
diff --git a/lib/PublicInbox/WwwText.pm b/lib/PublicInbox/WwwText.pm
index b5874cf..d3413ad 100644
--- a/lib/PublicInbox/WwwText.pm
+++ b/lib/PublicInbox/WwwText.pm
@@ -88,9 +88,44 @@ sub _srch_prefix ($$) {
 	1;
 }
 
+sub _colors_help ($$) {
+	my ($ctx, $txt) = @_;
+	my $ibx = $ctx->{-inbox};
+	my $base_url = $ibx->base_url($ctx->{env});
+	$$txt .= "color customization for $base_url\n";
+	$$txt .= <<EOF;
+
+public-inbox provides a stable set of CSS classes for users to
+customize colors for highlighting diffs and code.
+
+Users of browsers such as dillo, Firefox, or some browser
+extensions may start by downloading the following sample CSS file
+to control the colors they see:
+
+	${base_url}userContent.css
+
+CSS classes
+-----------
+
+	   span.q - quoted text in email messages
+
+For diff highlighting, we try to match class names with those
+used by cgit: https://git.zx2c4.com/cgit/
+
+	 span.add - diff post-image lines
+
+	 span.del - diff pre-image lines
+
+	span.head - diff header (metainformation)
+
+	span.hunk - diff hunk-header
+
+EOF
+}
 
 sub _default_text ($$$) {
 	my ($ctx, $key, $txt) = @_;
+	return _colors_help($ctx, $txt) if $key eq 'color';
 	return if $key ne 'help'; # TODO more keys?
 
 	my $ibx = $ctx->{-inbox};
-- 
EW


^ permalink raw reply	[relevance 6%]

Results 1-2 of 2 | reverse | sort options + mbox downloads above
-- links below jump to the message on this page --
2019-01-21 20:52  7% [PATCH 00/37] viewvcs: diff highlighting and more Eric Wong
2019-01-21 20:52  6% ` [PATCH 24/37] $INBOX/_/text/color/ and sample user-side CSS Eric Wong

Code repositories for project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).