Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a Sublime Text 2 plugin with a custom display area at the bottom, like the console?

I wish to make a Sublime Text 2 plugin which will display information in an area at the bottom of the screen, just like the console does. However in this area I wish to display my own text from my Plugin, not related to the console.

Here is a screenshot of a window with the console open.

enter image description here

How can this be done?

like image 404
Phil Avatar asked Mar 16 '13 03:03

Phil


People also ask

How do I display output in Sublime Text?

In order for taking input and receiving output from a code, we need to manually set up our input and output files. Step 1: From the top menu, select View->Layout->Columns :3 or press Shift+Alt+3. Step 2: Now select View->Groups->Max columns: 2. Step 3: Now you can view three files simultaneously in sublime text.

How do you use terminus sublime?

Type 'Terminus' and select it. Wait for it to Complete installation and Restart sublime text. And save it. Note: The above code is for Linux users for Windows users you have to enter “cmd.exe” in place of “bash”, also here we kept the shortcut key as “alt+1” you can use your own key.

Is Sublime Text alive?

Sublime is quite alive, and as stated previously, has some alpha testing going on. Any large project has old bugs going back a long way.

How do I open the console in Sublime Text?

Use Ctrl + ' to open the console. When Ctrl + ` is pressed, Sublime Text does not receive anything.


2 Answers

Basically, what you need is

  1. Create an output panel: self.window.get_output_panel("textarea")
  2. Show this panel: self.window.run_command("show_panel", {"panel": "output.textarea"})

A simple example is shown below. And you can refer to exec command in the default package: C:\Users\lhuang\AppData\Roaming\Sublime Text 2\Packages\Default\exec.py.

class ShowTextAreaCommand(sublime_plugin.WindowCommand):
    def run(self):
        self.output_view = self.window.get_output_panel("textarea")
        self.window.run_command("show_panel", {"panel": "output.textarea"})

        self.output_view.set_read_only(False)
        edit = self.output_view.begin_edit()
        self.output_view.insert(edit, self.output_view.size(), "Hello, World!")
        self.output_view.end_edit(edit)
        self.output_view.set_read_only(True)
like image 175
longhua Avatar answered Jan 03 '23 13:01

longhua


And if you're going after Sublime Text 3, where begin_edit() and end_edit() are depreciated:

class ShowTextAreaCommand(sublime_plugin.WindowCommand):
    def run(self):
        self.output_view = self.window.get_output_panel("textarea")
        self.window.run_command("show_panel", {"panel": "output.textarea"})

        self.output_view.set_read_only(False)
        # edit = self.output_view.begin_edit()
        # self.output_view.insert(edit, self.output_view.size(), "Hello, World!")
        self.output_view.run_command("append", {"characters": "Hello, World!"})
        # self.output_view.end_edit(edit)
        self.output_view.set_read_only(True)
like image 42
Miro Avatar answered Jan 03 '23 14:01

Miro