<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang=""> <head> <meta charset="utf-8" /> <meta name="generator" content="pandoc" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" /> <meta name="author" content="By John Mercouris" /> <title>dark-mode keeps your screen dim</title> <style type="text/css"> code{white-space: pre-wrap;} span.smallcaps{font-variant: small-caps;} span.underline{text-decoration: underline;} div.column{display: inline-block; vertical-align: top; width: 50%;} </style> <style type="text/css"> a.sourceLine { display: inline-block; line-height: 1.25; } a.sourceLine { pointer-events: none; color: inherit; text-decoration: inherit; } a.sourceLine:empty { height: 1.2em; position: absolute; } .sourceCode { overflow: visible; } code.sourceCode { white-space: pre; position: relative; } div.sourceCode { margin: 1em 0; } pre.sourceCode { margin: 0; } @media screen { div.sourceCode { overflow: auto; } } @media print { code.sourceCode { white-space: pre-wrap; } a.sourceLine { text-indent: -1em; padding-left: 1em; } } pre.numberSource a.sourceLine { position: relative; } pre.numberSource a.sourceLine:empty { position: absolute; } pre.numberSource a.sourceLine::before { content: attr(data-line-number); position: absolute; left: -5em; text-align: right; vertical-align: baseline; border: none; pointer-events: all; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; padding: 0 4px; width: 4em; color: #aaaaaa; } pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; } div.sourceCode { } @media screen { a.sourceLine::before { text-decoration: underline; } } code span.al { color: #ff0000; font-weight: bold; } /* Alert */ code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */ code span.at { color: #7d9029; } /* Attribute */ code span.bn { color: #40a070; } /* BaseN */ code span.bu { } /* BuiltIn */ code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */ code span.ch { color: #4070a0; } /* Char */ code span.cn { color: #880000; } /* Constant */ code span.co { color: #60a0b0; font-style: italic; } /* Comment */ code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */ code span.do { color: #ba2121; font-style: italic; } /* Documentation */ code span.dt { color: #902000; } /* DataType */ code span.dv { color: #40a070; } /* DecVal */ code span.er { color: #ff0000; font-weight: bold; } /* Error */ code span.ex { } /* Extension */ code span.fl { color: #40a070; } /* Float */ code span.fu { color: #06287e; } /* Function */ code span.im { } /* Import */ code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */ code span.kw { color: #007020; font-weight: bold; } /* Keyword */ code span.op { color: #666666; } /* Operator */ code span.ot { color: #007020; } /* Other */ code span.pp { color: #bc7a00; } /* Preprocessor */ code span.sc { color: #4070a0; } /* SpecialChar */ code span.ss { color: #bb6688; } /* SpecialString */ code span.st { color: #4070a0; } /* String */ code span.va { color: #19177c; } /* Variable */ code span.vs { color: #4070a0; } /* VerbatimString */ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */ </style> <!--[if lt IE 9]> <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script> <![endif]--> </head> <body> <header> <h1 class="title">dark-mode keeps your screen dim</h1> <p class="author">By John Mercouris</p> </header> <p>Nyxt has a brand new dark-mode!</p> <p><img src="../static/image/article/wiki-cichlid-dark.png" /></p> <h1 id="how-to-use-it">How to use it?</h1> <p>Simple, just enable <code>dark-mode</code>. That's it! Nyxt will do its best to attempt to configure the screen to be dark, while remaining legible and leaving images/videos unaltered.</p> <p>If you want to selectively enable/disable dark-mode for different domains, you can leverage auto-mode to automatically/enable dark-mode. To find out more check out our article about auto-mode <a href="https://nyxt.atlas.engineer/article/auto-mode.org">here</a>.</p> <h1 id="extended-customization-options">Extended Customization Options</h1> <p>If you want to change the behavior of dark-mode, you have a couple of options:</p> <p>You can either:</p> <ul> <li>match styles based on the domain</li> <li>match styles based on a custom predicate</li> </ul> <p>You can source your styles from:</p> <ul> <li>embedding them directly in your init file</li> <li>placing them in a file on your system</li> <li>downloading them from a remote URL</li> </ul> <p>In order to do this you must make a <code>style-association</code> struct and add it to your <code>style-associations</code> list of your <code>dark-mode</code> configuration.</p> <p>Let's begin with our struct definition:</p> <div class="sourceCode" id="style-association-struct" data-org-language="lisp"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><a class="sourceLine" id="style-association-struct-1" data-line-number="1">(<span class="kw">defstruct</span><span class="fu"> style-association</span></a> <a class="sourceLine" id="style-association-struct-2" data-line-number="2"> (url)</a> <a class="sourceLine" id="style-association-struct-3" data-line-number="3"> (predicate)</a> <a class="sourceLine" id="style-association-struct-4" data-line-number="4"> (style)</a> <a class="sourceLine" id="style-association-struct-5" data-line-number="5"> (style-file)</a> <a class="sourceLine" id="style-association-struct-6" data-line-number="6"> (style-url))</a></code></pre></div> <ul> <li>If you want to match based on URL, provide a URL.</li> <li><p>If you want to match based on a predicate, provide a predicate that accepts a single argument (the URL) and returns t or nil depending on whether the style should be applied.</p></li> <li>If you want to specify a style directly in your <code>style-association</code> struct, use the <code>style</code>.</li> <li>If you want to specify your style via a file use a <code>style-file</code> with a full path to the file to load the style from.</li> <li><p>If you want to specify your style via a URL use a <code>style-url</code> with a full path to the URL with the file to load the style from. Nyxt will download the style and cache it on your system (by default in <code>~/.local/share/nyxt/dark-mode-css-cache</code>).</p></li> </ul> <p>Using this struct definition let's go through some examples:</p> <h2 id="setting-the-style-based-on-url">Setting the style based on URL</h2> <p>In the example below if we visit "<a href="https://example.org" class="uri">https://example.org</a>", our style will be applied.</p> <div class="sourceCode" id="style-association-simple" data-org-language="lisp"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><a class="sourceLine" id="style-association-simple-1" data-line-number="1">(make-style-association</a> <a class="sourceLine" id="style-association-simple-2" data-line-number="2"> :url <span class="st">"https://example.org"</span></a> <a class="sourceLine" id="style-association-simple-3" data-line-number="3"> :style (cl-css:css</a> <a class="sourceLine" id="style-association-simple-4" data-line-number="4"> '((body</a> <a class="sourceLine" id="style-association-simple-5" data-line-number="5"> :background-color <span class="st">"black"</span>))))</a></code></pre></div> <h2 id="setting-the-style-based-on-a-predicate">Setting the style based on a predicate</h2> <p>In the example below if the length of the URL is greater than 10 characters, our style will be applied.</p> <div class="sourceCode" id="style-association-predicate" data-org-language="lisp"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><a class="sourceLine" id="style-association-predicate-1" data-line-number="1">(make-style-association</a> <a class="sourceLine" id="style-association-predicate-2" data-line-number="2"> <span class="bu">:predicate</span> (<span class="kw">lambda</span> (url) (<span class="op">></span> (<span class="kw">length</span> url) <span class="dv">10</span>))</a> <a class="sourceLine" id="style-association-predicate-3" data-line-number="3"> :style (cl-css:css</a> <a class="sourceLine" id="style-association-predicate-4" data-line-number="4"> '((body</a> <a class="sourceLine" id="style-association-predicate-5" data-line-number="5"> :background-color <span class="st">"black"</span>))))</a></code></pre></div> <h2 id="setting-the-style-from-a-file">Setting the style from a file</h2> <p>In the example below, our style will be sourced from a file.</p> <div class="sourceCode" id="style-association-predicate" data-org-language="lisp"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><a class="sourceLine" id="style-association-predicate-1" data-line-number="1">(make-style-association</a> <a class="sourceLine" id="style-association-predicate-2" data-line-number="2"> :url <span class="st">"https://example.org"</span></a> <a class="sourceLine" id="style-association-predicate-3" data-line-number="3"> :style-file <span class="st">"/user/local/file.css"</span>)</a></code></pre></div> <h2 id="setting-the-style-from-a-url">Setting the style from a URL</h2> <p>In the example below, our style will be sourced from a URL.</p> <div class="sourceCode" id="style-association-predicate" data-org-language="lisp"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><a class="sourceLine" id="style-association-predicate-1" data-line-number="1">(make-style-association</a> <a class="sourceLine" id="style-association-predicate-2" data-line-number="2"> :url <span class="st">"https://example.org"</span></a> <a class="sourceLine" id="style-association-predicate-3" data-line-number="3"> :style-url <span class="st">"https://www.example.org/css-file"</span>)</a></code></pre></div> <h2 id="setting-our-style-association-list">Setting our <code>style-association-list</code></h2> <p>When we've collected our list of <code>style-association</code> objects, we will want to set our <code>dark-mode</code> to use them. To do so we can do something like the following:</p> <div class="sourceCode" id="dark-mode-configuration" data-org-language="lisp"><pre class="sourceCode commonlisp"><code class="sourceCode commonlisp"><a class="sourceLine" id="dark-mode-configuration-1" data-line-number="1">(define-configuration nyxt/style-mode::dark-mode</a> <a class="sourceLine" id="dark-mode-configuration-2" data-line-number="2"> ((nyxt/style-mode::style-associations</a> <a class="sourceLine" id="dark-mode-configuration-3" data-line-number="3"> (<span class="kw">list</span> (nyxt/style-mode::make-style-association :url <span class="st">"https://nyxt.atlas.engineer"</span></a> <a class="sourceLine" id="dark-mode-configuration-4" data-line-number="4"> :style (cl-css:css</a> <a class="sourceLine" id="dark-mode-configuration-5" data-line-number="5"> '((body</a> <a class="sourceLine" id="dark-mode-configuration-6" data-line-number="6"> :background-color <span class="st">"gray"</span>))))))))</a></code></pre></div> <p>The above configuration will set the background color of <a href="https://nyxt.atlas.engineer" class="uri">https://nyxt.atlas.engineer</a> to gray.</p> <p>Here are some more examples of the default Nyxt dark-mode in action!</p> <p><img src="../static/image/article/lobsters-bright.png" /></p> <p><img src="../static/image/article/lobsters-dark.png" /></p> <p><img src="../static/image/article/github-bright.png" /></p> <p><img src="../static/image/article/github-dark.png" /></p> <p><img src="../static/image/article/yc-bright.png" /></p> <p><img src="../static/image/article/yc-dark.png" /></p> <p>We hope you enjoy customizing dark-mode and viewing the Internet on your terms!</p> <p>Thanks for reading :-)</p> </body> </html>