I\'m writing an eclipse-plugin which creating a new Console. Please see my source code:
CliConsoleFactory.java
import java.io.IOException;
import or
To gain access to the caret position, you will need to implement a console viewer.
This is the setup I have for my custom console,
public class MyConsole extends IOConsole
{
....
@Override
public IPageBookViewPage createPage(IConsoleView view) {
return new MyConsolePage(this, view);
}
}
public class MyConsolePage extends TextConsolePage
{
....
@Override
protected TextConsoleViewer createViewer(Composite parent) {
return new MyConsoleViewer(parent, (MyConsole) this.getConsole());
}
}
public class MyConsoleViewer extends TextConsoleViewer
{
//This class gives you access to setting the caret position
//by getting the styled text widget and then using setCaretOffset
}
There are multiple ways of getting the styled text widget depending on which method you are overriding. I also created my own Console history class which kept track of the caret offset since I needed additional functionality of using the up and down arrow keys to navigate through previously entered commands.
The best way to implement the MyConsoleViewer is to use Eclipse's vast source code that sets a perfect example. I practically reused all of this class org.eclipse.ui.internal.console.IOConsoleViewer
. It even shows examples of setting the caret.
Hope this still helps as your question was a while ago.