Closed Sergix closed 7 years ago
I would be interested in working on this issue. I'm new to contributing on github but have a pretty good amount of experience in Java and this doesn't sound too difficult at first glance.
Ideally what you could do for this is remove all output line by line on the console, using a modified version of the ClearLine method that is sitting in the dev branch of my fork. Although printing lines would be much easier, it leaves the cursor at the bottom of the terminal window. Alternatively, make the OS run the cls or clear command depending on the OS the program is running on, using Runtime. Just giving some ideas, if you have another one, just say, after all the best ideas only surface after some back and forth.
Thanks for looking into this, @ccmetz !
To implement this, I would go with the first part of what @nanoandrew4 said, and use ClearLine
(although this function doesn't exist in the head repo yet). When writing this code, create a new class (ideally Clear.java
) that will have all the related functions for clearing the screen. Then create a public constructor method. All your basic code will go in there.
If you have any other questions or comments, don't hesitate to ask. Also, consider joining our Slack group, which gives you automatic updates on the repository.
Thanks again! 😀
Sounds good, @Sergix !
I see that this is an eclipse project. I've been using Intellij for awhile now. Is there anything special I would need to do if I wanted to work on this project in Intellij? Or should I just download Eclipse and use that to be safe?
Also, I would love to join your slack group. You can send an invite to ccmetz92@gmail.com
.
@nanoandrew4 , if you could let me know when you eventually push your code with the ClearLine
method, that would be great! It sounds like that would be the best way to go.
It shouldn't matter what IDE you use, especially since I use Visual Studio Code to work on this project. 😜 I'm not really sure if there is any special setup, other than the obvious fact that you need Maven installed.
Plus, if you are on Windows, there's a few batch scripts included in the repository (init.bat
, build.bat
, and run.bat
) that I use to build the project since I use VSCode. If IntelliJ has an integrated terminal (or even if it doesn't), you can call init
to load the development terminal environment, then build
and run
to test the project. If you aren't on Windows, you should be able to run the build with Maven anyways; the batch files don't provide any real advantage, other than if you enjoy using the terminal (like myself).
Also, we're actually just about to merge the changes, so you can pull the updates from the head repo after it's finished. I'll notify you in this conversation when it has merged.
Pull request submitted, changes should be live soon.
@ccmetz I work on IntelliJ, just import the project by choosing the pom.xml file, set your source folders under Project Structure -> Modules -> Sources to src (just click on src and then on the Sources button that has a blue folder beside it) and all should be good! I got it up and running, so any questions, just ask (though maybe open another issue so that we don't overload this one with unrelated info)
For the ClearLine function, you will have to use it in tandem with other stuff to go up and down the lines and other stuff, might take a bit of research, but it'll be a good learning experience for sure!
https://github.com/Sergix/JTerm/commit/80e428858372412a590cfd8edd6e6162836de06f Includes all the code necessary.
Okay so now that we've got JTerm working on Macs, I can begin working on this issue! I probably won't do much with it for the rest of the night but I'd expect to finish it at some point this weekend.
Good luck! If you get stuck Google is your friend, and if you need anything regarding input I'll also be working on binaries this weekend so just ask, happy to answer!
Also, because this is cross platform and you are unable to test on all four platforms, expect it to take longer than you think :P learnt that the hard way... Just remember Windows handles consoles differently from Unix, and that each sometimes are a bit erratic in how they want stuff done...
Yeah no kidding. 🤣 It's really dumb that Windows doesn't support ASCII like UNIX does. :/
Oh right - forgot about Windows! We'll see how that goes. Might be a little hard to test as I don't have easy access to a Windows computer right now.
@ccmetz I'll test the code for you. I can clone your fork on my machine, so just tell me when you need something tested! 😁
Just always double check with the internet when it comes to writing the code for Windows. It will save you lots of time.
@Sergix Awesome, I'll let you know
While researching ways to efficiently clear the console, I came across this question on stackoverflow: https://stackoverflow.com/questions/19323494/ways-to-clear-the-console
For terminals supporting ANSI escape sequences, it's possible to clear the screen using:
System.out.print("\033[H\033[2J");
System.out.flush();
^ I've tested this and it works on both of the terminals that I've been using on my Mac. Not sure if Windows or Linux will support this. I'm worried mostly about Windows...
Otherwise, I haven't found a way to really go up and down lines using java in the console just yet. I'm still looking into that - I'm not entirely sure if it's possible with just plain java.
I also wanted to mention that when I run a clear
command on my system terminal, it clears the lines on the screen but I can still scroll back up and see what used to be there in the scroll buffer. Obviously this was mentioned earlier, but we could easily simulate this by just printing out a bunch of new lines equal to the number of lines currently displayed on the screen.
So this leaves us with the following options:
1) Use ANSI Escape sequences (after verifying that they will work on Windows and other OS's)
2) Continue looking into ways to move the cursor up and down the console and use a modified version of the ClearLine
method to print spaces over the lines
3) Print out a bunch of new lines to give the user a fresh screen but still allow them to scroll up see what's in the display buffer
4) More research!!!
Anyways, just wanted to update you guys. I'll continue researching today. Let me know if you have any additional thoughts on this issue!
Escape sequences don't work on Windows. We encountered this issue when working on tab completion. Soooo... yeah. I would try and go for option number two though. :P
@ccmetz Have you tried passing commands to the OS such as "cls" or "clear"? That could maybe work, and it would be quite easy to implement.
You can't simply call "cls" from the Runtime, because it's not an actual system program, it's a cmd command. There's no "cls.exe".
Sergix Peyton McGinnis
On Oct 1, 2017, at 5:00 PM, "Andres" notifications@github.com<mailto:notifications@github.com> wrote:
@ccmetzhttps://github.com/ccmetz Have you tried passing commands to the OS such as "cls" or "clear"? That could maybe work, and it would be quite easy to implement.
— You are receiving this because you were assigned. Reply to this email directly, view it on GitHubhttps://github.com/Sergix/JTerm/issues/33#issuecomment-333406389, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ATomMfUE83-WZMEk6B5qUUcmf1YYkDp4ks5sn_2CgaJpZM4PlBqV.
Well then... In that case, maybe pass ANSI escape sequences for Unix, and look for another alternative for Windows if you can find one? Otherwise as @Sergix says, option two is probably best path forward if we want to apply the same system to all OS's.
If we did go the route of calling commands from the OS, it looks like it might be possible to invoke the command line interpreter on windows and tell it to execute a command: https://stackoverflow.com/questions/2979383/java-clear-the-console
I'm not for sure if this works or not though because I can't test it.
I'll check it out later.
But also, HEADS UP: before you pull changes from the dev branch on the head repo, back up your current changes on your local machine. The next commit moves a bunch if classes around into new folders, so please take caution.
Also, it appears that
new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
could work. Let me know when you have an update on it so I can test it out!
By the way, the commit I was talking about in the last comment has been pushed, so you can now pull the changes if you've backed up your code. View changelog entry #90 for details.
@Sergix Alright the code has been pushed to my fork on the dev
branch. Let me know how it works on Windows.
@ccmetz Just tested it, and it was successful! Works as expected. 😄
Unless you have any final changes, go ahead and open a PR to merge into the head repo.
One of the basic functionalities yet to be added to JTerm is a "clear screen" command.
Implementation-wise, it would be best to replace all the characters on the screen that are visible, and then output an input prompt.