Allow /theme command to return current theme - Add empty args to return theme name on /theme call - Improve help string docs for /theme
| @@ -2968,7 +2968,13 @@ function setAvgBG() { | |||
| 2968 | return ''; | 2968 | return ''; |
| 2969 | } | 2969 | } |
| 2970 | 2970 | ||
| 2971 | async function setThemeCallback(_, text) { | 2971 | async 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-ignore | 2978 | // @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 | }); |
| 2978 | 2984 | ||
| 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; |
| 2982 | 2988 | ||
| 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 | } |
| 2987 | 2993 | ||
| @@ -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', |