-
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 9990460
Showing
5 changed files
with
65 additions
and
52 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 |
---|---|---|
|
@@ -11,21 +11,21 @@ ProgressBar in terminal for deno | |
#### 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 +74,7 @@ interface constructorOptions { | |
interval?: number; | ||
display?: string; | ||
prettyTime?: boolean; | ||
writer?: typeof Deno.stdout | typeof Deno.stderr; | ||
} | ||
|
||
interface renderOptions { | ||
|
@@ -109,6 +110,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 +160,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 +195,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 +250,7 @@ interface ConstructorOptions { | |
interval?: number, | ||
display?: string | ||
prettyTime?: boolean; | ||
writer?: typeof Deno.stdout | typeof Deno.stderr; | ||
} | ||
|
||
interface renderOptions { | ||
|
@@ -286,6 +289,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; | ||
|
||
|
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