clear output in 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 succeede开发者_Python百科d logging in, I do cls
for Windows or clear
for Linux.
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.
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.
Scrolling blank lines is the only way I can think of in Java if you need to support windows.
精彩评论