Quantcast
Download
(10 Kb)
Download
Updated: 05/20/19 09:00 AM
Pictures
File Info
Compatibility:
Elsweyr (5.0.5)
Updated:05/20/19 09:00 AM
Created:10/19/16 09:56 AM
Monthly downloads:10,024
Total downloads:15,477
Favorites:56
MD5:
5.0.5
LibSlashCommander  Updated this week!  Popular! (More than 5000 hits)
Version: 1.0 r6
by: sirinsidiator [More]
This library wraps around slash commands and adds many useful features.
  • Autocompletion for all slash commands
  • Color coding and description for all built-in commands
  • Functions for addon authors to register their own commands with a description
  • Subcommands for structured menus
  • Autocompletion for subcommands
  • Custom autocompletion handlers for easy parameter selection

Quick Start

In order to use the library, the following line has to be included in the addon manifest:

Code:
## DependsOn: LibSlashCommander
A simple slash command is then registered with the following code:

Lua Code:
  1. local LSC = LibSlashCommander
  2. LSC:Register("/mycommand", function(input) d(input) end, "Prints the specified text")

You can also add multiple names for the same command

Lua Code:
  1. LSC:Register({"/mycommand", "/mycmd"}, function(input) d(input) end, "Prints the specified text")

Alternatively you can also set the values on the Command object which is returned from Register.

Lua Code:
  1. local LSC = LibSlashCommander
  2. local command = LSC:Register()
  3. command:AddAlias("/mycommand")
  4. command:AddAlias("/mycmd")
  5. command:SetCallback(function(input) d(input) end)
  6. command:SetDescription("Prints the specified text")

In order to add a subcommand to the new command you can call RegisterSubCommand and set the properties like before.
Lua Code:
  1. local subCommand = command:RegisterSubCommand()
  2. subCommand:AddAlias("fail")
  3. subCommand:SetCallback(function() error("as expected") end)
  4. subCommand:SetDescription("Produces an error")

If the base command has a callback, it will still get called if there is no matching subcommand alias. You can also register subcommands to a subcommand to create a tree of commands.

Autocompletion for your registered subcommands will automatically turn on as long as there is no custom autocompletion enabled. In order to disable the built in autocompletion for your subcommands you can either call command:SetAutoComplete(false) or set your own autocompletion.

There are two ways to make your own autocompletion.
Either you supply a numerically indexed table of strings to SetAutoComplete:
Lua Code:
  1. command:SetAutoComplete({"foo", "bar", "baz"})

Or you create your own AutoCompleteProvider:
Lua Code:
  1. local MyAutoCompleteProvider = LSC.AutoCompleteProvider:Subclass()
  2. function MyAutoCompleteProvider:New()
  3.     return LSC.AutoCompleteProvider.New(self)
  4. end
  5.  
  6. function MyAutoCompleteProvider:GetResultList()
  7.     return {
  8.         foo = "foo",
  9.         bar = "bar",
  10.         baz = "baz",
  11.     }
  12. end
  13.  
  14. command:SetAutoComplete(MyAutoCompleteProvider:New())

The key in the table returned from GetResultList will be used to determine which results should show up in the autocomplete box.
The values will be used as the label for the entries and also show up in the chat input box when you select an entry.

If you want to have a different label, you can use the GetResultFromLabel method to transform the displayed entry to something else on select.
Lua Code:
  1. function MyAutoCompleteProvider:GetResultFromLabel(label)
  2.     return "always the same"
  3. end

The simplest way to handle it is to generate a lookup table in GetResultList and then just return lookup[label].
You can also generate the results on the fly, but keep in mind that GetResultList will be called on every change to the chat input, so it is usually better to cache the results.

API Reference
Will follow soon.
r6
- added new global for access without LibStub (LibStub is still used internally for now)
- updated for Elsweyr

r5
- fixed autocompletion showing up when browsing the command history
- removed min score requirement for autocomplete results (meaning it will always show 10 results, even when they are not a match)
Optional Files (0)


Archived Files (2)
File Name
Version
Size
Uploader
Date
1.0 r5
10kB
sirinsidiator
06/17/18 02:23 PM
1.0 r4
9kB
10/19/16 09:56 AM


Post A Reply Comment Options
Unread 05/20/19, 09:54 AM  
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view AddOns

Forum posts: 1226
File comments: 761
Uploads: 32
Re: LIbstub embedded version 4

Originally Posted by Anceane
The libstub library embedded with this lib package is version 4, should it be the last version 5 or no problem ?
There is no difference between LibStub r4 and r5. The version increment was only for the standalone package, so it doesn't matter which one is embedded.
__________________
Like what I do? Support me on Patreon!
>siri.exe MyAddon
Does your addon work? [y/n] n
There is a typo in there.
Report comment to moderator  
Reply With Quote
Unread 05/20/19, 09:23 AM  
Anceane
 
Anceane's Avatar

Forum posts: 186
File comments: 661
Uploads: 0
LIbstub embedded version 4

The libstub library embedded with this lib package is version 4, should it be the last version 5 or no problem ?
__________________
Report comment to moderator  
Reply With Quote
Unread 05/19/19, 07:47 AM  
Anceane
 
Anceane's Avatar

Forum posts: 186
File comments: 661
Uploads: 0
Re: Re: even with out of date addon checked, this library would not load

Originally Posted by sirinsidiator
Originally Posted by Anceane
Even with the out of date checked, to be able to use the addon Beammeup, i had to force update api on this library and the one called

https://www.esoui.com/downloads/file...=2171#comments

Do i need to do more ?
Did you by chance install it while the game was running? I remember someone else having a similar problem with another addon, where a simple reload ui was not enough after enabling the out of date checkbox. They had to restart the game in order to get it working.
No, game was off, and after multiple attempts, the only thing that worked was to up the api to 100026 100027.

The game was seeing both librairies but marking those as not a compatible version. So i guessed that updating API would perhaps do the trick. And it did it
__________________
Report comment to moderator  
Reply With Quote
Unread 05/19/19, 07:31 AM  
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view AddOns

Forum posts: 1226
File comments: 761
Uploads: 32
Re: even with out of date addon checked, this library would not load

Originally Posted by Anceane
Even with the out of date checked, to be able to use the addon Beammeup, i had to force update api on this library and the one called

https://www.esoui.com/downloads/file...=2171#comments

Do i need to do more ?
Did you by chance install it while the game was running? I remember someone else having a similar problem with another addon, where a simple reload ui was not enough after enabling the out of date checkbox. They had to restart the game in order to get it working.
__________________
Like what I do? Support me on Patreon!
>siri.exe MyAddon
Does your addon work? [y/n] n
There is a typo in there.
Report comment to moderator  
Reply With Quote
Unread 05/18/19, 06:11 PM  
Anceane
 
Anceane's Avatar

Forum posts: 186
File comments: 661
Uploads: 0
even with out of date addon checked, this library would not load

Even with the out of date checked, to be able to use the addon Beammeup, i had to force update api on this library and the one called

https://www.esoui.com/downloads/file...=2171#comments

Do i need to do more ?
__________________
Report comment to moderator  
Reply With Quote
Unread 10/21/16, 06:17 AM  
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view AddOns

Forum posts: 1226
File comments: 761
Uploads: 32
Originally Posted by code65536
Could you please add a check so that the auto-complete selection box closes itself once the slash command has been completed and there are no auto-completes available for the parameters?

For example, once I type "/script<SPACEBAR>", the auto-complete selection box should close because I've completed the slash command portion with the <SPACEBAR>, and for the "/script" command, there are no parameters to auto-complete.

The reason I'm asking for this is because for a number of slash commands, I need to see or reference what is being shown in the chat box, and the auto-complete selection box covers up the chat. "/script" is the most prominent example because I use it to test/debug stuff which often requires looking at chat output, but there are probably other cases too.

Thanks in advance.
I'll see what I can do. For now you can use the tab key instead of space to get it to disappear.
__________________
Like what I do? Support me on Patreon!
>siri.exe MyAddon
Does your addon work? [y/n] n
There is a typo in there.
Report comment to moderator  
Reply With Quote
Unread 10/21/16, 05:42 AM  
code65536
AddOn Author - Click to view AddOns

Forum posts: 17
File comments: 104
Uploads: 18
Could you please add a check so that the auto-complete selection box closes itself once the slash command has been completed and there are no auto-completes available for the parameters?

For example, once I type "/script<SPACEBAR>", the auto-complete selection box should close because I've completed the slash command portion with the <SPACEBAR>, and for the "/script" command, there are no parameters to auto-complete.

The reason I'm asking for this is because for a number of slash commands, I need to see or reference what is being shown in the chat box, and the auto-complete selection box covers up the chat. "/script" is the most prominent example because I use it to test/debug stuff which often requires looking at chat output, but there are probably other cases too.

Thanks in advance.
Report comment to moderator  
Reply With Quote
Post A Reply



Category Jump:

Support AddOn Development!

You have just downloaded by the author . If you like this AddOn why not consider supporting the author? This author has set up a donation account. Donations ensure that authors can continue to develop useful tools for everyone.