From c2e6903b303fa99bd427c289fe353c2012ae050c Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Sun, 28 Jul 2024 01:15:55 +0200 Subject: [PATCH 1/2] Allow /theme command to return current theme - Add empty args to return theme name on /theme call - Improve help string docs for /theme --- public/scripts/power-user.js | 37 +++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/public/scripts/power-user.js b/public/scripts/power-user.js index 5babc0542..36ed925b3 100644 --- a/public/scripts/power-user.js +++ b/public/scripts/power-user.js @@ -2968,7 +2968,13 @@ function setAvgBG() { return ''; } -async function setThemeCallback(_, text) { +async function setThemeCallback(_, themeName) { + if (!themeName) { + // allow reporting of the theme name if called without args + // for use in ST Scripts via pipe + return power_user.theme; + } + // @ts-ignore const fuse = new Fuse(themes, { keys: [ @@ -2976,12 +2982,12 @@ async function setThemeCallback(_, text) { ], }); - const results = fuse.search(text); - console.debug('Theme fuzzy search results for ' + text, results); + const results = fuse.search(themeName); + console.debug('Theme fuzzy search results for ' + themeName, results); const theme = results[0]?.item; if (!theme) { - toastr.warning(`Could not find theme with name: ${text}`); + toastr.warning(`Could not find theme with name: ${themeName}`); return; } @@ -4056,13 +4062,30 @@ $(document).ready(() => { callback: setThemeCallback, unnamedArgumentList: [ SlashCommandArgument.fromProps({ - description: 'name', + description: 'theme name', typeList: [ARGUMENT_TYPE.STRING], - isRequired: true, enumProvider: () => themes.map(theme => new SlashCommandEnumValue(theme.name)), }), ], - helpString: 'sets a UI theme by name', + helpString: ` +
+ Sets a UI theme by name. +
+
+ If no theme name is is provided, this will return the currently active theme. +
+
+ Example: + +
+ `, })); SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'movingui', From 6b1045ab52b1034c186515f59394081b3d1f1c2d Mon Sep 17 00:00:00 2001 From: Wolfsblvt Date: Sun, 28 Jul 2024 01:17:11 +0200 Subject: [PATCH 2/2] Update /bg docs to match the actual command --- public/scripts/slash-commands.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index aef81d246..bcf980b02 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -139,9 +139,8 @@ export function initDefaultSlashCommands() { returns: 'the current background', unnamedArgumentList: [ SlashCommandArgument.fromProps({ - description: 'filename', + description: 'background filename', typeList: [ARGUMENT_TYPE.STRING], - isRequired: true, enumProvider: () => [...document.querySelectorAll('.bg_example')] .map(it => new SlashCommandEnumValue(it.getAttribute('bgfile'))) .filter(it => it.value?.length), @@ -151,12 +150,18 @@ export function initDefaultSlashCommands() {
Sets a background according to the provided filename. Partial names allowed.
+
+ If no background is provided, this will return the currently selected background. +
Example:
  • /bg beach.jpg
  • +
  • +
    /bg
    +
`,