]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/UserContent.pm
imap+nntp: share COMPRESS implementation
[public-inbox.git] / lib / PublicInbox / UserContent.pm
1 # Copyright (C) 2019-2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 # Self-updating module containing a sample CSS for client-side
5 # customization by users of public-inbox.  Used by Makefile.PL
6 package PublicInbox::UserContent;
7 use strict;
8 use warnings;
9
10 # this sub is updated automatically:
11 sub CSS () {
12         <<'_'
13         /*
14          * CC0-1.0 <https://creativecommons.org/publicdomain/zero/1.0/legalcode>
15          * Dark color scheme using 216 web-safe colors, inspired
16          * somewhat by the default color scheme in mutt.
17          * It reduces eyestrain for me, and energy usage for all:
18          * https://en.wikipedia.org/wiki/Light-on-dark_color_scheme
19          */
20         * { font-size: 100% !important;
21                 font-family: monospace !important;
22                 background:#000 !important;
23                 color:#ccc !important }
24         pre { white-space: pre-wrap !important }
25
26         /*
27          * Underlined links add visual noise which make them hard-to-read.
28          * Use colors to make them stand out, instead.
29          */
30         a:link { color:#69f !important;
31                 text-decoration:none !important }
32         a:visited { color:#96f !important }
33
34         /* quoted text in emails gets a different color */
35         *.q { color:#09f !important }
36
37         /*
38          * these may be used with cgit <https://git.zx2c4.com/cgit/>, too.
39          * (cgit uses <div>, public-inbox uses <span>)
40          */
41         *.add { color:#0ff !important } /* diff post-image lines */
42         *.del { color:#f0f !important } /* diff pre-image lines */
43         *.head { color:#fff !important } /* diff header (metainformation) */
44         *.hunk { color:#c93 !important } /* diff hunk-header */
45
46         /*
47          * highlight 3.x colors (tested 3.18) for displaying blobs.
48          * This doesn't use most of the colors available, as I find too
49          * many colors overwhelming, so the default is commented out.
50          */
51         .hl.num { color:#f30 !important } /* number */
52         .hl.esc { color:#f0f !important } /* escape character */
53         .hl.str { color:#f30 !important } /* string */
54         .hl.ppc { color:#f0f !important } /* preprocessor */
55         .hl.pps { color:#f30 !important } /* preprocessor string */
56         .hl.slc { color:#09f !important } /* single-line comment */
57         .hl.com { color:#09f !important } /* multi-line comment */
58         /* .hl.opt { color:#ccc !important } */ /* operator */
59         /* .hl.ipl { color:#ccc !important } */ /* interpolation */
60
61         /* keyword groups kw[a-z] */
62         .hl.kwa { color:#ff0 !important }
63         .hl.kwb { color:#0f0 !important }
64         .hl.kwc { color:#ff0 !important }
65         /* .hl.kwd { color:#ccc !important } */
66
67         /* line-number (unused by public-inbox) */
68         /* .hl.lin { color:#ccc !important } */
69 _
70 }
71 # end of auto-updated sub
72
73 # return a sample CSS
74 sub sample ($$) {
75         my ($ibx, $env) = @_;
76         my $url_prefix = $ibx->base_url($env);
77         my $preamble = <<"";
78 /*
79  * Firefox users: this goes in \$PROFILE_FOLDER/chrome/userContent.css
80  * where \$PROFILE_FOLDER is platform-specific
81  *
82  * cf. http://kb.mozillazine.org/UserContent.css
83  *     http://kb.mozillazine.org/Profile_folder_-_Firefox
84  *
85  * Users of dillo can remove the entire lines with "moz-only"
86  * in them and place the resulting file in ~/.dillo/style.css
87  */
88 \@-moz-document url-prefix($url_prefix) { /* moz-only */
89
90         $preamble . CSS() . "\n} /* moz-only */\n";
91 }
92
93 # Auto-update this file based on the contents of a CSS file:
94 # usage: perl -I lib __FILE__ contrib/css/216dark.css
95 # (See Makefile.PL)
96 if (scalar(@ARGV) == 1 && -r __FILE__) {
97         open my $ro, '<', $ARGV[0] or die $!;
98         my $css = do { local $/; <$ro> } or die $!;
99
100         # indent one level:
101         $css =~ s/^([ \t]*\S)/\t$1/smg;
102
103         # "!important" overrides whatever the BOFH sets:
104         $css =~ s/;/ !important;/sg;
105         $css =~ s/(\w) \}/$1 !important }/msg;
106
107         open my $rw, '+<', __FILE__ or die $!;
108         my $out = do { local $/; <$rw> } or die $!;
109         $css =~ s/; /;\n\t\t/g;
110         $out =~ s/^sub CSS.*^_\n\}/sub CSS () {\n\t<<'_'\n${css}_\n}/sm;
111         seek $rw, 0, 0;
112         print $rw $out or die $!;
113         close $rw or die $!;
114 }
115
116 1;