Say I have a terminal with 30 lines of height.
And say I have a loop that outputs 100 lines of output
for(int i=0; i<100; i++){
System.out.println(i);
}
Is there a way I can output the first 30 lines, show text that says "Press enter to continue output...", show the next 30 lines when the user presses enter, etc?
I want to do this in the easiest manner possible. If I can use less
somehow, that would be excellent.
Update
This needs to be implemented in the Java source code. The following is not a suitable solution:
java program | less'
Also, I will need to programmatically get the height of whatever terminal it is executed in.
Either pass
tput cols
to your java program as a command line arg or system property (java -DTermHeight=`tput cols`) or fetch it during runtime usingRuntime.getRuntime().exec("tput cols")
Store that value in a variable
height
. Now