2 Commits
1.0 ... 1.1

Author SHA1 Message Date
5f7cbeae92 Updated license file. 2016-01-25 15:13:51 -06:00
42eb01d5f8 Fixed access modifiers for Java version. 2016-01-25 15:13:21 -06:00
6 changed files with 52 additions and 7 deletions

View File

@ -1,4 +1,4 @@
Copyright (c) 2014 Copyright (c) 2016
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without

45
README.md Normal file
View 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)
```

View File

@ -2,7 +2,7 @@ apply plugin: "groovy"
apply plugin: "maven" apply plugin: "maven"
group = "com.jdbernard" group = "com.jdbernard"
version = "1.0" version = "1.1"
repositories { repositories {
mavenLocal() mavenLocal()

View File

@ -1,6 +1,6 @@
# Package # Package
version = "1.0" version = "1.1"
author = "Jonathan Bernard" author = "Jonathan Bernard"
description = "Utility for writing dynamic progress bars to the console." description = "Utility for writing dynamic progress bars to the console."
license = "BSD" license = "BSD"

View File

@ -8,7 +8,7 @@ package com.jdbernard.util
* counter is 1-based because the current step is complete for this counter. * counter is 1-based because the current step is complete for this counter.
* @author Jonathan Bernard (jdbernard@gmail.com) * @author Jonathan Bernard (jdbernard@gmail.com)
*/ */
class ConsoleProgressBar { public class ConsoleProgressBar {
int MAX_STEP = 30 int MAX_STEP = 30
long max = 10 long max = 10
@ -21,7 +21,7 @@ class ConsoleProgressBar {
public void setMax(long max) { public void setMax(long max) {
this.max = Math.max(max, 1) } this.max = Math.max(max, 1) }
void update(long value, String info) { public void update(long value, String info) {
if (value == 0 || startTime == 0) if (value == 0 || startTime == 0)
startTime = System.currentTimeMillis() startTime = System.currentTimeMillis()
@ -60,7 +60,7 @@ class ConsoleProgressBar {
out.flush() out.flush()
} }
void erase() { public void erase() {
out.print '\b' * lastLinePrinted.length() out.print '\b' * lastLinePrinted.length()
out.print ' ' * lastLinePrinted.length() out.print ' ' * lastLinePrinted.length()
out.print '\b' * lastLinePrinted.length() out.print '\b' * lastLinePrinted.length()