Eclipse RCP:自定义控制台 [英] Eclipse RCP: Custom console

查看:472
本文介绍了Eclipse RCP:自定义控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个控制台,作为一个自定义编程语言的shell。这将非常类似于pydev交互式控制台。



目前,我的RCP使用基本的TextConsole,并通过管道连接到shell,所以它只显示任何shell显示并且如果用户在RCP控制台中输入任何内容,那么在shell中写入相同内容。



我想要能够做更多的操作,例如移动插入位置,为上下箭头键添加事件等。我相信,我需要添加一个StyledText小部件到控制台通过ConsoleViewer。



问题是,有什么办法我重写TextConsole的ConsoleViewer,或者如果我要扩展TextConsole和创建自己的,那么如何链接它与启动配置(通过管道连接shell)?



此外,为了获得当前的默认控制台,我使用 DebugUITools.getConsole(process)



对不起,如果我没有把所有必要的信息;它有点难以解释。我很乐意添加更多信息。



一个想法...
根据我的理解,我可以创建一个 TextConsolePage 使用 TextConsole 一旦我有页面,我可以通过 setViewer(viewer)设置查看器。在这里,我想如果我创建自己的查看器(它将有适当的stylewidget),那么这可能是一个领先。唯一的问题是,查看器需要一个Composite,我似乎不知道从哪里得到它。

解决方案

所以我想我会回答这个自己,因为我终于能够完成控制台。它仍然是一个工作原型,但我猜,当你继续添加的东西,你可以清理代码越来越多。对我目前的目的这是它的工作原理。



如果你想要的短版本,那么我基本上模仿 ProcessConsole 由Eclipse提供,因为这是我需要的:一个控制台,其中我可以连接一个进程,但由于 ProcessConsole 是内部的,我喜欢避免扩展这些类。 p>

以下是我用来实现与我的控制台交互的类的概述。我不会给予 MyConsole 创建的借口。基本上,我不使用 DebugUITools.getConsole(myProcess),而是使用我自己的 myProcess.getConsole()方法。 MyProcess 扩展 RuntimeProcess

  class MyConsole extends IOConsole {
private IOConsoleInputStream fInput;
private IOConsoleOutputStream fOutput;
private IStreamsProxy fStreamsProxy;
private ConsoleHistory history;
//这是要记住提示后的插入符位置
private int caretAtPrompt;
/ *在控制台中,所以当你需要替换命令上下
*箭头键你有位置。
*我只是做了一个caretAtPrompt + = String.Length,其中字符串是
*追加到控制台。主要在streamlistener和
* InputJob,除非你特定输出的东西到输出
* stream。
* /
//在构造函数中,您分配所有上述字段。下面是一些
//指出。
// fInput = getInputStream();
// fStreamsProxy = process.getStreamsProxy();
// fOutput = newOutputStream();

//我们必须重写以下方法来获取光标
@Override
public IPageBookViewPage createPage(IConsoleView view){
return new MyConsolePage(this,视图);
}
//之后我遵循ProcessConsole并添加了
// InputJob和StreamListener
//。
}

类MyConsolePage扩展TextConsolePage {
//在这个类中没有多少,只是重写createViewer
//来返回MyConsoleViewer
}

类MyConsoleViewer扩展TextConsoleViewer {
//这是最重要的类,大部分工作在这里完成
//我基本上复制了所有从IOConsoleViewer然后
//更新我需要的任何内容
//为上下箭头添加一个VerifyKeyListener
//控制台历史记录的键

MyConsoleViewer(复合父,MyConsole控制台){
//我省略了很多代码,因为它太多了,
//只是突出显示几个
getTextWidget()。addVerifyKeyListener(new MyKeyChecker());
}

class MyKeyChecker implements VerifyKeyListener {...}

}

ProcessConsole
IOConsoleViewer 的代码。



我创建的 ConsoleHistory 类只有一个双向链接的字符串列表来保存用户输入的所有命令。一个简单的类创建。



一旦你看看Eclipse类( ProcessConsole IOConsoleViewer )它实际上都是相当自我解释。我没有在这里放很多代码,因为有很多。但我希望这可以给我一些方向,因为我完全失去了我开始。



我很乐意回答问题,如果有人问,添加更多的具体代码。

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 ProcessConsole provided by Eclipse as that is what I needed: a console in which I can connect a process but since the ProcessConsole is 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 MyConsole was created. Basically, instead of using DebugUITools.getConsole(myProcess), I used my own myProcess.getConsole() method. 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 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 (ProcessConsole and IOConsoleViewer) 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.

这篇关于Eclipse RCP:自定义控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆