randy3k / Terminus

Bring a real terminal to Sublime Text

Home Page:https://packagecontrol.io/packages/Terminus

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

auto hide terminal if build output is empty

ryuukk opened this issue · comments

This is the kind of thing that drive me crazy with sublime text

I fixed the default exec plugin sublimehq/Packages#3945

But i need colors, so i have to use this plugin, i tried to hack things around, managed to make it build, i managed to detect wether it is empty or not, but i can't figure out how to close the damn panel

            "target": "terminus_exec_test",
            "cancel": "terminus_cancel_build",
DEFAULT_PANEL = "Terminus"
DEFAULT_TITLE = "Terminus"
EXEC_PANEL = "Terminus Build Results"
CONTINUATION = "\u200b\u200c\u200b"
class TerminusExecTestCommand(sublime_plugin.WindowCommand):
    def run(self, **kwargs):
        if "kill" in kwargs and kwargs["kill"]:
            self.window.run_command("terminus_cancel_build")
            return

        if "cmd" not in kwargs and "shell_cmd" not in kwargs:
            raise Exception("'cmd' or 'shell_cmd' is required")
        if "show_in_panel" in kwargs and kwargs["show_in_panel"] is False:
            raise Exception("'show_in_panel must be True")
        if "panel_name" in kwargs:
            raise Exception("'panel_name' must not be specified")
        if "tag" in kwargs:
            raise Exception("'tag' must not be specified")
        kwargs["panel_name"] = EXEC_PANEL
        if "focus" not in kwargs:
            kwargs["focus"] = False
        if "auto_close" not in kwargs:
            kwargs["auto_close"] = False
        if "cancellable" not in kwargs:
            kwargs["cancellable"] = True
        if "reactivable" not in kwargs:
            kwargs["reactivable"] = False
        if "timeit" not in kwargs:
            kwargs["timeit"] = True
        for key in ["encoding", "quiet", "word_wrap", "syntax"]:
            if key in kwargs:
                del kwargs[key]
        # kwargs["auto_close"] = True
        self.window.run_command("terminus_open", kwargs)

        panel = self.window.find_output_panel(EXEC_PANEL)

        if panel == None:
            return
        content = panel.substr(sublime.Region(0, panel.size()))
        print("######")
        print(content)
        if content.startswith("[Finished in"):
            print("close!")
            # self.window.focus_view(panel)
            self.window.run_command("hide_panel")
            panel.run_command("terminus_close")
######
[Finished in 0.54s]
close!

Yet the panel doesn't close.., something seems to prevent it, do you know what?

My theory is

  • self.window.run_command("terminus_open", kwargs) is async?
  • it finds [Finished in only because i ran it before so it's in the buffer?

So question is, how to await it?