I am trying to create a console that would work as a shell for a custom programming language. It would be very similar to the pydev interactive console.
Currently, my RCP uses the basic TextConsole and is connected to the shell via pipes so it just displays whatever the shell displays and if the user enters anything in the RCP console, the same is written in the shell.
I want to be able to do a bit more such as move the caret position, add events for up and down arrow keys etc. I believe to do that I need to add a StyledText widget to the console which is done via the ConsoleViewer.
So my question is, that is there any way for me to either override the TextConsole’s ConsoleViewer or if I were to extend TextConsole and create my own, then how do I link it with the launch configuration (the one that connects the shell via pipes)?
Also, to get the current default console I use DebugUITools.getConsole(process).
I’m sorry if I haven’t put all the information needed; it is a bit difficult to explain. I am happy to add more information.
An idea…
From what I understand I can create a TextConsolePage from the TextConsole using createPage(ConsoleView). Once I have the page I can set the viewer via setViewer(viewer). Here I thought if I create my own viewer (which will have the appropriate stylewidget) then that could be a lead. The only problem is that the viewer needs a Composite and I can’t seem to figure out where to get that from.
So I thought I would answer this myself as I was finally able to accomplish the console. It still is a working prototype but I guess as you keep adding things, you can clean up the code more and more. For my current purposes this is how it worked.
If you want the short version, then I basically mimicked the
ProcessConsoleprovided by Eclipse as that is what I needed: a console in which I can connect a process but since theProcessConsoleis internal, I like to avoid extending those classes.Following is an outline of the classes I used to achieve interaction with my console. I am not going to give the pretext as to where
MyConsolewas created. Basically, instead of usingDebugUITools.getConsole(myProcess), I used my ownmyProcess.getConsole()method.MyProcessextendsRuntimeProcess.This is the code for
ProcessConsole.This is the code for
IOConsoleViewer.The
ConsoleHistoryclass I created just had a doubly linked string list to save all the commands the user entered. Quite a simple class to create.Once you look at the Eclipse classes (
ProcessConsoleandIOConsoleViewer) it is actually all quite self explanatory. I haven’t put in much 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 though and add more specific code if anyone asks.