Home Download Buy Blog Forum Support

Indicator bar

Indicator bar

Postby bitserf on Thu Mar 01, 2012 9:59 am

Hi,

I'm looking for something I'm not sure is possible with the current plugin API.

I'm using the RubyText plugin, and it works great for running unit tests from within the editor, but what I am used to from when I use VIM is slightly more obtrusive pass/fail indicators.

To give you an idea of what I mean, here's a screenshot of what happens when I kick off a unit test run from within VIM.

http://yfrog.com/z/nvuyxp

I'd like to have a similar thing show up in the Sublime Text UI, and I thought I'd try to hack it into the RubyTest plugin.

Most important to me is that I be able to display PASS/FAIL in green/red.

But I couldn't see a way to display a colored temporary indicator like this that is dismissed when next I type into the window, or a small timeout elapses, whichever happens first. Just to be clear, monochrome status bar text is not obtrusive enough for me.

Any ideas?

Thanks!
bitserf
 
Posts: 1
Joined: Thu Mar 01, 2012 9:52 am

Re: Indicator bar

Postby jbjornson on Thu Mar 01, 2012 11:27 am

Hi bitserf,

Unfortunately I can't see the screenshot you linked to (blocked by my work), but I have some ideas on how you might approach this type of issue.

Maybe you can create your own output panel for the test results, write your results to that output panel and set the syntax of the panel to use a custom syntax that adequately "highlights" your results.

Your plugin can write to the panel as it completes the test cases, giving you a decent progress indicator. You could also get creative with the message that you are writing and include the overall success status of the test cases alongside the status of the most recent test case. If you also know how many test cases there are and which one you are on, you could provide a %-complete indication as well.

Here is a very basic custom syntax to use as an example. If your line starts with "FAIL" it will highlight the word FAIL (according to your color scheme). Save this file in "Packages/User/TestCaseResults.tmLanguage".
Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>patterns</key>
        <array>
            <dict>
                <key>match</key>
                <string>^FAIL</string>
                <key>name</key>
                <string>invalid.illegal.unexpected-text.test_case_results</string>
            </dict>
        </array>
        <key>name</key>
        <string>Test case results custom syntax</string>
        <key>scopeName</key>
        <string>source.test_case_results</string>
    </dict>
</plist>


Creating a custom syntax to highlight your test case results may take some fiddling, but shouldn't be too tough (depending on how complicated your test case results are and how much coloring you want).

Here are some resources on creating a custom syntax (aka language grammars). There are also a bunch of forum discussion about creating custom syntaxes.
http://manual.macromates.com/en/language_grammars
http://sublimetext.info/docs/en/extensi ... xdefs.html

Here is some example code to make your own output panel, write to it and set the syntax. This code will request some input and simply echo that to an output panel. To see the custom syntax working, you will need to enter some text that starts with "FAIL".
Code: Select all
import sublime, sublime_plugin

class ExampleCommand(sublime_plugin.WindowCommand):
    def run(self):
        sublime.active_window().show_input_panel('Enter a test case result to append to the output panel', '', lambda s: self.appendTestCaseResult(s), None, None)

    def appendTestCaseResult(self, message):
        # some unique name for your output panel
        panel_name = 'MyPluginName-OutputPanel'

        # relative path to your custom syntax
        custom_syntax = 'Packages/User/TestCaseResults.tmLanguage'

        # only use "get_output_panel" once, otherwise sublime will
        # recreate a new one and you will lose any existing text
        if not hasattr(self, 'panel'):
            self.panel = sublime.active_window().get_output_panel(panel_name)
        v = self.panel

        # write this text to the output panel and display it
        edit = v.begin_edit()
        v.insert(edit, v.size(), message + '\n')
        v.end_edit(edit)
        v.show_at_center(v.size())

        # set the syntax of the output panel
        v.set_syntax_file(custom_syntax)

        # make sure the panel is visible
        sublime.active_window().run_command("show_panel", {"panel": "output." + panel_name})


Hope that helps.

Cheers,
Josh
jbjornson
 
Posts: 350
Joined: Tue Oct 27, 2009 4:25 pm
Location: Zurich, Switzerland


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 1 guest