-
-
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.
feat: allow to configure the writer to stderr (#30)
- Loading branch information
zhangfuxing
committed
Oct 30, 2024
1 parent
bcc5d0d
commit 32cd98a
Showing
6 changed files
with
70 additions
and
57 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 |
---|---|---|
|
@@ -4,28 +4,32 @@ ProgressBar in terminal for deno | |
|
||
![logo](screenshots/logo.png) | ||
|
||
## Changelog | ||
|
||
[changelog](./changelog.md) | ||
|
||
## Usage | ||
|
||
### Multiple progress bars | ||
|
||
#### example | ||
|
||
```ts | ||
import { MultiProgressBar } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { delay } from "https://deno.land/[email protected]/async/delay.ts"; | ||
|
||
// or JSR | ||
// import { MultiProgressBar } from "jsr:@deno-library/progress"; | ||
// import { delay } from "jsr:@std/async"; | ||
import { MultiProgressBar } from "jsr:@deno-library/progress"; | ||
import { delay } from "jsr:@std/async"; | ||
|
||
// or JSR (with version) | ||
// import { MultiProgressBar } from "jsr:@deno-library/progress@1.4.9"; | ||
// import { MultiProgressBar } from "jsr:@deno-library/progress@1.5.0"; | ||
// import { delay } from "jsr:@std/[email protected]"; | ||
|
||
// or JSR (no prefix, run `deno add @deno-library/progress` and `deno add @std/async`) | ||
// import { MultiProgressBar } from "@deno-library/progress"; | ||
// import { delay } from "@std/async"; | ||
|
||
// or | ||
// import { MultiProgressBar } from "https://deno.land/x/[email protected]/mod.ts"; | ||
// import { delay } from "https://deno.land/[email protected]/async/delay.ts"; | ||
|
||
const title = "download files"; | ||
const total = 100; | ||
|
||
|
@@ -74,6 +78,7 @@ interface constructorOptions { | |
interval?: number; | ||
display?: string; | ||
prettyTime?: boolean; | ||
output?: typeof Deno.stdout | typeof Deno.stderr; | ||
} | ||
|
||
interface renderOptions { | ||
|
@@ -109,6 +114,7 @@ class MultiProgressBar { | |
* @param interval minimum time between updates in milliseconds, default: 16 | ||
* @param display What is displayed and display order, default: ':bar :text :percent :time :completed/:total' | ||
* @param prettyTime Whether to pretty print time and eta | ||
* @param output Output stream, can be Deno.stdout or Deno.stderr, default is Deno.stdout | ||
*/ | ||
constructor(options: ConstructorOptions); | ||
|
||
|
@@ -158,21 +164,21 @@ What is displayed and display order, default: ':bar :text :percent :time | |
#### simple example | ||
|
||
```ts | ||
import ProgressBar from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { delay } from "https://deno.land/[email protected]/async/delay.ts"; | ||
|
||
// or JSR | ||
// import ProgressBar from "jsr:@deno-library/progress"; | ||
// import { delay } from "jsr:@std/async"; | ||
import ProgressBar from "jsr:@deno-library/progress"; | ||
import { delay } from "jsr:@std/async"; | ||
|
||
// or JSR (with version) | ||
// import ProgressBar from "jsr:@deno-library/progress@1.4.9"; | ||
// import ProgressBar from "jsr:@deno-library/progress@1.5.0"; | ||
// import { delay } from "jsr:@std/[email protected]"; | ||
|
||
// or JSR (no prefix, run `deno add @deno-library/progress` and `deno add @std/async`) | ||
// import ProgressBar from "@deno-library/progress"; | ||
// import { delay } from "@std/async"; | ||
|
||
// or | ||
// import ProgressBar from "https://deno.land/x/[email protected]/mod.ts"; | ||
// import { delay } from "@std/async/delay"; | ||
|
||
const title = "downloading:"; | ||
const total = 100; | ||
const progress = new ProgressBar({ | ||
|
@@ -193,21 +199,21 @@ await download(); | |
#### complex example | ||
|
||
```ts | ||
import ProgressBar from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { delay } from "https://deno.land/[email protected]/async/delay.ts"; | ||
|
||
// or JSR | ||
// import ProgressBar from "jsr:@deno-library/progress"; | ||
// import { delay } from "jsr:@std/async"; | ||
import ProgressBar from "jsr:@deno-library/progress"; | ||
import { delay } from "jsr:@std/async"; | ||
|
||
// or JSR (with version) | ||
// import ProgressBar from "jsr:@deno-library/progress@1.4.9"; | ||
// import ProgressBar from "jsr:@deno-library/progress@1.5.0"; | ||
// import { delay } from "jsr:@std/[email protected]"; | ||
|
||
// or JSR (no prefix, run `deno add @deno-library/progress` and `deno add @std/async`) | ||
// import ProgressBar from "@deno-library/progress"; | ||
// import { delay } from "@std/async"; | ||
|
||
// or | ||
// import ProgressBar from "https://deno.land/x/[email protected]/mod.ts"; | ||
// import { delay } from "@std/async/delay"; | ||
|
||
const total = 100; | ||
const progress = new ProgressBar({ | ||
total, | ||
|
@@ -248,6 +254,7 @@ interface ConstructorOptions { | |
interval?: number, | ||
display?: string | ||
prettyTime?: boolean; | ||
output?: typeof Deno.stdout | typeof Deno.stderr; | ||
} | ||
|
||
interface renderOptions { | ||
|
@@ -286,6 +293,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' | ||
* @param prettyTime Whether to pretty print time and eta | ||
* @param output Output stream, can be Deno.stdout or Deno.stderr, default is Deno.stdout | ||
*/ | ||
constructor(options: ConstructorOptions): void; | ||
|
||
|
@@ -382,7 +390,3 @@ Log some messages next to the bar | |
![console](./screenshots/info.gif) | ||
|
||
More screenshots in the `screenshots` folder. | ||
|
||
## Changelog | ||
|
||
[changelog](./changelog.md) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import ProgressBar from "../mod.ts"; | ||
import { delay } from "../deps.example.ts"; | ||
|
||
const total = 100; | ||
|
||
const progress = new ProgressBar({ | ||
total, | ||
// ==> here | ||
output: Deno.stderr, | ||
// <== here | ||
}); | ||
|
||
let completed = 0; | ||
|
||
async function download() { | ||
while (completed <= total) { | ||
await progress.render(completed++); | ||
|
||
await delay(50); | ||
} | ||
} | ||
|
||
await download(); |
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