Sublime Forum

Style the input panel


Is it possible to style the input panel?

I have my own incremental search implementation which is more like - wait for it - emacs, and I just wish I could change the style of the text to red, for example, as soon as what’s being searched for doesn’t exist in the document.

It’s a view … so … is it possible to define regions there?

Also - when setting regions in the main view window (that you’re searching) you have to specify a scope. I guess I am not 100% sure what that means even though I have been using it for ages.

Silly me - I just read the docs more carefully. The scope is used as a source for the color to use.

So - do themes tend to have a scope which means “error” that I can assume exists?

So - two questions: can I apply regions in the input panel to style it, and is there a generic “error” scope that I can expect to exist in most themes?




OK - all I really care about is the ability to style the input view.

If I could change the input panel prompt while it was open, that would be amazing.

Any hope for me?



The View.show_input_panel returns the view object corresponding to the input widget, so you can capture the view object in a variable & theoretically apply any view related methods to it.
As an example,

import sublime
import sublime_plugin

class ExampleStyleInputCommand(sublime_plugin.WindowCommand):

    def run(self):
        input_view = self.window.show_input_panel(caption="Example", initial_text="Example", on_done = self.on_done, on_change = None, on_cancel = None)
        input_view.add_regions("example", [sublime.Region(0, 7)], scope = "region.redish", flags = sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_SQUIGGLY_UNDERLINE)

    def on_done(self, text):
        if text is not None:

You can see we capture the returned view object in the variable input_view & then use the View.add_regions to add any specific regions we want. This example uses of the region.redish pseudoscope for the error part and a combination of the flags (for the red squiggle).

Here is how it looks like :-

I think beyond this (beyond what is provided by add_regions), very custom styling is not possible via the API.

Hope it helps.



Wow - super helpful!

Sadly the syntax file for the input panel is text/plain so there are no colours to choose from.

I tried changing the syntax file to the same as the view I was currently editing in, but that caused the input_panel to close immediately for some reason … Probs because key presses were being interpreted based on that syntax.

So I need a new simple syntax with a few scopes that define some colours. Huh … fascinating.



OK I am super happy with the result.