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