Closed rdxnaor closed 6 years ago
Can you be a bit more specific ? Which characters are printed ? Can you make a copy/paste of the output (either copy the text or a picture maybe) ?
for example - ^[[?1h^[=^[[?2004h another one is - ^[[?1l^[
Ok, so I just overrided some problematic functions of LineReaderImpl and it seems ok. anyway I still have 2 questions about it :
Thanks a lot!
You clearly have a configuration problem. Those characters are ansi escape sequences that are used to control the terminal (cursor movement, etc...). The reason may be that you did not configure the ssh client or server correctly, as some informations need to be set correctly in order for jline to recognize the terminal and behave correctly. If you use Mina SSHD, you can find some very useful code at: https://github.com/jline/jline3/tree/master/remote-ssh/src/main/java/org/jline/builtins/ssh
I'm not sure that I can change the ssh configuration (and I'm not sure what to change even if I could). please let me be more clear about how I use jline in my project. I have a remote machine that have Ubuntu on it. written down a cli using jline. afterwards I configured a user and when the user ssh inside the machine my program comes up and he gets into the cli.
I didn't use any of ssh java client and I'm not sure what I need to do in order to use it. Do you have an example to see how terminal, reader and ssh are combined and what is the actual result from it?
Thanks
If you use a native ssh client, this part should be ok. It's the server side you need to care about. You need to setup JLine correctly according to the SSH session: https://github.com/jline/jline3/blob/master/remote-ssh/src/main/java/org/jline/builtins/ssh/ShellFactoryImpl.java#L119-L225
Thanks! We are actually using JSch on the client side. any special configuration in this case?
Not sure, you absolutely need to pass the TERM environement variable along with the pty modes. You also need to make sure your real terminal is in raw mode. You can also set callbacks to forward signals (terminal resize, ^C, etc...) https://github.com/jline/jline3/blob/master/remote-ssh/src/main/java/org/jline/builtins/ssh/Ssh.java#L168-L254
I haven't done any integration with JSCh, but maybe you'll find some code. Or you need to adapt the above.
Worst case, set the terminal type to dumb
, but you'll loose most of the jline goodness.
Are you using a real terminal on the client side ?
client side includes virtual and real terminal...
I have to say that I didn't really understand the ssh class part in all of this. my program includes mainly the following commands:
///////////////////////////////// Terminal terminal = TerminalBuilder.builder().signalHandler(Terminal.SignalHandler.SIG_IGN).build(); LineReader reader = LineReaderBuilder.builder() .completer(myCompleter) .terminal(terminal) .build(); String line = reader.readLine(promper.getPrompt(context.getCurrentDirectory())); ///////////////////////////////
After I get the line I do all the things I want to do. I understand that the reader have to get the terminal, and the reader does the actual read. I don't understand where the ssh part in all of this?
Is the above code for the client or server side ? If from the server side, it's broken, because you need to use the streams from the ssh session. If from the client side, then you need to configure your terminal in raw mode before giving them to JSCh.
I suggest you study the jline demo a bit and try to replicate it with JSch if you really need to use it. Correctly integrating JLine with ssh is not an easy task to get right.
Hi, It seems that all the escape characters causing things at my end to get complicated. when I'm connecting to my app using ssh I'm getting special characters at the beginning of each promp, before every print I make and at the end of any print I make. can I somehow don't print them?