chrissimpkins / glue

Glue is a plugin that joins your shell to Sublime Text in quasi-perfect harmony.
http://gluedocs.readthedocs.org/
MIT License
254 stars 10 forks source link

Arrow to navigate in commands history #16

Open fvelcker opened 10 years ago

fvelcker commented 10 years ago

I didn't really have the time to use your terminal but it sounds great.

But one things is missing for me, is the ability to use the up arrow key to re-display previous command in order to execute it (or modify it).

(And the TAB key as weel to complete folder or file name)

chrissimpkins commented 10 years ago

Great suggestions. I don't keep the history of previous commands but that is simple enough to do. I will need to look into capturing key presses through Sublime Text. I haven't come across a way to do this from the command entry field without interfering with keys that users press in the editor views. I will dig around a bit and see if we can come up with a way to avoid interfering with the editor itself.

fvelcker commented 10 years ago

Happy you like the idea !

I don't know if it can helps, but there is another plugin, "shell-turtlestein", it keeps the history and we can use up/down arrow to navigate.

chrissimpkins commented 10 years ago

Excellent will check out the source and see how they did it. Thanks for the link

FichteFoll commented 10 years ago

Yes please!

chrissimpkins commented 10 years ago

@FichteFoll : are you aware of whether Sublime Text allows you to intercept keystrokes in the input panel? I haven't come across any documentation on this to support path expansions and automatic population of the text field with history. The problem is that users can have the Glue input panel open with multiple source views and I don't want to interfere with the editor in their other views. Eliminating their ability to use up or down arrow and capturing their tab completion in the input panel would limit capabilities in the editor itself.

From what I have gathered from review of all easily accessible documentation out there, this does not appear to be possible.

FichteFoll commented 10 years ago

Maybe. You should be able to set a keybinding to the up key and specify a custom context for that.

You can then define an event hook for context queries in which you determine whether you are in the "glue input" or not and then do whatever you need to do. The problem here is: How do you determine if you are in the input panel? Idea: You can define an on_cancel callback that will tell you if the panel was closed. Afaik you can also not have any other panels at the bottom of the page (e.g. console, output panels or search/replace) but you can have goto anywhere and the command palette active - and I'm not too sure how to differentiate between them. There are a few boolean values you can access but afaik they don't go this far. You'll have to experiment a bit and browse the web. Maybe https://github.com/SublimeText/InactivePanes/ can also help you a bit since it should only work on real views and not these panels.

Another idea would be to ditch the input panel thing completely and work with a separate and special view, some read-only stuff, a <character> binding to allow insertion only at the last line and a lot of context stuff. ST is pretty flexible in that regard, as long as you know which view you are in and you are willing to go through it.

chrissimpkins commented 10 years ago

Thanks for that feedback. To define a new file context, it looks like I can add a new .glue-tmLanguage file to the Packages/User directory with the following:

{ 
    "name": "Glue",
    "scopeName": "text.glue",
    "fileTypes": ["glue"],
    "patterns": []
}

TODO

  1. Does this work from within the Glue packages directory too?
  2. Does Glue have write access to the Packages/User directory on all platforms?

That would get me started with a glue context to capture the keystrokes. I know that the output is bound to the .glue view. The text manipulation only occurs in the terminal.glue view, even if you enter commands with a different active view.

That's a start. I will dig a bit deeper into the docs and see what I can come up with.

ST Syntax Defs Reference

http://docs.sublimetext.info/en/latest/extensibility/syntaxdefs.html#creating-a-new-syntax-definition

FichteFoll commented 10 years ago

First, use this: http://docs.sublimetext.info/en/sublime-text-2/extensibility/syntaxdefs.html#creating-a-new-syntax-definition

Second, instead of reinventing the wheel you could just call view.settings().set('glue', True) when creating a view and then have something like "context": [{ "key": "setting.glue", "operator": "equal", "operand": true }] in your key binding. This is the easiest way to determine if you are within your view.

However, this will not get you anywhere when you want to do this to the input panel (which is what I was talking about in the first solution) because you can not access that handle arbitrarily. You can only get the view's handle from event handlers, e.g. on_activated, and then you need to find out what view you got.

FWIW, I didn't look at your source code a single time apart from the single commit I commented on.

Regarding your questions:

Does this work from within the Glue packages directory too?

Yes, otherwise you couldn't download packages that define syntaxes.

Does Glue have write access to the Packages/User directory on all platforms?

Probably? I don't know, why would you need it?

chrissimpkins commented 10 years ago

@FichteFoll Thanks Fichte. I really appreciate the information. I'll see what I can come up with.

nphirning commented 8 years ago

Any update on this?