deno-library / progress

ProgressBar in terminal for deno
MIT License
60 stars 9 forks source link

Request: Text input when `render` is called #1

Closed SteelAlloy closed 4 years ago

SteelAlloy commented 4 years ago

This module is very good, it gives me what I need.

But I was wondering if it would be possible to display text at each rendering, i.e. to inform about what's going on. For example, the current value of a variable or the file that is being processed.

Either on the right side of the bar: image NOTE: The bars are one on top of the other but it's just to show the look at each render, the bar is of course erased each time.

Or above the bar and just like it, the text would be erased at each rendering: image

I'm asking this because I don't want to pollute the console with millions of messages that could very well be integrated with the bar.

fuxingZhang commented 4 years ago

I have changed my code.

interface renderOptions {
  title?: string,
  total?: number,
  complete?: string,
  incomplete?: string,
}
render(completed: number, options? renderOptions): void;

exmaple

import ProgressBar from "https://deno.land/x/progress@v1.0.0/mod.ts";

const total = 100;

const progress = new ProgressBar({
  total,
  display: ':percent :bar :time :completed/:total :title'
});

let completed = 0;

function run() {
  if (completed <= total) {

    progress.render(completed++, {
      title: `CUSTOM TEXT, value: ${Math.random().toFixed(3)}`
    });

    setTimeout(function () {
      run();
    }, 50)
  }
}

run();
SteelAlloy commented 4 years ago

Thank you very much, that's exactly what I needed! I can display the files that are being processed. progress

I just have a little problem, the titles are of variable length and the bar collapses at times. Is there a way to fix this or is it necessary to keep it from spilling over?

EDIT: When I display accents with progress.console, they are not displayed correctly. I think this is Deno's fault. image

With `console.log': image

fuxingZhang commented 4 years ago

barWidth = Math.min(this.width, ttyWith) - titleWith - percentWidth -timeWidth - (completed/total)Width; Too many settings will cause too complicated. You can modify it to suit your program on the current basis. You can also submit a pull request if you have a good idea.

progress.console use Deno.writeAllSync, I plan to submit a pull request to deno to fix it.

SteelAlloy commented 4 years ago

I think it will be better when the TTY columns will be supported. Thank you!

fuxingZhang commented 4 years ago

process.console bug, can see this issue:

https://github.com/denoland/deno/issues/6001