-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhangfuxing
committed
Aug 12, 2021
1 parent
e5908c3
commit a880518
Showing
6 changed files
with
63 additions
and
71 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,48 @@ | ||
![logo](screenshots/logo.png) | ||
# ProgressBar | ||
|
||
<p align="center"> | ||
Progress bar in terminal for deno | ||
</p> | ||
ProgressBar in terminal for deno | ||
|
||
[![nest badge](https://nest.land/badge.svg)](https://nest.land/package/progress) | ||
![logo](screenshots/logo.png) | ||
|
||
## Update | ||
|
||
### v1.2.0 - 2020.12.5 | ||
|
||
Add support for "Render multiple progress bars" | ||
[Thanks "shixiaobao17145" for the great idea](https://github.com/deno-library/progress/issues/7). | ||
|
||
### v1.1.1 - 2020.07.15 | ||
|
||
changes: add mod.unstable.ts and ./exmaples/width.unstable.ts | ||
|
||
> Deno v1.2.0 started to support tty column, but is unstable | ||
```bash | ||
deno run --unstable ./examples/width.unstable.ts | ||
``` | ||
|
||
## Usage | ||
|
||
### Multiple progress bars | ||
* example | ||
```ts | ||
import { MultiProgressBar } from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
const title = 'download files'; | ||
const total = 100; | ||
* example | ||
|
||
```ts | ||
import { MultiProgressBar } from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
const title = 'download files'; | ||
const total = 100; | ||
|
||
const bars = new MultiProgressBar({ | ||
title, | ||
// clear: true, | ||
complete: '=', | ||
incomplete: '-', | ||
title, | ||
// clear: true, | ||
complete: '=', | ||
incomplete: '-', | ||
display: '[:bar] :text :percent :time :completed/:total' | ||
}); | ||
}); | ||
|
||
let completed1 = 0; | ||
let completed2 = 0; | ||
let completed1 = 0; | ||
let completed2 = 0; | ||
|
||
function downloading() { | ||
if (completed1 <= total || completed2 <= total) { | ||
|
@@ -62,16 +66,16 @@ function downloading() { | |
} | ||
} | ||
|
||
downloading(); | ||
``` | ||
downloading(); | ||
``` | ||
|
||
* interface | ||
|
||
```ts | ||
interface constructorOptions { | ||
title?: string; | ||
width?: number; | ||
complete?: string; | ||
preciseBar?: string[]; | ||
incomplete?: string; | ||
clear?: boolean; | ||
interval?: number; | ||
|
@@ -126,9 +130,11 @@ class MultiProgressBar { | |
``` | ||
|
||
### Single progress bar | ||
|
||
* simple example | ||
|
||
```ts | ||
import ProgressBar from "https://deno.land/x/[email protected].3/mod.ts"; | ||
import ProgressBar from "https://deno.land/x/[email protected].4/mod.ts"; | ||
|
||
const title = 'downloading:'; | ||
const total = 100; | ||
|
@@ -147,10 +153,12 @@ function downloading() { | |
} | ||
} | ||
downloading(); | ||
``` | ||
``` | ||
|
||
* complex example | ||
|
||
```ts | ||
import ProgressBar from "https://deno.land/x/[email protected].3/mod.ts"; | ||
import ProgressBar from "https://deno.land/x/[email protected].4/mod.ts"; | ||
|
||
const total = 100; | ||
const progress = new ProgressBar({ | ||
|
@@ -177,28 +185,30 @@ function run() { | |
} | ||
run(); | ||
``` | ||
|
||
More examples in the `examples` folder. | ||
|
||
## interface | ||
|
||
```ts | ||
interface ConstructorOptions { | ||
title?: string, | ||
total?: number, | ||
width?: number, | ||
complete?: string, | ||
preciseBar?: string[], | ||
incomplete?: string, | ||
clear?: boolean, | ||
interval?: number, | ||
title?: string, | ||
total?: number, | ||
width?: number, | ||
complete?: string, | ||
preciseBar?: string[], | ||
incomplete?: string, | ||
clear?: boolean, | ||
interval?: number, | ||
display?: string | ||
} | ||
|
||
interface renderOptions { | ||
title?: string, | ||
total?: number, | ||
complete?: string, | ||
preciseBar?: string[], | ||
incomplete?: string, | ||
title?: string, | ||
total?: number, | ||
complete?: string, | ||
preciseBar?: string[], | ||
incomplete?: string, | ||
} | ||
|
||
class ProgressBar { | ||
|
@@ -215,7 +225,7 @@ class ProgressBar { | |
* @param interval minimum time between updates in milliseconds, default: 16 | ||
* @param display What is displayed and display order, default: ':title :percent :bar :time :completed/:total' | ||
*/ | ||
constructor(optopns: ConstructorOptions): void; | ||
constructor(optopns: ConstructorOptions): void; | ||
|
||
/** | ||
* render: render the progress bar | ||
|
@@ -227,40 +237,40 @@ class ProgressBar { | |
* @param options.complete completion character, If you want to change at a certain moment. For example, it turns red at 20% | ||
* @param options.incomplete incomplete character, If you want to change at a certain moment. For example, it turns red at 20% | ||
*/ | ||
render(completed: number, options? renderOptions): void; | ||
render(completed: number, options? renderOptions): void; | ||
|
||
/** | ||
* console: interrupt the progress bar and write a message above it | ||
* | ||
* @param message The message to write | ||
*/ | ||
console(message: string): void; | ||
console(message: string): void; | ||
|
||
/** | ||
* end: end a progress bar. | ||
* No need to call in most cases, unless you want to end before 100% | ||
*/ | ||
end(): void; | ||
end(): void; | ||
} | ||
``` | ||
|
||
## Screenshots | ||
|
||
Standard use | ||
|
||
![normal](./screenshots/title.gif) | ||
![normal](./screenshots/title.gif) | ||
|
||
Multi-line progress bar output in terminal | ||
|
||
![normal](./screenshots/multi.gif) | ||
![normal](./screenshots/multi.gif) | ||
|
||
Change how the order and look of elements | ||
|
||
![console](./screenshots/display.gif) | ||
![console](./screenshots/display.gif) | ||
|
||
Change character color | ||
|
||
![console](./screenshots/changeColor.gif) | ||
![console](./screenshots/changeColor.gif) | ||
|
||
Change background color | ||
|
||
|
@@ -279,19 +289,19 @@ Wider bar | |
![console](./screenshots/width.gif) | ||
|
||
Clear the bar once finished | ||
![clear](./screenshots/clear.gif) | ||
|
||
![clear](./screenshots/clear.gif) | ||
|
||
Backward progress | ||
|
||
![backward](./screenshots/backward.gif) | ||
![backward](./screenshots/backward.gif) | ||
|
||
Log some messages | ||
|
||
![console](./screenshots/console.gif) | ||
![console](./screenshots/console.gif) | ||
|
||
Log some messages next to the bar | ||
|
||
![console](./screenshots/info.gif) | ||
![console](./screenshots/info.gif) | ||
|
||
More screenshots in the `screenshots` folder. |
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 @@ | ||
export { bgGreen, bgWhite } from "https://deno.land/[email protected]/fmt/colors.ts"; |
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,4 +1,4 @@ | ||
import { bgGreen, bgWhite } from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
import { bgGreen, bgWhite } from "./deps.ts"; | ||
export { MultiProgressBar } from "./multi.ts"; | ||
|
||
const isTTY = Deno.isatty(Deno.stdout.rid); | ||
|
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,7 +1,4 @@ | ||
import { | ||
bgGreen, | ||
bgWhite, | ||
} from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
import { bgGreen, bgWhite } from "./deps.ts"; | ||
|
||
const isTTY = Deno.isatty(Deno.stdout.rid); | ||
const isWindow = Deno.build.os === "windows"; | ||
|
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,4 +1,4 @@ | ||
import { bgGreen, bgWhite } from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
import { bgGreen, bgWhite } from "./deps.ts"; | ||
|
||
const isTTY = Deno.isatty(Deno.stdout.rid); | ||
const isWindow = Deno.build.os === "windows"; | ||
|
@@ -7,7 +7,6 @@ interface constructorOptions { | |
title?: string; | ||
width?: number; | ||
complete?: string; | ||
preciseBar?: string[]; | ||
incomplete?: string; | ||
clear?: boolean; | ||
interval?: number; | ||
|
@@ -25,7 +24,6 @@ interface renderOptions { | |
export class MultiProgressBar { | ||
width: number; | ||
complete: string; | ||
preciseBar: string[]; | ||
incomplete: string; | ||
clear: boolean; | ||
interval: number; | ||
|
@@ -57,7 +55,6 @@ export class MultiProgressBar { | |
title = "", | ||
width = 50, | ||
complete = bgGreen(" "), | ||
preciseBar = [], | ||
incomplete = bgWhite(" "), | ||
clear = false, | ||
interval, | ||
|
@@ -70,7 +67,6 @@ export class MultiProgressBar { | |
} | ||
this.width = width; | ||
this.complete = complete; | ||
this.preciseBar = preciseBar.concat(complete); | ||
this.incomplete = incomplete; | ||
this.clear = clear; | ||
this.interval = interval ?? 16; | ||
|