-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restricting command line output to one line #705
Comments
I don't know if there's a way to overwrite the same line using logging.. AFAIK, there's no way to overwrite to same line using logging |
The logging can be reimplemented if such feature does not exist; can even write our own API too if we have to as it also provides us with greater control. |
Alternatively, we can try to format the output such that important messages are hard to miss. |
The intention is to make it less important message to take up less space though. So my suggestion is to have the info messages to always overwrite itself, leaving the error messages right on top of it. E.g.
If the following line is going to be another error message, delete the last [INFO] line, output the new [ERROR] message, then prints the next [INFO] line again.
If the user wants to keep all the messages, we can add in a verbose flag afterward to disable the overwriting. |
I came up with something like this: Specifically, I did this in
However, it is highly dependent on the width of the terminal because of using Also, there doesn't seem to be a platform-independent way to determine the width of the terminal in Java unless we want to include libraries (https://stackoverflow.com/questions/1286461/can-i-find-the-console-width-with-java). Finding the width would help to determine the number of lines a message occupies in the terminal. Are there other ways of making |
For the width problem is it that if the newly printed line is shorter than the existing one, non-overwritten chars from previous line will remain? |
No - if all messages are short enough to fit in 1 line in the terminal, we can use the escape sequence The issue is when some messages are long and occupy multiple lines in the terminal due to line wrapping. Suppose a long message occupies 2 lines on the terminal due to line wrapping. The cursor will be at the 2nd line. Using |
Hmm, maybe in that case, we could probably make our own print class? Whenever a call is made to the print function, we will record the length of the text that will be printed. With that info, when we're going to overwrite the previous line, we can |
Yes that would help with recording the number of lines the old message occupied. To calculate the number of lines ( |
If we do the backspace way, we wouldn't need to know the width of the terminal anymore, isnt it? |
Ah. Using backspace ( I also tried using saving/restoring the cursor position:
but it doesn't work when the messages reach the bottom of the terminal and the terminal has to scroll. |
I guess this is also cause of the problem with your original solution; it does not have any concept of lines of text. In that case, we may have to restrict non-error messages to fit into single lines. |
Messages of different severity are outputed in similar format, without any form of distinction. This creates difficulty for our users to distinguish messages of different severity from the logs. Moreover, messages of higher severity often contains important info which may requires user's action and shouldn't be left unnoticed. Let's make these messages more distinct by inserting a highlighted status tag e.g. `[ERROR]` before the message.
The console output too much messages; making it difficult to differentiate important messages.
Hence, we should restrict the status message from occupying too many lines on the terminal screen, making it self contained in a single line by overwriting itself.
The text was updated successfully, but these errors were encountered: