views:

60

answers:

2

Hello,

I am writing a console application in Java. It is similar to a chat client: Input and output are asynchronously made. The problem is that if some output is made while the user is in the middle of typing, the lines will get mixed up on the screen.

I am looking for a solution which allows me to have a input area separate from the output area. At the moment I am using an extra thread which polls a BufferedReader on System.in.

The program needs to run on a Linux server and be accessed via an ssh session. So any hints that only work in this environment are fine.

Are there any high level libraries which can do this? Or is there a smart trick using terminal / ANSI codes? The ANSI codes s (save cursor) and r (restore cursor) might be helpful but how do i know where to jump to do the output and how do i handle scrolling?

+1  A: 

Sounds like you need to use Curses. JCurses is a Java implementation of the Curses library and will give you control of the terminal to allow scrolling, positioning etc.

Brian Agnew
+1  A: 

I recall a long time ago working with similar things but in C++. I was using the ncurses library then. Check out javacurses which seems to be a Java implementation of something like ncurses. Check it out!

Kristoffer E