yahns Ruby server user/dev discussion
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: yahns-public@yhbt.net
Subject: [PATCH] extras/autoindex: use dark colors by default
Date: Sun, 21 Apr 2019 21:24:23 +0000	[thread overview]
Message-ID: <20190421212423.11453-1-e@80x24.org> (raw)

Some browsers (e.g. Firefox 67.0a1 via "ui.systemUsesDarkTheme") are
adding support for the "prefers-color-scheme" @media query.  So this
allows pages to respect user choice when it comes to dark or light

OLED and CRT displays measure significant power savings when using
dark schemes.  Dark themes work better with less ambient light, so
favoring darkness can lead to overall power savings even with CCFL
and LED-lit displays.
 extras/autoindex.rb | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/extras/autoindex.rb b/extras/autoindex.rb
index 45b80cf..9060c6c 100644
--- a/extras/autoindex.rb
+++ b/extras/autoindex.rb
@@ -14,6 +14,21 @@ class Autoindex
   FN = %{<a href="%s">%s</a>}
   TFMT = "%Y-%m-%d %H:%M"
+  # default to a dark, web-safe (216 color) palette for power-savings.
+  # Color-capable browsers can respect the prefers-color-scheme:light
+  # @media query (browser support a work-in-progress)
+  STYLE = <<''.gsub(/^\s*/m, '').delete!("\n")
+@media screen {
+  *{background:#000;color:#ccc}
+  a{color:#69f;text-decoration:none}
+  a:visited{color:#96f}
+@media screen AND (prefers-color-scheme:light) {
+  *{background:#fff;color:#333}
+  a{color:#00f;text-decoration:none}
+  a:visited{color:#808}
   def initialize(app, *args)
     app.respond_to?(:root) or raise ArgumentError,
        "wrapped app #{app.inspect} does not respond to #root"
@@ -139,8 +154,9 @@ def call(env)
       path_info_html = path_info_ue.split(%r{/}, -1).map! do |part|
-      body = "<html><head><title>Index of #{path_info_html}</title></head>" \
-             "<body><h1>Index of #{path_info_html}</h1><hr><pre>\n" \
+      body = "<html><head><title>Index of #{path_info_html}</title>" \
+             "<style>#{STYLE}</style>" \
+             "</head><body><h1>Index of #{path_info_html}</h1><hr><pre>\n" \
              "#{dirs.concat(files).join("\n")}" \
       h = { "Content-Type" => "text/html", "Content-Length" => body.size.to_s }

                 reply	other threads:[~2019-04-21 21:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://yhbt.net/yahns/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190421212423.11453-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=yahns-public@yhbt.net \
    --subject='Re: [PATCH] extras/autoindex: use dark colors by default' \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

yahns Ruby server user/dev discussion

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhbt.net/yahns-public
	git clone --mirror http://ou63pmih66umazou.onion/yahns-public

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 yahns-public yahns-public/ https://yhbt.net/yahns-public \
		yahns-public@yhbt.net yahns-public@rubyforge.org
	public-inbox-index yahns-public

Example config snippet for mirrors.
Newsgroups are available over NNTP:
 note: .onion URLs require Tor: https://www.torproject.org/

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


AGPL code for this site: git clone http://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/public-inbox.git