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 -9Ignore whitespace
public/scripts/power-user.js+30 -7
@@ -2968,7 +2968,13 @@ function setAvgBG() {
2968 return '';2968 return '';
2969}2969}
29702970
2971async function setThemeCallback(_, text) {2971async function setThemeCallback(_, themeName) {
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
2972 // @ts-ignore2978 // @ts-ignore
2973 const fuse = new Fuse(themes, {2979 const fuse = new Fuse(themes, {
2974 keys: [2980 keys: [
@@ -2976,12 +2982,12 @@ async function setThemeCallback(_, text) {
2976 ],2982 ],
2977 });2983 });
29782984
2979 const results = fuse.search(text);2985 const results = fuse.search(themeName);
2980 console.debug('Theme fuzzy search results for ' + text, results);2986 console.debug('Theme fuzzy search results for ' + themeName, results);
2981 const theme = results[0]?.item;2987 const theme = results[0]?.item;
29822988
2983 if (!theme) {2989 if (!theme) {
2984 toastr.warning(`Could not find theme with name: ${text}`);2990 toastr.warning(`Could not find theme with name: ${themeName}`);
2985 return;2991 return;
2986 }2992 }
29872993
@@ -4056,13 +4062,30 @@ $(document).ready(() => {
4056 callback: setThemeCallback,4062 callback: setThemeCallback,
4057 unnamedArgumentList: [4063 unnamedArgumentList: [
4058 SlashCommandArgument.fromProps({4064 SlashCommandArgument.fromProps({
4059 description: 'name',4065 description: 'theme name',
4060 typeList: [ARGUMENT_TYPE.STRING],4066 typeList: [ARGUMENT_TYPE.STRING],
4061 isRequired: true,
4062 enumProvider: () => themes.map(theme => new SlashCommandEnumValue(theme.name)),4067 enumProvider: () => themes.map(theme => new SlashCommandEnumValue(theme.name)),
4063 }),4068 }),
4064 ],4069 ],
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 `,
4066 }));4089 }));
4067 SlashCommandParser.addCommandObject(SlashCommand.fromProps({4090 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
4068 name: 'movingui',4091 name: 'movingui',
public/scripts/slash-commands.js+7 -2
@@ -139,9 +139,8 @@ export function initDefaultSlashCommands() {
139 returns: 'the current background',139 returns: 'the current background',
140 unnamedArgumentList: [140 unnamedArgumentList: [
141 SlashCommandArgument.fromProps({141 SlashCommandArgument.fromProps({
142 description: 'filename',142 description: 'background filename',
143 typeList: [ARGUMENT_TYPE.STRING],143 typeList: [ARGUMENT_TYPE.STRING],
144 isRequired: true,
145 enumProvider: () => [...document.querySelectorAll('.bg_example')]144 enumProvider: () => [...document.querySelectorAll('.bg_example')]
146 .map(it => new SlashCommandEnumValue(it.getAttribute('bgfile')))145 .map(it => new SlashCommandEnumValue(it.getAttribute('bgfile')))
147 .filter(it => it.value?.length),146 .filter(it => it.value?.length),
@@ -152,11 +151,17 @@ export function initDefaultSlashCommands() {
152 Sets a background according to the provided filename. Partial names allowed.151 Sets a background according to the provided filename. Partial names allowed.
153 </div>152 </div>
154 <div>153 <div>
154 If no background is provided, this will return the currently selected background.
155 </div>
156 <div>
155 <strong>Example:</strong>157 <strong>Example:</strong>
156 <ul>158 <ul>
157 <li>159 <li>
158 <pre><code>/bg beach.jpg</code></pre>160 <pre><code>/bg beach.jpg</code></pre>
159 </li>161 </li>
162 <li>
163 <pre><code>/bg</code></pre>
164 </li>
160 </ul>165 </ul>
161 </div>166 </div>
162 `,167 `,