Skip to content

Commit

Permalink
v.1.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangfuxing committed Aug 12, 2021
1 parent e5908c3 commit a880518
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 71 deletions.
108 changes: 59 additions & 49 deletions README.md
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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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({
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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.
1 change: 1 addition & 0 deletions deps.ts
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";
12 changes: 0 additions & 12 deletions egg.json

This file was deleted.

2 changes: 1 addition & 1 deletion mod.ts
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);
Expand Down
5 changes: 1 addition & 4 deletions mod.unstable.ts
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";
Expand Down
6 changes: 1 addition & 5 deletions multi.ts
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";
Expand All @@ -7,7 +7,6 @@ interface constructorOptions {
title?: string;
width?: number;
complete?: string;
preciseBar?: string[];
incomplete?: string;
clear?: boolean;
interval?: number;
Expand All @@ -25,7 +24,6 @@ interface renderOptions {
export class MultiProgressBar {
width: number;
complete: string;
preciseBar: string[];
incomplete: string;
clear: boolean;
interval: number;
Expand Down Expand Up @@ -57,7 +55,6 @@ export class MultiProgressBar {
title = "",
width = 50,
complete = bgGreen(" "),
preciseBar = [],
incomplete = bgWhite(" "),
clear = false,
interval,
Expand All @@ -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;
Expand Down

0 comments on commit a880518

Please sign in to comment.