Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clear output in telnet

Tags:

java

telnet

Is there any way to make a telnet app to clear the output client-side (using Java Socket connection + Buffers)? For example, the program queries the connected user for login and password and when they've succeeded logging in, I do cls for Windows or clear for Linux.

like image 784
jurchiks Avatar asked Jan 21 '23 08:01

jurchiks


2 Answers

The telnet application is a terminal emulator. In really old times the only way to communicate with a computer was by using a terminal with a pure text based screen and a keyboard. The terminal sent everything you typed to the computer. The computer sent characters back that was printed on the screen. Just like telnet. DEC created a series of terminals called VT52, VT100 etc. They was able to interpret special control sequences so that the computer could give more fancy instructions to the terminal. These control sequences was standardized by ANSI and is now called ANSI escape codes. Terminal emulators that understand the VT100 escape codes are called VT100 terminal emulators.

You may look up the ansi escape codes on wikipedia and other places. They all start with the character codes for escape and [ followd by the control characters. The control characters for clearing the screen is "2J". So, what you need to do is sending this string from your server to the telnet client:

myOutputStream.print("\u001B[2J");
myOutputStream.flush();

You may send other control characters as well. Try "\u001B[7m" to reverse the screen.

like image 190
sstendal Avatar answered Jan 31 '23 23:01

sstendal


On the Linux side, clear simply issues some terminal control characters to tell it to clear the screen. For VT terminals, that's Esc]2J. Not sure if Windows would support something similar.

like image 33
Marc B Avatar answered Jan 31 '23 22:01

Marc B