-
Notifications
You must be signed in to change notification settings - Fork 4
Description
I was just thinking that most (text) input handlers are fairly simple and provide mostly static values for their (abstract) methods, which makes creation of a separate class rather decoupled from the command's not as transparent as it needs to.
Furthermore, implementing the command's input seems like busy work most of the time and things become especially complicated once you start using multiple handlers and want them to chain using next_input.
I believe a decorator in ArgumentParser.add_argument style could make this API more streamlined while still allowing for the complex case.
API example:
@input_handler("param", kind="text", placeholder="Replace me", validate=lambda _: True)
@input_handler("param2", kind="list", items=list(range(10)))
@input_handler(Param3InputHandler) # name *can* be determined from handler's `name()`
class TestCommand(sublime_plugin.WindowCommand):
def run(self, explicit_param, param, param2, param3, opt_param=None):
passQuestions
-
Technically, input handlers don't have access to the command instance, the window/view or any of the previous parameters. Especially for the complex case, I'm unsure how to provide this information since you'd use custom handlers mostly in those situations when that information is needed. How to handle this? Just pass
window/viewand a dict of all args to the handler's__init__? -
The same issue also surfaces when the list items you want to provide are dynamic.
-
For a similar reason, I don't think
confirm,cancel, ordescriptionmake much sense to be supplied in the decorator short-hand form. -
Use the
kindparam to distinguish, decide based on anitemsparameter, or use two decorators usetext_input_handlerandlist_input_handler?