Merge pull request #2572 from SillyTavern/theme-command-improvements /theme allows returning current theme & fix /theme and /bg doc

bdafa09c1b389c4f3d446aa4835195c7748deb92

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
2 files changed, +37 -9Showing whitespace changes
public/scripts/power-user.js+30 -7
@@ -2968,7 +2968,13 @@ function setAvgBG() {
29682968 return '';
29692969}
29702970
29712971async function setThemeCallback(_, textthemeName) {
2972+ if (!themeName) {
2973+ // allow reporting of the theme name if called without args
2974+ // for use in ST Scripts via pipe
2975+ return power_user.theme;
2976+ }
2977+
29722978 // @ts-ignore
29732979 const fuse = new Fuse(themes, {
29742980 keys: [
@@ -2976,12 +2982,12 @@ async function setThemeCallback(_, text) {
29762982 ],
29772983 });
29782984
29792985 const results = fuse.search(textthemeName);
29802986 console.debug('Theme fuzzy search results for ' + textthemeName, results);
29812987 const theme = results[0]?.item;
29822988
29832989 if (!theme) {
29842990 toastr.warning(`Could not find theme with name: ${textthemeName}`);
29852991 return;
29862992 }
29872993
@@ -4056,13 +4062,30 @@ $(document).ready(() => {
40564062 callback: setThemeCallback,
40574063 unnamedArgumentList: [
40584064 SlashCommandArgument.fromProps({
40594065 description: 'theme name',
40604066 typeList: [ARGUMENT_TYPE.STRING],
4061- isRequired: true,
40624067 enumProvider: () => themes.map(theme => new SlashCommandEnumValue(theme.name)),
40634068 }),
40644069 ],
4065- helpString: 'sets a UI theme by name',
4070+ helpString: `
4071+ <div>
4072+ Sets a UI theme by name.
4073+ </div>
4074+ <div>
4075+ If no theme name is is provided, this will return the currently active theme.
4076+ </div>
4077+ <div>
4078+ <strong>Example:</strong>
4079+ <ul>
4080+ <li>
4081+ <pre><code>/theme Cappuccino</code></pre>
4082+ </li>
4083+ <li>
4084+ <pre><code>/theme</code></pre>
4085+ </li>
4086+ </ul>
4087+ </div>
4088+ `,
40664089 }));
40674090 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
40684091 name: 'movingui',
public/scripts/slash-commands.js+7 -2
@@ -139,9 +139,8 @@ export function initDefaultSlashCommands() {
139139 returns: 'the current background',
140140 unnamedArgumentList: [
141141 SlashCommandArgument.fromProps({
142142 description: 'background filename',
143143 typeList: [ARGUMENT_TYPE.STRING],
144- isRequired: true,
145144 enumProvider: () => [...document.querySelectorAll('.bg_example')]
146145 .map(it => new SlashCommandEnumValue(it.getAttribute('bgfile')))
147146 .filter(it => it.value?.length),
@@ -152,11 +151,17 @@ export function initDefaultSlashCommands() {
152151 Sets a background according to the provided filename. Partial names allowed.
153152 </div>
154153 <div>
154+ If no background is provided, this will return the currently selected background.
155+ </div>
156+ <div>
155157 <strong>Example:</strong>
156158 <ul>
157159 <li>
158160 <pre><code>/bg beach.jpg</code></pre>
159161 </li>
162+ <li>
163+ <pre><code>/bg</code></pre>
164+ </li>
160165 </ul>
161166 </div>
162167 `,