mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2024-12-12 17:36:22 +01:00
Merge pull request #2572 from SillyTavern/theme-command-improvements
/theme allows returning current theme & fix /theme and /bg doc
This commit is contained in:
commit
bdafa09c1b
@ -2968,7 +2968,13 @@ function setAvgBG() {
|
|||||||
return '';
|
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
|
// @ts-ignore
|
||||||
const fuse = new Fuse(themes, {
|
const fuse = new Fuse(themes, {
|
||||||
keys: [
|
keys: [
|
||||||
@ -2976,12 +2982,12 @@ async function setThemeCallback(_, text) {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
const results = fuse.search(text);
|
const results = fuse.search(themeName);
|
||||||
console.debug('Theme fuzzy search results for ' + text, results);
|
console.debug('Theme fuzzy search results for ' + themeName, results);
|
||||||
const theme = results[0]?.item;
|
const theme = results[0]?.item;
|
||||||
|
|
||||||
if (!theme) {
|
if (!theme) {
|
||||||
toastr.warning(`Could not find theme with name: ${text}`);
|
toastr.warning(`Could not find theme with name: ${themeName}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4056,13 +4062,30 @@ $(document).ready(() => {
|
|||||||
callback: setThemeCallback,
|
callback: setThemeCallback,
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
SlashCommandArgument.fromProps({
|
SlashCommandArgument.fromProps({
|
||||||
description: 'name',
|
description: 'theme name',
|
||||||
typeList: [ARGUMENT_TYPE.STRING],
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
isRequired: true,
|
|
||||||
enumProvider: () => themes.map(theme => new SlashCommandEnumValue(theme.name)),
|
enumProvider: () => themes.map(theme => new SlashCommandEnumValue(theme.name)),
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
helpString: 'sets a UI theme by name',
|
helpString: `
|
||||||
|
<div>
|
||||||
|
Sets a UI theme by name.
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
If no theme name is is provided, this will return the currently active theme.
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<strong>Example:</strong>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<pre><code>/theme Cappuccino</code></pre>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<pre><code>/theme</code></pre>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
`,
|
||||||
}));
|
}));
|
||||||
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
||||||
name: 'movingui',
|
name: 'movingui',
|
||||||
|
@ -139,9 +139,8 @@ export function initDefaultSlashCommands() {
|
|||||||
returns: 'the current background',
|
returns: 'the current background',
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
SlashCommandArgument.fromProps({
|
SlashCommandArgument.fromProps({
|
||||||
description: 'filename',
|
description: 'background filename',
|
||||||
typeList: [ARGUMENT_TYPE.STRING],
|
typeList: [ARGUMENT_TYPE.STRING],
|
||||||
isRequired: true,
|
|
||||||
enumProvider: () => [...document.querySelectorAll('.bg_example')]
|
enumProvider: () => [...document.querySelectorAll('.bg_example')]
|
||||||
.map(it => new SlashCommandEnumValue(it.getAttribute('bgfile')))
|
.map(it => new SlashCommandEnumValue(it.getAttribute('bgfile')))
|
||||||
.filter(it => it.value?.length),
|
.filter(it => it.value?.length),
|
||||||
@ -151,12 +150,18 @@ export function initDefaultSlashCommands() {
|
|||||||
<div>
|
<div>
|
||||||
Sets a background according to the provided filename. Partial names allowed.
|
Sets a background according to the provided filename. Partial names allowed.
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
If no background is provided, this will return the currently selected background.
|
||||||
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<strong>Example:</strong>
|
<strong>Example:</strong>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<pre><code>/bg beach.jpg</code></pre>
|
<pre><code>/bg beach.jpg</code></pre>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<pre><code>/bg</code></pre>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
`,
|
`,
|
||||||
|
Loading…
Reference in New Issue
Block a user