0

So I am working on a http server app thing, and I need to make a inbuilt shell for some stuff (like minecraft). I tried a lot with jline but cannot get a proper prompt without the logs messing up the prompt input. Here's what I want:

  • The prompt to disappear as the app logs something
  • Then the prompt appears again
  • But doesn't remove whatever I typed in the prompt

I am using log4j2 for the logging framework.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
  • What exactly are you asking? Are you looking for recommendations for a library that will help create a console? – Hovercraft Full Of Eels May 03 '22 at 11:59
  • 1
    Note regarding, *"its urgent..."* -- You don't want to state this. Even if it is urgent to you, it is not urgent to us, and some may take offense to your implying that your post is more important than everyone else's and that you want to put pressure on the volunteers who come here to help on their own free time. Also see: [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](https://meta.stackoverflow.com/q/326569/). I have removed the urgency statement from your question. – Hovercraft Full Of Eels May 03 '22 at 12:01
  • @HovercraftFullOfEels Well a library would surely be helpful, but I am ok with making my own kind of implementation with jline3 and log4j2. And sorry, noted that. – EkaSaffronGaruda May 03 '22 at 13:10
  • Change your logger configs so that log messages are not written to the console. (The log4j2 documentation explains how the config files work.) – Stephen C May 03 '22 at 13:49
  • @StephenC I want log4j to log to console though? – EkaSaffronGaruda May 03 '22 at 15:02

1 Answers1

0

It should be feasible using JLine, however you'll need JLine and log4j2 to coexist peacefully. In order to do that, you'll have to implement a custom log4j appender that will write to the console using JLine's reader printAbove method.

Guillaume Nodet
  • 311
  • 1
  • 5
  • This is what i have till now: https://pastie.io/mylrlk.java The 3rd point i have mentioned doesn't work. https://stackoverflow.com/a/27389903/18799738 this is something written in the stone age, I want it done in jline3. – EkaSaffronGaruda May 05 '22 at 01:25
  • Your snippet looks good. I've just added a simple example of `printAbove` to JLine3 with https://github.com/jline/jline3/commit/ed6cef30551cc165dae91ffc74b0aa01944fb23e and it seems to work great. The prompt is kept and the lines are printed above as desired. – Guillaume Nodet May 06 '22 at 05:15
  • I am sorry, but the example you shared is far away than simple. Do you mind sharing a simple log4j custom appender with that prompt? – EkaSaffronGaruda May 10 '22 at 09:27
  • You already have one in https://pastie.io/mylrlk.java and it looks correct. Are you sure that this one is used in your config and not the usual console appender ? The `printAbove` method does keep the existing input, so if it does not work, I suspect the appender is not the one actually used. – Guillaume Nodet May 11 '22 at 11:05
  • I am sure I am not using ConsoleAppender and the custom appender I made, it still doesn't save the input. – EkaSaffronGaruda May 11 '22 at 13:49
  • Sorry, it was eclipse console which was causing the trouble. Everything works fine now, thank you! – EkaSaffronGaruda May 14 '22 at 11:09