nbz*_*nbz 5 java eclipse console eclipse-rcp
我正在尝试创建一个可用作自定义编程语言外壳的控制台。这将与pydev交互式控制台非常相似。
当前,我的RCP使用基本的TextConsole并通过管道连接到外壳,因此它仅显示外壳显示的内容,并且如果用户在RCP控制台中输入任何内容,也将在外壳中写入内容。
我希望能够做更多的事情,例如移动插入符号的位置,添加向上和向下箭头键的事件等。我相信要做到这一点,我需要向控制台添加一个StyledText小部件,这是通过ConsoleViewer完成的。
所以我的问题是,有什么办法让我覆盖TextConsole的ConsoleViewer,或者如果我要扩展TextConsole并创建自己的控制台,那么如何将其与启动配置(通过管道连接外壳的链接)链接起来? ?
另外,要获取当前的默认控制台,请使用DebugUITools.getConsole(process)。
很抱歉,如果我没有提供所有必要的信息;这有点难以解释。我很高兴添加更多信息。
一个想法......从我明白我可以创建一个TextConsolePage从TextConsole使用createPage(ConsoleView)。进入页面后,可以通过设置查看器setViewer(viewer)。在这里,我想如果我创建自己的查看器(将具有适当的stylewidget),那可能是一个线索。唯一的问题是观众需要一个复合影片,而我似乎无法弄清楚从哪里获得。
所以我想我会自己回答这个问题,因为我终于能够完成控制台了。它仍然是一个工作原型,但我想随着你不断添加东西,你可以越来越多地清理代码。就我目前的目的而言,这就是它的工作原理。
如果你想要简短的版本,那么我基本上模仿了ProcessConsoleEclipse 提供的,因为这就是我所需要的:一个控制台,我可以在其中连接一个进程,但由于它ProcessConsole是内部的,我喜欢避免扩展这些类。
以下是我用来实现与控制台交互的类的概述。我不会给出关于MyConsole创建地点的借口。基本上,DebugUITools.getConsole(myProcess)我没有使用 ,而是使用了我自己的myProcess.getConsole()方法。MyProcess延伸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 {...}
}
Run Code Online (Sandbox Code Playgroud)
这是 的代码ProcessConsole。
这是 的代码IOConsoleViewer。
我创建的类ConsoleHistory只有一个双向链接的字符串列表来保存用户输入的所有命令。创建一个非常简单的类。
一旦您查看了 Eclipse 类(ProcessConsole和IOConsoleViewer),它实际上都是不言自明的。我没有在这里输入太多代码,因为代码相当多。但希望这能给我一些方向,因为当我开始时我完全迷失了。
我很乐意回答问题,并在有人问时添加更具体的代码。
| 归档时间: |
|
| 查看次数: |
2424 次 |
| 最近记录: |