Skip to content

input_handler class decorator to automatically add and create simple input handlers #136

@FichteFoll

Description

@FichteFoll

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):
        pass

Questions

  1. 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/view and a dict of all args to the handler's __init__?

  2. The same issue also surfaces when the list items you want to provide are dynamic.

  3. For a similar reason, I don't think confirm, cancel, or description make much sense to be supplied in the decorator short-hand form.

  4. Use the kind param to distinguish, decide based on an items parameter, or use two decorators use text_input_handler and list_input_handler?

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionThe issue is being evaluatedenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions