From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id CD6C020377 for ; Mon, 22 Apr 2019 01:49:06 +0000 (UTC) From: Eric Wong To: Subject: [PATCH 1/3] add dark216 color scheme for power savings Date: Mon, 22 Apr 2019 01:49:04 +0000 Message-Id: <20190422014906.4253-2-e@80x24.org> In-Reply-To: <20190422014906.4253-1-e@80x24.org> References: <20190422014906.4253-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: "oldweb" remains for compatibility and we still have minimal styling. 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 schemes. 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. --- Documentation/olddoc.1.txt | 4 +++- GNUmakefile | 2 +- README | 14 +++++++------ lib/dark216.rb | 40 ++++++++++++++++++++++++++++++++++++++ lib/olddoc.rb | 3 ++- lib/oldweb.rb | 1 + lib/oldweb/_head.rhtml | 6 +++++- 7 files changed, 60 insertions(+), 10 deletions(-) create mode 100644 lib/dark216.rb diff --git a/Documentation/olddoc.1.txt b/Documentation/olddoc.1.txt index c294cdb..25bf88b 100644 --- a/Documentation/olddoc.1.txt +++ b/Documentation/olddoc.1.txt @@ -10,9 +10,11 @@ olddoc - old-fashioned RDoc HTML generator `rdoc` -f oldweb +`rdoc` -f dark216 + # DESCRIPTION -olddoc features oldweb, and old-fashioned RDoc HTML generator. +olddoc features dark216, and old-fashioned RDoc HTML generator. You can also use "olddoc prepare" to generate NEWS files from git tags. diff --git a/GNUmakefile b/GNUmakefile index 038bc25..1df29ae 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -41,7 +41,7 @@ doc: $(placeholders) $(MAKE) -C Documentation html rm -rf doc olddoc prepare - rdoc --debug -f oldweb + rdoc --debug -f dark216 olddoc merge ln NEWS.atom.xml doc/ diff --git a/README b/README index 4b5aa1f..b9538e7 100644 --- a/README +++ b/README @@ -3,15 +3,17 @@ olddoc contains old-fashioned document generators for those who do not wish to impose bloated, new-fangled web cruft on their readers. -olddoc contains oldweb, an HTML generator without any images, frames, -CSS, or JavaScript. It is designed for users of text-based browsers -and/or low-bandwidth connections. oldweb focuses on text as it is -the lowest common denominator for accessibility and compatibility +olddoc contains dark216, a HTML generator without any images, frames, +or JavaScript. It is designed for users of text-based browsers +and/or low-bandwidth connections; yet respects user preference for +light color schemes in new CSS browsers while favoring darkness for +power savings on OLED and CRT displays. dark216 focuses on text as +it is the lowest common denominator for accessibility and compatibility with people and hardware. == Reasons -* No CSS. Encouraging users to use CSS leads to problems like +* No CSS required. Encouraging users to use CSS leads to problems like copy-paste hijacking: https://thejh.net/misc/website-terminal-copy-paste External CSS also increases page load time as it often blocks page rendering. Asynchronous loading of CSS also causes accessibility @@ -38,7 +40,7 @@ missing out! gem install olddoc cd $ANY_RDOC_USING_RUBY_PROJECT - rdoc -f oldweb + rdoc -f dark216 You can also use olddoc to generate NEWS entries assuming you have git tags, a README file and .olddoc.yml diff --git a/lib/dark216.rb b/lib/dark216.rb new file mode 100644 index 0000000..a01584c --- /dev/null +++ b/lib/dark216.rb @@ -0,0 +1,40 @@ +# Copyright (C) 2019 all contributors +# License: GPL-3.0+ + +# Loosely derived from Darkfish in the main rdoc distribution +require_relative 'oldweb' + +# dark216 is an \RDoc template and not intended as a programming API. +# It respect prefers-color-scheme:light on newer browsers with CSS +# support, but favors darkness for power-savings. +# You may specify it as an \RDoc formatter: +# +# rdoc -f dark216 ... +class Dark216 < Oldweb + RDoc::RDoc.add_generator(self) # :nodoc: + include ERB::Util # :nodoc: + + # description of the generator + DESCRIPTION = 'minimal dark HTML generator' + + # 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") # :nodoc: +@media screen { + *{background:#000;color:#ccc} + a{color:#69f} + a:visited{color:#96f} +} +@media screen AND (prefers-color-scheme:light) { + *{background:#fff;color:#333} + a{color:#00f} + a:visited{color:#808} +} + + def initialize(*args) # :nodoc: + super + @oldweb_style = STYLE + end +end +# :startdoc: diff --git a/lib/olddoc.rb b/lib/olddoc.rb index 3061e73..d5d6b37 100644 --- a/lib/olddoc.rb +++ b/lib/olddoc.rb @@ -1,4 +1,4 @@ -# Copyright (C) 2015-2016 all contributors +# Copyright (C) 2015-2019 all contributors # License: GPL-3.0+ module Olddoc # :nodoc: autoload :Gemspec, 'olddoc/gemspec' @@ -16,3 +16,4 @@ module Olddoc # :nodoc: end end require_relative 'oldweb' +require_relative 'dark216' diff --git a/lib/oldweb.rb b/lib/oldweb.rb index ccc37f7..5b55019 100644 --- a/lib/oldweb.rb +++ b/lib/oldweb.rb @@ -91,6 +91,7 @@ class Oldweb cgit_url << '#n%d' # lineno @old_vcs_url = cgit_url end + @oldweb_style = nil # used by dark216 end def generate # :nodoc: diff --git a/lib/oldweb/_head.rhtml b/lib/oldweb/_head.rhtml index 720fd95..15a428e 100644 --- a/lib/oldweb/_head.rhtml +++ b/lib/oldweb/_head.rhtml @@ -8,4 +8,8 @@ type="application/atom+xml" /><% end %> +content="text/html; charset=<%= @options.charset %>"><% +if @oldweb_style +%><% +end +%> -- EW