patx/twig
add dark mode for website
Commit 7edb2c0 · patx · 2026-06-14T10:02:03-04:00
Comments
No comments yet.
Diff
diff --git a/docs/index.html b/docs/index.html
index 82a5ae2..050217e 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -3,8 +3,30 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
+<meta name="color-scheme" content="light dark">
<title>Twig — minimal code editor</title>
<style>
+ :root {
+ color-scheme: light dark;
+ --page-bg: #fff;
+ --text: #111;
+ --body-text: #444;
+ --muted: #888;
+ --subtle: #bbb;
+ --code-bg: #f2f2f2;
+ }
+
+ @media (prefers-color-scheme: dark) {
+ :root {
+ --page-bg: #111;
+ --text: #f2f2f2;
+ --body-text: #d0d0d0;
+ --muted: #a0a0a0;
+ --subtle: #777;
+ --code-bg: #242424;
+ }
+ }
+
body {
font-family: monospace;
font-size: 15px;
@@ -12,22 +34,22 @@
max-width: 600px;
margin: 60px auto;
padding: 0 20px 80px;
- color: #111;
- background: #fff;
+ color: var(--text);
+ background: var(--page-bg);
}
h1 { font-size: 1.1rem; margin: 0 0 8px; }
- h2 { font-size: 0.85rem; margin: 40px 0 12px; text-transform: uppercase; letter-spacing: 0.05em; color: #888; }
- p { color: #444; margin: 0 0 8px; }
- ul { padding-left: 1.2em; color: #444; margin: 0; }
+ h2 { font-size: 0.85rem; margin: 40px 0 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
+ p { color: var(--body-text); margin: 0 0 8px; }
+ ul { padding-left: 1.2em; color: var(--body-text); margin: 0; }
li { margin: 2px 0; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
td { padding: 4px 0; vertical-align: top; }
- td:first-child { width: 55%; color: #111; }
- td:last-child { color: #888; }
- code { background: #f2f2f2; padding: 1px 5px; }
- a { color: #111; }
- footer { margin-top: 48px; color: #bbb; font-size: 0.8rem; }
- pre { background: #f2f2f2; padding: 12px; margin: 0; overflow-x: auto; }
+ td:first-child { width: 55%; color: var(--text); }
+ td:last-child { color: var(--muted); }
+ code { background: var(--code-bg); color: var(--text); padding: 1px 5px; }
+ a { color: var(--text); }
+ footer { margin-top: 48px; color: var(--subtle); font-size: 0.8rem; }
+ pre { background: var(--code-bg); padding: 12px; margin: 0; overflow-x: auto; }
.site-title { display: flex; justify-content: center; align-items: center; gap: 10px; margin-bottom: 25px; }
.site-title img { height: 150px; width: auto; }
</style>
diff --git a/tests/test_helpers.py b/tests/test_helpers.py
new file mode 100644
index 0000000..084f1e7
--- /dev/null
+++ b/tests/test_helpers.py
@@ -0,0 +1,40 @@
+import importlib.util
+import unittest
+from pathlib import Path
+
+
+ROOT = Path(__file__).resolve().parents[1]
+spec = importlib.util.spec_from_file_location("twig", ROOT / "twig.py")
+twig = importlib.util.module_from_spec(spec)
+spec.loader.exec_module(twig)
+
+
+class HelperTests(unittest.TestCase):
+ def test_detect_language_from_filename(self):
+ self.assertEqual(twig.detect_language("example.py"), "python")
+ self.assertEqual(twig.detect_language("index.html"), "html")
+ self.assertEqual(twig.detect_language("style.css"), "css")
+ self.assertEqual(twig.detect_language("script.js"), "javascript")
+ self.assertEqual(twig.detect_language("README.md"), "markdown")
+ self.assertEqual(twig.detect_language("Makefile"), "config")
+ self.assertEqual(twig.detect_language("notes.txt"), "plain")
+
+ def test_clamp_font_size(self):
+ self.assertEqual(twig.clamp_font_size(1), twig.MIN_EDITOR_FONT_SIZE)
+ self.assertEqual(twig.clamp_font_size(12), 12)
+ self.assertEqual(twig.clamp_font_size(99), twig.MAX_EDITOR_FONT_SIZE)
+
+ def test_line_count_for_text(self):
+ self.assertEqual(twig.line_count_for_text(""), 1)
+ self.assertEqual(twig.line_count_for_text("one"), 1)
+ self.assertEqual(twig.line_count_for_text("one\ntwo"), 2)
+ self.assertEqual(twig.line_count_for_text("one\n"), 2)
+
+ def test_select_print_command_prefers_lpr_then_lp(self):
+ self.assertEqual(twig.select_print_command(lambda command: command == "lpr"), "lpr")
+ self.assertEqual(twig.select_print_command(lambda command: command == "lp"), "lp")
+ self.assertIsNone(twig.select_print_command(lambda _command: None))
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/twig.py b/twig.py
index f534897..5ff64c3 100755
--- a/twig.py
+++ b/twig.py
@@ -20,7 +20,7 @@ try:
except (ImportError, ValueError) as exc:
print(
"Twig requires GTK 3, PyGObject, and GtkSourceView.\n"
- "On CrunchBang++/Debian, install:\n"
+ "On Debian/Ubuntu, install:\n"
" sudo apt install python3-gi gir1.2-gtk-3.0 gir1.2-gtksource-4\n"
f"\nStartup error: {exc}",
file=sys.stderr,