3

I want to create console app in Java like "Bukkit, Spigot" (https://i.stack.imgur.com/AXWq6.png)

As you can see in the pic, There are print log to the Console screen but how to keep cursor at bottom of screen (Keep the ">" sign bottom of screen and every input chars will started next to ">" sign and you can't delete ">" sign too!)

When I'm typing something in Console, and meanwhile there have a new line of log message, This thing always keep my input inline at bottom of screen (not split to somewhere else)

So how do I make something like this? I tried hard to search it from Google and didn't found solution for this :'(

Thank you in advance

Apidech T.

//Edit (add more details)

This thing like a chat client in console, Input and output are asynchronously and separated

//Solution The solution is Jline. Thank you

Tackleza
  • 33
  • 5
  • 1
    Can you post a little bit of your code? I'm not completely certain what it is you are already doing that isn't working. – Ryan - Llaver Aug 24 '17 at 20:44
  • Yes, https://pastebin.com/5d5Stm2M, [edit]This is just a example I try to make input non-blocking Console app and I have no idea how to keep input at same line while there have a new line of message coming – Tackleza Aug 24 '17 at 20:47
  • Have a look at [JLine](https://github.com/jline/jline3). It provides most of the functionality you seek for out of the box, I think. – cello Aug 24 '17 at 20:49

2 Answers2

3

You need some library for terminal control that implements commands like "jump to line n, column m" or "erase to end of line" and so on. Have a look at What's a good Java, curses-like, library for terminal applications?.

"curses" is a library that does the job for C/C++.

blafasel
  • 1,091
  • 14
  • 25
-2

It sounds like you are using System.out.println() but that prints on a new line every time it is called.

You should be using System.out.print() which will just append to the same line.

For example:

Scanner s = new Scanner(System.in);
System.out.println("Enter your statement: \n")
System.out.print("> ");
String s = s.nextLine();

Will output:

Enter your statement:

> /* You will be typing here in the console */
Ryan - Llaver
  • 528
  • 4
  • 19
  • Well. I try to create console app which show log or message or something in meantime This console app can accept user input which is non-blocking on main thread, Thanks – Tackleza Aug 24 '17 at 20:52
  • If you look at the pic (http://i.imgur.com/mDgTZ83.png) I want to know how to split Console app into 2 zone (first zone is show log and second zone is wait for input), Thanks – Tackleza Aug 24 '17 at 20:54
  • No. I just want to know "how to" create console app like this one. I didn't want someone to create console app for me – Tackleza Aug 24 '17 at 20:56
  • That is something you should have put in your original question. You're going to have to be specific if you want advice. What have you tried already, what isn't working, what exactly is it you are trying to achieve, what code do you have already, etc. are all things we need to know to be able to help. – Ryan - Llaver Aug 24 '17 at 22:24