Jump to content

make results dynamic in java


jonas garden

Recommended Posts

I am creating  console application of top command (Linux) through java, but the results are only given for just  the instant   you run the program, I don't know how to delay or refesh  the results with time to be like in Linux for the top command (the result appears continuously and dynamic like in linux )

Link to comment
Share on other sites

33 minutes ago, jonas garden said:

I am creating  console application of top command (Linux) through java, but the results are only given for just  the instant   you run the program, I don't know how to delay or refesh  the results with time to be like in Linux for the top command (the result appears continuously and dynamic like in linux )

It's hard to pinpoint your problem with the facts given but as a general approach you may have a look exiting code. The github project jvmtop seems to have a goal similar to yours; it may not be very active but could provide some hints about how to proceed. The method run(ConsoleView view) in class JvmTop.java and the output implementation in VMDetailView.java may be reasonable points to start.

 

Note & Disclaimer: I am not a participant in the project and I have not used the code or done anything further check the quality of the code in JvmTop 

Link to comment
Share on other sites

There are special ANSI codes to control cursor position and clearing terminal, storing and restoring cursor position etc etc.

https://en.m.wikipedia.org/wiki/ANSI_escape_code

Write example code which is using them to check whether it is what you want.

It is independent from used computer language.

 

Edited by Sensei
Link to comment
Share on other sites

Iirc (this may not be true but it is for most dynamic console commands) top uses ncurses which is a TUI library.  It’s fairly easy to do this ncurses though my only experience with it is in C not Java, you may want to see if there are binding for that.  The old school way is to simply redraw the entire console with only the characters you want changed changed.  Normally you’d check how tall the current console is and ‘\n’ your way to a clear screen before redrawing, but you can use the clear command if you want (most languages have a system library that lets you call commands programmatically.)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.