JetBrains / jediterm

Pure Java Terminal Emulator. Works with SSH and PTY.
GNU Lesser General Public License v3.0
675 stars 171 forks source link

Can I get the out without a ui page? #270

Closed ZhouMM92 closed 1 year ago

ZhouMM92 commented 1 year ago

Now , I have a array like this:

        ArrayList<String> strList = new ArrayList<String>();
        strList.add("l");
        strList.add("s");
        strList.add(" ");
        strList.add("-");
        strList.add("l");
        strList.add("r");
        strList.add("t");

and the out I want to get is "ls -lrt" by this utils , so just like a function in java,I give the input ,and I get the out, so can I solve it by jediterm? Because I have lots of commands of the ssh, and there are special characters in them, I want get the out by jediterm automatically.

Thank you very much.

ZhouMM92 commented 1 year ago

Wow, I find a demo, but there is a function which name is "BackBufferTerminal" that can not be found. the codes are as follows:

    protected TerminalTextBuffer doTest(int width, int height, String expected) throws Exception {
        StyleState state = new StyleState();
        TerminalTextBuffer terminalTextBuffer = new TerminalTextBuffer(width, height, state);
        Terminal terminal = new BackBufferTerminal(terminalTextBuffer, state);
        ArrayList<String> strList = new ArrayList<>();
        strList.add("l");
        strList.add("s");
        strList.add(" ");
        strList.add(" ");
        strList.add("-");
        strList.add("l");
        strList.add("r");
        strList.add("t");
        String crlfText = StringUtil.pieceStr(strList);
        ArrayTerminalDataStream fileStream = new ArrayTerminalDataStream(crlfText.toCharArray());
        Emulator emulator = new JediEmulator(fileStream, terminal);
        while (emulator.hasNext()) {
            emulator.next();
        }
        System.out.println(terminalTextBuffer.getScreenLines());
        assertEquals(expected, terminalTextBuffer.getScreenLines());
        return terminalTextBuffer;
    }

So, can I solve my input by this demo, and where can I import the dependence of the function which name is "BackBufferTerminal".

segrey commented 1 year ago

BackBufferTerminal is located in test sources which are not included in jediterm distribution. Not sure, but maybe you can use JediTerminal instead of BackBufferTerminal.

ZhouMM92 commented 1 year ago

BackBufferTerminal is located in test sources which are not included in jediterm distribution. Not sure, but maybe you can use JediTerminal instead of BackBufferTerminal.

A release to Maven Central would be nice.

segrey commented 1 year ago

Even if JediTerm would be uploaded to Maven Central, BackBufferTerminal won't be in the distribution, because it's in test sources.

ZhouMM92 commented 1 year ago

Even if JediTerm would be uploaded to Maven Central, BackBufferTerminal won't be in the distribution, because it's in test sources.

So, is there the same function that I can use in the distribution? I try to use JediTerminal, but the first para of it is the TerminalPanel class, and there are some paras need to be determined for TerminalPanel , I do not know how to determine the paras, because I only need a default object of TerminalPanel .

segrey commented 1 year ago

You can explore how BackBufferTerminal is implemented and copy-paste needed parts to your code base.

ZhouMM92 commented 1 year ago

You can explore how BackBufferTerminal is implemented and copy-paste needed parts to your code base.

Thank you very much, but when I run with my project, a error is occured : image

and the dependency I use in my project is:

        <dependency>
            <groupId>org.jetbrains.jediterm</groupId>
            <artifactId>jediterm-pty</artifactId>
            <version>2.42</version>
        </dependency>

So , is the way I use wrong?

segrey commented 1 year ago

JediTerm 2.42 uses log4j as a logging framework. (BTW, 2.42 is a pretty old version, latest released version is 3.18.)

Just add log4j 1.2.17 dependency to your project and it should fix the issue.

ZhouMM92 commented 1 year ago

I can not find 3.18 in marven repository .

segrey commented 1 year ago

JediTerm is not uploaded anymore to Maven Central. Now it's hosted at https://packages.jetbrains.team/maven/p/ij/intellij-dependencies

<repositories>
    <repository>
        <id>space-intellij-dependencies</id>
        <url>https://packages.jetbrains.team/maven/p/ij/intellij-dependencies</url>
    </repository>
</repositories>

Also, jediterm-pty is split into jediterm-core and jediterm-ui:

  1. jediterm-core v3.18

    <dependency>
    <groupId>org.jetbrains.jediterm</groupId>
    <artifactId>jediterm-core</artifactId>
    <version>3.18</version>
    </dependency>
  2. jediterm-ui v3.18

    <dependency>
    <groupId>org.jetbrains.jediterm</groupId>
    <artifactId>jediterm-ui</artifactId>
    <version>3.18</version>
    </dependency>
ZhouMM92 commented 1 year ago

JediTerm is not uploaded anymore to Maven Central. Now it's hosted at https://packages.jetbrains.team/maven/p/ij/intellij-dependencies

<repositories>
    <repository>
        <id>space-intellij-dependencies</id>
        <url>https://packages.jetbrains.team/maven/p/ij/intellij-dependencies</url>
    </repository>
</repositories>

Also, jediterm-pty is split into jediterm-core and jediterm-ui:

  1. jediterm-core v3.18
<dependency>
    <groupId>org.jetbrains.jediterm</groupId>
    <artifactId>jediterm-core</artifactId>
    <version>3.18</version>
</dependency>
  1. jediterm-ui v3.18
<dependency>
    <groupId>org.jetbrains.jediterm</groupId>
    <artifactId>jediterm-ui</artifactId>
    <version>3.18</version>
</dependency>

Wow, great ! thank you very much.

ZhouMM92 commented 1 year ago

JediTerm is not uploaded anymore to Maven Central. Now it's hosted at https://packages.jetbrains.team/maven/p/ij/intellij-dependencies

<repositories>
    <repository>
        <id>space-intellij-dependencies</id>
        <url>https://packages.jetbrains.team/maven/p/ij/intellij-dependencies</url>
    </repository>
</repositories>

Also, jediterm-pty is split into jediterm-core and jediterm-ui:

  1. jediterm-core v3.18
<dependency>
    <groupId>org.jetbrains.jediterm</groupId>
    <artifactId>jediterm-core</artifactId>
    <version>3.18</version>
</dependency>
  1. jediterm-ui v3.18
<dependency>
    <groupId>org.jetbrains.jediterm</groupId>
    <artifactId>jediterm-ui</artifactId>
    <version>3.18</version>
</dependency>

I have met a problem for a very long time, at first I wanted to solve it this way, but I have not solved it. The problem is: I would like to simulate the host terminal input, for example, I input 'c','d','a', then I input backspace. So ,in host terminal , it will display as 'cd'. Now I want save the input of the host terminal in a array, and the last string of the array is the unicode of the backspace, the array is as follows :

inputArray=["c","d","a","\x08\x1b[K"]

I want to get the out "cd", which the jediTerm tools can automatically solve the host terminal input. In this scene, it can automatically delete "a". So, can I solve the problem with functions of jediTerm ?

segrey commented 1 year ago

Seems it should work in the way you tried it initially - feed all the items from the array to JediEmulator and then parse terminalTextBuffer.getScreenLines(). If you tried and it doesn't work, could you please share what exactly didn't work in this approach?