Tharga / Console

Tharga Toolkit Console is used to simplify construction of advanced console applications.
MIT License
23 stars 6 forks source link

Printing text output while prompt is active? #2

Closed WasabiFan closed 9 years ago

WasabiFan commented 9 years ago

If I create a new engine and run it and then start printing output to the console, the prompt (>) is not re-written. This makes it unclear if the window is still accepting input. Is there a way to make it so that while the prompt is shown, subsequent WriteLine calls will re-write the prompt after the output is displayed? Something like this:

Currently, if output is written to the console while the prompt is shown (and the user is typing) it does this:

> inputinputOUTPUT
moreinputmoreinput

Once that output is written, the user is left to finish their typing without a prompt. I'm looking for this instead:

> inputinput
OUTPUT
> inputinputmoreinputmoreinput

In this case, the new output was put on a new line. At the end of that output, a new prompt was written followed by the unfinished input.

poxet commented 9 years ago

Getting that to work would really be great. Then it would be possible to really take advantage of async as well.

I will give it a try. Feel free to try it out as well!

WasabiFan commented 9 years ago

My attempt was to add System.Console.Write("> ") after the WriteLine call in the ClientConsole (see here). This almost worked, but...

I'm still trying to fully understand how this library works, so don't expect any genius contributions coming from me anytime soon :wink: But I'll see what I can figure out.

poxet commented 9 years ago

I think I would try to somehow move the line with the input buffer and cursor down and print the output above it. Not sure that this would work, but I think that would be my first try.

poxet commented 9 years ago

When using the Output... methods in the commands this should work now. If using the regular "System.Console.WriteLine(.." it will not work.

Give it a try and tell me what you think.

WasabiFan commented 9 years ago

The Output... methods don't seem to have any dependency on being inside a command; could they be separated into the generic console? I'd like to be able to use them for things like debug info and warnings from other code that isn't part of a command.

poxet commented 9 years ago

You are very right. I moved that thing to the console part. So, you can use the console object instead. _console.WriteLine("SOME DATA", OutputLevel.Default); Then it works for commands as well, since it uses the console.

I also found two other issues now. When pressing ESC, the cursor moves back up to the lines above, where input started. And, if the input is above two lines then only the last line is moved.

I am not sure how to fix that. Have to sleep on that. :)

WasabiFan commented 9 years ago

This is looking great! One more thing: can it be added to the Write() method as well?

poxet commented 9 years ago

Testing some more I realised that this is really tricky. There are so many special cases where it does not work as it should.

I have started to write a completley new input manager. I have the basic stuff in place but there is still some work to do. I will try to have a new version out later today so that you can try it out if you like.

poxet commented 9 years ago

This is fixed with version 1.5.13.0. Now Write will get a new line to write on (above the input buffer). The Write() function will continue to write there, until a WriteLine() is used. Then the line is "closed". And a new line will be used for writing.