blob: d074c8086ff8ff8182e3fdcbc16678f51379886a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
.pragma library
// The wallpapers the companion blushes at, as a plain text file: one
// absolute path per line, blank lines and lines starting with # skipped.
// Pure, so test_mood.js drives it; Admired.qml reads and writes the file.
function parse(text) {
const out = [];
for (const l of text.split("\n")) {
const p = l.trim();
if (p !== "" && p[0] !== "#") out.push(p);
}
return out;
}
// text with path's line removed if it is listed, else appended. Comments
// and every other line stay as they are.
function toggle(text, path) {
const lines = text === "" ? [] : text.replace(/\n$/, "").split("\n");
const kept = lines.filter(l => l.trim() !== path);
if (kept.length === lines.length) kept.push(path);
return kept.length ? kept.join("\n") + "\n" : "";
}
// wallp.conf's OUTPUT_H and OUTPUT_V, as { connector: "H" | "V" }. An exec
// loop, because QML's engine has no String.matchAll.
function outputs(conf) {
const out = {};
const re = /^\s*OUTPUT_([HV])\s*=\s*(\S+)/gm;
let m;
while ((m = re.exec(conf)) !== null) out[m[2]] = m[1];
return out;
}
|