npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

clui-progressbar

v0.1.1

Published

Simple terminal progress bar, backed by clui-live

Downloads

6

Readme

clui-progressbar

Simple terminal progress bar, backed by clui-live

Installation

npm install --save clui-progressbar

Usage

You can call the .setState() method when updating more than just the progress, or simple set the handly .percentage property on the object.

import { LiveProgressBar } from 'clui-live';

const progressbar = new LiveProgressBar( { title: 'Long running task...' } );

for ( let i = 0; i < 100; i++ ) {
    progressbar.percentage = i;

    await sleepRandom();
}

for ( let i = 0; i < 100; i++ ) {
    progressbar.setState( {
        percentage: i,
        rightLabel: 'Some other stat (like speed)'
    } );

    await sleepRandom();
}

// The progressbar is a live area, so we can use any of the habitual methods on it, like closing
progressbar.close();

API

The component LiveProgressBar extends the LiveComponent, which in turn extends the LiveArea class.

interface ProgressBarState

interface ProgressBarState {
    // Shown on the line above the progress bar
    title ?: string;
    // A value between 0 and 100. Values outside of this range are clamped.
    percentage : number;
    // Shown on the left side of the progressbar
    leftLabel ?: string;
    // Shown on the right side of the progressbar
    rightLabel ?: string;
}

new LiveProgressBar( initialState ?: ProgressBarState )

Creates a LiveProgressBar. Optionaly accepts an initial state.

.progress : number

Is an alias to .state.progress when getting, and to .setState( { progress: value } ) when setting.

.state : ProgressBarState

Holds the current state of the component. Should not be updated manually, as doing so won't not refresh the terminal

.maxWidth : number = Infinity

Allows to define a max width for the progress bar (including any labels it might have). By default it's value is infinity, which means the progress bar tries to fit the entire terminal's width.

.hook() : this

Hooks this component to the global LiveContainer. Useful when there may be lines written to the terminal while the progress bar is showing, which would traditionally cause the output to become a mess (since the cursor would now be in a different position). Calling this method monkey patches some methods (like console.log) to account for this type of sittuations.

.clear() : this

Can be called to clear the output of the progress bar from the screen. There is no need to manually call this method when updating the progress bar. However it can come in handy if we don't want the progress bar to remain visible after it has finished (must be called before .close()).

.close() : this

Should be called when the progress bar is finished and won't be used any more, to release resources