-
Notifications
You must be signed in to change notification settings - Fork 108
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
Added support for multiple progress bars displayed simultaneously #69
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
705d3b9
Resolve #60
mordechaim 246f08a
update documentations
ctongfei 4d6c6fe
version bump
ctongfei 21910f7
Added support for multiple progress bars displayed simultaneously (st…
vehovsky 4e2d0fc
- synchronization fix for terminals without capability to move cursor
vehovsky ac46d59
minor refactoring to simplify code
vehovsky 7429cef
terminal utils refactoring and cleanup
vehovsky 7fbc131
- ensure same thread that renders last progress status also closes th…
vehovsky 1dbaf8b
Creating terminal is relatively expensive, usually takes between 5-10ms
vehovsky 4684ee4
potential NPE fix
vehovsky 6df1ef7
Merge branch '1.0' into multiline-progressbar
ctongfei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 7 additions & 17 deletions
24
src/main/java/me/tongfei/progressbar/ConsoleProgressBarConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,38 @@ | ||
package me.tongfei.progressbar; | ||
|
||
import org.jline.terminal.Terminal; | ||
|
||
import java.io.IOException; | ||
import java.io.PrintStream; | ||
|
||
import static me.tongfei.progressbar.TerminalUtils.MOVE_CURSOR_TO_LINE_START; | ||
|
||
/** | ||
* Progress bar consumer that prints the progress bar state to console. | ||
* By default {@link System#err} is used as {@link PrintStream}. | ||
* | ||
* @author Tongfei Chen | ||
* @author Alex Peelman | ||
*/ | ||
public class ConsoleProgressBarConsumer implements ProgressBarConsumer { | ||
|
||
private static int consoleRightMargin = 2; | ||
private final PrintStream out; | ||
private Terminal terminal = Util.getTerminal(); | ||
|
||
ConsoleProgressBarConsumer() { | ||
this(System.err); | ||
} | ||
final PrintStream out; | ||
|
||
ConsoleProgressBarConsumer(PrintStream out) { | ||
public ConsoleProgressBarConsumer(PrintStream out) { | ||
this.out = out; | ||
} | ||
|
||
@Override | ||
public int getMaxProgressLength() { | ||
return Util.getTerminalWidth(terminal) - consoleRightMargin; | ||
return TerminalUtils.getTerminalWidth() - consoleRightMargin; | ||
} | ||
|
||
@Override | ||
public void accept(String str) { | ||
out.print('\r'); // before update | ||
out.print(str); | ||
out.print(MOVE_CURSOR_TO_LINE_START + str); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
out.println(); | ||
out.flush(); | ||
try { | ||
terminal.close(); | ||
} | ||
catch (IOException ignored) { /* noop */ } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/me/tongfei/progressbar/InteractiveConsoleProgressBarConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package me.tongfei.progressbar; | ||
|
||
import java.io.PrintStream; | ||
|
||
import static me.tongfei.progressbar.TerminalUtils.*; | ||
|
||
/** | ||
* Progress bar consumer for terminals supporting moving cursor up/down. | ||
* | ||
* @author Martin Vehovsky | ||
*/ | ||
public class InteractiveConsoleProgressBarConsumer extends ConsoleProgressBarConsumer { | ||
|
||
private boolean initialized = false; | ||
int position = 1; | ||
|
||
public InteractiveConsoleProgressBarConsumer(PrintStream out) { | ||
super(out); | ||
} | ||
|
||
@Override | ||
public void accept(String str) { | ||
if (!initialized) { | ||
TerminalUtils.filterActiveConsumers(InteractiveConsoleProgressBarConsumer.class).forEach(c -> c.position++); | ||
TerminalUtils.activeConsumers.add(this); | ||
out.println(MOVE_CURSOR_TO_LINE_START + str); | ||
initialized = true; | ||
return; | ||
} | ||
|
||
out.print(moveCursorUp(position) + str + moveCursorDown(position)); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
out.flush(); | ||
TerminalUtils.activeConsumers.remove(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly I don't see point in keeping this deprecated method in the public API. There is no way anymore (even before this PR) to construct the ProgressBar without the Runnable being started. Personally I would remove it and made the updateInterval private again in ProgressThread.