5

カスタム プログラミング言語のシェルとして機能するコンソールを作成しようとしています。これは、pydev インタラクティブ コンソールに非常に似ています。

現在、私のRCPは基本的なTextConsoleを使用しており、パイプを介してシェルに接続されているため、シェルが表示するものを表示するだけで、ユーザーがRCPコンソールに何かを入力すると、同じことがシェルに書き込まれます.

キャレット位置の移動、上下矢印キーのイベントの追加など、もう少しできるようにしたいと考えています。それには、ConsoleViewer を介して行われる StyledText ウィジェットをコンソールに追加する必要があると考えています。

だから私の質問は、TextConsole の ConsoleViewer をオーバーライドする方法があるか、または TextConsole を拡張して独自のものを作成する場合、それを起動構成 (パイプ経由でシェルを接続するもの) とリンクするにはどうすればよいかということです。 ?

また、現在のデフォルト コンソールを取得するには、DebugUITools.getConsole(process).

必要な情報がすべて記載されていない場合は申し訳ありません。説明するのは少し難しいです。さらに情報を追加していただければ幸いです。

アイデア...私が理解していることTextConsolePageから、TextConsoleを使用して を作成できますcreatePage(ConsoleView)。ページを取得したら、 を介してビューアーを設定できますsetViewer(viewer)。ここで、独自のビューアー (適切な stylewidget を持つ) を作成すると、それがリードになると考えました。唯一の問題は、視聴者がコンポジットを必要とすることであり、それをどこから取得すればよいかわかりません。

4

2 に答える 2

2

PyDev が行うことに従ってみませんか (EPL ライセンスに対処できる場合)。

関連するコードは次の場所にあります。

https://github.com/aptana/Pydev/tree/ad4fd3512c899b73264e4ee981be0c4b69ed5b27/plugins/org.python.pydev/src_dltk_console

https://github.com/aptana/Pydev/tree/ad4fd3512c899b73264e4ee981be0c4b69ed5b27/plugins/org.python.pydev.debug/src_console

于 2012-05-10T18:15:20.187 に答える
2

それで、ようやくコンソールを完成させることができたので、自分で答えようと思いました。これはまだ機能するプロトタイプですが、何かを追加し続けると、コードをどんどんクリーンアップできると思います。私の現在の目的では、これがどのように機能したかです。

短いバージョンがProcessConsole必要な場合は、Eclipse が提供するものを基本的に模倣しました。それが必要だったからです。プロセスを接続できるコンソールですが、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 {...}

 }

のコードですProcessConsole。 のコードですIOConsoleViewer

私が作成したConsoleHistoryクラスには、ユーザーが入力したすべてのコマンドを保存するための二重にリンクされた文字列リストがありました。作成する非常に単純なクラス。

ProcessConsoleEclipse のクラス (および)を見れば、IOConsoleViewer実際にはすべて一目瞭然です。かなりの量があるため、ここには多くのコードを入れていません。しかし、私が始めたときは完全に迷っていたので、これが何らかの方向性を示してくれることを願っています.

ただし、質問に答えて、誰かが尋ねた場合はより具体的なコードを追加して喜んでいます。

于 2012-06-08T16:17:59.267 に答える