Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
5f7cbeae92 | |||
42eb01d5f8 |
4
LICENSE
4
LICENSE
@ -1,4 +1,4 @@
|
||||
Copyright (c) 2014
|
||||
Copyright (c) 2016
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
@ -24,4 +24,4 @@ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
45
README.md
Normal file
45
README.md
Normal file
@ -0,0 +1,45 @@
|
||||
# Console Progress Bar
|
||||
|
||||
Simple progress bar for long-running operations.
|
||||
|
||||
## Java/Groovy
|
||||
|
||||
Build with gradle:
|
||||
|
||||
gradle assemble
|
||||
|
||||
|
||||
Example usage:
|
||||
|
||||
```java
|
||||
import com.jdbernard.util.ConsoleProgressBar
|
||||
|
||||
// ...
|
||||
|
||||
ConsoleProgressBar progressBar = new ConsoleProgressBar()
|
||||
progressBar.setOut(System.out) // optional
|
||||
progressBar.setMax(100)
|
||||
|
||||
for (int i = 0; i <= 100; i++) {
|
||||
progressBar.update(i, "Message for " + i);
|
||||
Thread.sleep(500);
|
||||
}
|
||||
```
|
||||
|
||||
## Nim
|
||||
|
||||
Install the library using nimble:
|
||||
|
||||
nimble install
|
||||
|
||||
Example usage:
|
||||
|
||||
```nim
|
||||
import os, console_progress
|
||||
|
||||
var progress = newProgress(sout = stdout, maxValue = 100)
|
||||
|
||||
for i in 0..100:
|
||||
progress.updateProgress(i, "Message for " & i)
|
||||
sleep(500)
|
||||
```
|
@ -2,7 +2,7 @@ apply plugin: "groovy"
|
||||
apply plugin: "maven"
|
||||
|
||||
group = "com.jdbernard"
|
||||
version = "1.0"
|
||||
version = "1.1"
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Package
|
||||
|
||||
version = "1.0"
|
||||
version = "1.1"
|
||||
author = "Jonathan Bernard"
|
||||
description = "Utility for writing dynamic progress bars to the console."
|
||||
license = "BSD"
|
||||
|
Binary file not shown.
@ -8,7 +8,7 @@ package com.jdbernard.util
|
||||
* counter is 1-based because the current step is complete for this counter.
|
||||
* @author Jonathan Bernard (jdbernard@gmail.com)
|
||||
*/
|
||||
class ConsoleProgressBar {
|
||||
public class ConsoleProgressBar {
|
||||
int MAX_STEP = 30
|
||||
|
||||
long max = 10
|
||||
@ -21,7 +21,7 @@ class ConsoleProgressBar {
|
||||
public void setMax(long max) {
|
||||
this.max = Math.max(max, 1) }
|
||||
|
||||
void update(long value, String info) {
|
||||
public void update(long value, String info) {
|
||||
if (value == 0 || startTime == 0)
|
||||
startTime = System.currentTimeMillis()
|
||||
|
||||
@ -60,7 +60,7 @@ class ConsoleProgressBar {
|
||||
out.flush()
|
||||
}
|
||||
|
||||
void erase() {
|
||||
public void erase() {
|
||||
out.print '\b' * lastLinePrinted.length()
|
||||
out.print ' ' * lastLinePrinted.length()
|
||||
out.print '\b' * lastLinePrinted.length()
|
||||
|
Reference in New Issue
Block a user