Download
(11 Kb)
Download
Updated: 02/24/20 02:40 AM
Pictures
File Info
Compatibility:
Harrowstorm (5.3.5)
Updated:02/24/20 02:40 AM
Created:10/19/16 09:56 AM
Monthly downloads:4,010
Total downloads:494,372
Favorites:399
MD5:
LibSlashCommander  Popular! (More than 5000 hits)
Version: 1.1.0
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.
v1.1.0
- switched to semantic versioning
- changed internal structure
- updated for Harrowstorm

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 (3)
File Name
Version
Size
Uploader
Date
1.0 r6
10kB
sirinsidiator
05/20/19 09:00 AM
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/28/23, 06:59 AM  
Orion33

Forum posts: 0
File comments: 37
Uploads: 0
How to disable default chat changing?
Report comment to moderator  
Reply With Quote
Unread 08/17/20, 09:36 PM  
tawniey

Forum posts: 7
File comments: 13
Uploads: 0
Re: Re: Error message, (live, not pts)

Originally Posted by sirinsidiator
Originally Posted by tawniey
Hello!

I'm receiving this error message when using this:

user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:164: attempt to index a nil value
stack traceback:
user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:164: in function 'Load'
user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:194: in function 'Init'
user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:656: in function '(main chunk)'
|caaaaaa<Locals> MAJOR = "LibSlashCommander", MINOR = 6, lib = [table:1]{COMMAND_TYPE_EMOTE = 3, COMMAND_TYPE_CHAT_SWITCH = 2, WARNING_ALREADY_HAS_ALIAS = "Warning: Overwriting existing ...", COMMAND_TYPE_ADDON = 4, ERROR_CIRCULAR_HIERARCHY = "Circular hierarchy detected", ERROR_AUTOCOMPLETE_NOT_ACTIVE = "Tried to get autocomplete resu...", ERROR_ALREADY_HAS_PARENT = "Command already has a parent", ERROR_INVALID_TYPE = "Invalid argument type", COMMAND_TYPE_BUILT_IN = 1, ERROR_CALLED_WITHOUT_CALLBACK = "Tried to call command while no...", ERROR_HAS_NO_PARENT = "Command does not have a parent...", ERROR_AUTOCOMPLETE_RESULT_NOT_VALID = "Autocomplete provider returned..."}, RunAutoCompletion = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:45, GetCurrentCommandAndToken = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:52, Sanitize = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:61, OnTextEntryChanged = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:65, OnSetChannel = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:79, StartCommandAtIndex = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:83, AutocompleteOnTextChanged = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:88, OnAutoCompleteEntrySelected = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:95, GetTopMatches = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:110, GetAutoCompletionResults = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:118, GetDescriptionText = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:129, Unload = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:150, Load = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:160 </Locals>|r
The line numbers in your error message do not match up with the current version of the library. Make sure you install the latest version!
oh, strange! I use Minion to update, idk why it wasn't updating! Thank you!
Report comment to moderator  
Reply With Quote
Unread 08/02/20, 06:20 AM  
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view AddOns

Forum posts: 1566
File comments: 1119
Uploads: 41
Re: Error message, (live, not pts)

Originally Posted by tawniey
Hello!

I'm receiving this error message when using this:

user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:164: attempt to index a nil value
stack traceback:
user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:164: in function 'Load'
user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:194: in function 'Init'
user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:656: in function '(main chunk)'
|caaaaaa<Locals> MAJOR = "LibSlashCommander", MINOR = 6, lib = [table:1]{COMMAND_TYPE_EMOTE = 3, COMMAND_TYPE_CHAT_SWITCH = 2, WARNING_ALREADY_HAS_ALIAS = "Warning: Overwriting existing ...", COMMAND_TYPE_ADDON = 4, ERROR_CIRCULAR_HIERARCHY = "Circular hierarchy detected", ERROR_AUTOCOMPLETE_NOT_ACTIVE = "Tried to get autocomplete resu...", ERROR_ALREADY_HAS_PARENT = "Command already has a parent", ERROR_INVALID_TYPE = "Invalid argument type", COMMAND_TYPE_BUILT_IN = 1, ERROR_CALLED_WITHOUT_CALLBACK = "Tried to call command while no...", ERROR_HAS_NO_PARENT = "Command does not have a parent...", ERROR_AUTOCOMPLETE_RESULT_NOT_VALID = "Autocomplete provider returned..."}, RunAutoCompletion = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:45, GetCurrentCommandAndToken = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:52, Sanitize = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:61, OnTextEntryChanged = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:65, OnSetChannel = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:79, StartCommandAtIndex = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:83, AutocompleteOnTextChanged = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:88, OnAutoCompleteEntrySelected = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:95, GetTopMatches = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:110, GetAutoCompletionResults = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:118, GetDescriptionText = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:129, Unload = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:150, Load = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:160 </Locals>|r
The line numbers in your error message do not match up with the current version of the library. Make sure you install the latest version!
Report comment to moderator  
Reply With Quote
Unread 08/02/20, 02:25 AM  
tawniey

Forum posts: 7
File comments: 13
Uploads: 0
Error message, (live, not pts)

Hello!

I'm receiving this error message when using this:

user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:164: attempt to index a nil value
stack traceback:
user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:164: in function 'Load'
user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:194: in function 'Init'
user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:656: in function '(main chunk)'
|caaaaaa<Locals> MAJOR = "LibSlashCommander", MINOR = 6, lib = [table:1]{COMMAND_TYPE_EMOTE = 3, COMMAND_TYPE_CHAT_SWITCH = 2, WARNING_ALREADY_HAS_ALIAS = "Warning: Overwriting existing ...", COMMAND_TYPE_ADDON = 4, ERROR_CIRCULAR_HIERARCHY = "Circular hierarchy detected", ERROR_AUTOCOMPLETE_NOT_ACTIVE = "Tried to get autocomplete resu...", ERROR_ALREADY_HAS_PARENT = "Command already has a parent", ERROR_INVALID_TYPE = "Invalid argument type", COMMAND_TYPE_BUILT_IN = 1, ERROR_CALLED_WITHOUT_CALLBACK = "Tried to call command while no...", ERROR_HAS_NO_PARENT = "Command does not have a parent...", ERROR_AUTOCOMPLETE_RESULT_NOT_VALID = "Autocomplete provider returned..."}, RunAutoCompletion = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:45, GetCurrentCommandAndToken = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:52, Sanitize = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:61, OnTextEntryChanged = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:65, OnSetChannel = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:79, StartCommandAtIndex = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:83, AutocompleteOnTextChanged = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:88, OnAutoCompleteEntrySelected = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:95, GetTopMatches = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:110, GetAutoCompletionResults = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:118, GetDescriptionText = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:129, Unload = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:150, Load = user:/AddOns/LibSlashCommander/LibSlashCommander/LibSlashCommander.lua:160 </Locals>|r
Report comment to moderator  
Reply With Quote
Unread 01/29/20, 07:04 AM  
Marazota
AddOn Author - Click to view AddOns

Forum posts: 257
File comments: 1517
Uploads: 2
error on PTS

Report comment to moderator  
Reply With Quote
Unread 05/20/19, 09:54 AM  
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view AddOns

Forum posts: 1566
File comments: 1119
Uploads: 41
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.
Report comment to moderator  
Reply With Quote
Unread 05/20/19, 09:23 AM  
Anceane
 
Anceane's Avatar
AddOn Author - Click to view AddOns

Forum posts: 306
File comments: 1017
Uploads: 1
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
AddOn Author - Click to view AddOns

Forum posts: 306
File comments: 1017
Uploads: 1
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: 1566
File comments: 1119
Uploads: 41
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.
Report comment to moderator  
Reply With Quote
Unread 05/18/19, 06:11 PM  
Anceane
 
Anceane's Avatar
AddOn Author - Click to view AddOns

Forum posts: 306
File comments: 1017
Uploads: 1
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: 1566
File comments: 1119
Uploads: 41
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.
Report comment to moderator  
Reply With Quote
Unread 10/21/16, 05:42 AM  
code65536
AddOn Author - Click to view AddOns

Forum posts: 21
File comments: 371
Uploads: 40
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.