Eclipse RCP: user console

I am trying to create a console that will work as a shell for a custom programming language. This would be very similar to the pydev interactive console.

Currently, my RCP uses the base TextConsole and connects to the shell through the channels, so it just displays everything that is displayed in the shell, and if the user enters anything into the RCP console, then it is written to the shell.

I want to be able to do a little more, for example, move the caret position, add events for the up and down arrow keys, etc. I believe that I need to add the StyledText widget to the console, which runs through the ConsoleViewer.

So my question is: is there any way for me to override the TextConsole ConsoleViewer, or if I have to extend the TextConsole and create my own, then how can I associate it with the startup configuration (the one that connects the shell through pipes)?

Also, to get the current default console, I use DebugUITools.getConsole(process) .

Sorry if I did not put all the necessary information; it's a little hard to explain. I am pleased to add further information.

The idea ... As I understand it, I can create a TextConsolePage from a TextConsole using createPage(ConsoleView) . As soon as I have a page, I can set the viewer through setViewer(viewer) . Here I thought that if I create my own viewer (which will have the appropriate style), then this can be leading. The only problem is that the viewer needs a Composite, and I cannot figure out where to get it.

+4
source share
2 answers

So, I thought that I would answer this myself, since, finally, I was able to execute the console. This is still a working prototype, but I think as you keep adding things, you can clear the code more and more. For my current purposes, this is how it worked.

If you want a short version, I basically mimicked the ProcessConsole provided by Eclipse, as that was what I needed: a console where I can hook the process, but since the ProcessConsole is internal, I like to avoid extending these classes.

The following is a diagram of the classes that I used to interact with my console. I am not going to give an excuse where MyConsole was created. Basically, instead of using DebugUITools.getConsole(myProcess) I used my own method myProcess.getConsole() . MyProcess extends RuntimeProcess .

 class MyConsole extends IOConsole { private IOConsoleInputStream fInput; private IOConsoleOutputStream fOutput; private IStreamsProxy fStreamsProxy; private ConsoleHistory history; //This is to remember the caret position after the prompt private int caretAtPrompt; /* in the console so when you need to replace the command on up and down * arrow keys you have the position. * I just did a caretAtPrompt += String.Length wherever string was * appended to the console. Mainly in the streamlistener and * InputJob unless you specifically output something to the output * stream. */ //In the constructor you assign all the above fields. Below are some //to point out. //fInput = getInputStream(); // fStreamsProxy = process.getStreamsProxy(); // fOutput = newOutputStream(); //We must override the following method to get access to the caret @Override public IPageBookViewPage createPage(IConsoleView view) { return new MyConsolePage(this, view); } //After this I followed the ProcessConsole and added the //InputJob and StreamListener //defined in there. } class MyConsolePage extends TextConsolePage { //Not much in this class, just override the createViewer // to return MyConsoleViewer } class MyConsoleViewer extends TextConsoleViewer { //This is the most important class and most of the work is done here //Again I basically copied everything from IOConsoleViewer and then //updated whatever I needed //I added a VerifyKeyListener for the up and down arrow //keys for the console history MyConsoleViewer (Composite parent, MyConsole console) { //I have omitted a lot of code as it was too much to put up, //just highlighted a few getTextWidget().addVerifyKeyListener(new MyKeyChecker()); } class MyKeyChecker implements VerifyKeyListener {...} } 

This is the code for ProcessConsole . This is the code for IOConsoleViewer .

The ConsoleHistory class I ConsoleHistory consisted of only a double-linked list of strings to save all the commands entered by the user. A fairly simple class to create.

As soon as you look at the Eclipse classes ( ProcessConsole and IOConsoleViewer ), this is actually all clear. I have not added a lot of code here because there is quite a bit. But hopefully this gives some direction as I was completely lost when I started.

I am happy to answer questions and add more specific code if someone asks.

+2
source

Source: https://habr.com/ru/post/1411752/


All Articles