Use gholk's arg fork for :colourscheme

This commit is contained in:
Oliver Blanthorn 2025-11-23 18:07:09 +01:00
parent 030ef4d2ab
commit 6124ab93f4
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3

View file

@ -508,7 +508,7 @@ export async function unloadtheme(themename: string) {
*
* If THEMENAME is set to any other value except `--url`, Tridactyl will attempt to use its native binary (see [[native]]) in order to load a CSS file named THEMENAME from disk. The CSS file has to be in a directory named "themes" and this directory has to be in the same directory as your tridactylrc. If this fails, Tridactyl will attempt to load the theme from its internal storage.
*
* Lastly, themes can be loaded from URLs with `:colourscheme --url [url] [themename]`. They are stored internally - if you want to update the theme run the whole command again.
* Lastly, themes can be loaded from URLs with `:colourscheme --url [url] [themename]`. They are stored internally - if you want to update the theme run the whole command again. You can use `%` as a placeholder for the current URL.
*
* Note that the theme name should NOT contain any dot.
*
@ -528,14 +528,15 @@ export async function unloadtheme(themename: string) {
*/
//#background
export async function colourscheme(...args: string[]) {
const themename = args[0] == "--url" ? args[2] : args[0]
const option = arg.lib({"--url": String}, {argv: args, allowNegativePositional: true})
let url = option["--url"]
const themename = option._[0]
// If this is a builtin theme, no need to bother with slow stuff
if (Metadata.staticThemes.includes(themename)) return set("theme", themename)
if (themename.search("\\.") >= 0) throw new Error(`Theme name should not contain any dots! (given name: ${themename}).`)
if (args[0] == "--url") {
if (url) {
if (themename === undefined) throw new Error(`You must provide a theme name!`)
let url = args[1]
if (url === "%") url = window.location.href // this is basically an easter egg
if (!(url.startsWith("http://") || url.startsWith("https://"))) url = "http://" + url
const css = await rc.fetchText(url)