/ archiveofbelonging.org / back / node_modules / gauge /

[ICO]NameLast modifiedSizeDescription
[PARENTDIR]Parent Directory  -  
[TXT]CHANGELOG.md8 years ago6.2K 
[   ]LICENSE10 years ago751 7375cab EXHIBTION: fix overflow ellipsis cutoff [كارل مبارك]
[TXT]README.md8 years ago 15Kf12eb36 documentaiton updates [كارل مبارك]
[   ]base-theme.js9 years ago395  
[   ]error.js9 years ago616  
[   ]has-color.js9 years ago292  
[   ]index.js8 years ago6.8K 
[   ]package.json2 years ago2.0K7375cab EXHIBTION: fix overflow ellipsis cutoff [كارل مبارك]
[   ]plumbing.js8 years ago1.2K 
[   ]process.js9 years ago 89  
[   ]progress-bar.js9 years ago1.0K 
[   ]render-template.js9 years ago5.6K 
[   ]set-immediate.js9 years ago139  
[   ]set-interval.js9 years ago 93  
[   ]spin.js9 years ago105  
[   ]template-item.js9 years ago1.9K 
[   ]theme-set.js9 years ago3.6K 
[   ]themes.js9 years ago1.5K 
[   ]wide-truncate.js9 years ago828  
README.md

gauge

A nearly stateless terminal based horizontal gauge / progress bar.

var Gauge = require("gauge")

var gauge = new Gauge()

gauge.show("test", 0.20)

gauge.pulse("this")

gauge.hide()

CHANGES FROM 1.x

Gauge 2.x is breaking release, please see the changelog for details on what's changed if you were previously a user of this module.

THE GAUGE CLASS

This is the typical interface to the module– it provides a pretty fire-and-forget interface to displaying your status information.

var Gauge = require("gauge")

var gauge = new Gauge([stream], [options])

Constructs a new gauge. Gauges are drawn on a single line, and are not drawn if stream isn't a tty and a tty isn't explicitly provided.

If stream is a terminal or if you pass in tty to options then we will detect terminal resizes and redraw to fit. We do this by watching for resize events on the tty. (To work around a bug in verisons of Node prior to 2.5.0, we watch for them on stdout if the tty is stderr.) Resizes to larger window sizes will be clean, but shrinking the window will always result in some cruft.

IMPORTANT: If you prevously were passing in a non-tty stream but you still want output (for example, a stream wrapped by the ansi module) then you need to pass in the tty option below, as gauge needs access to the underlying tty in order to do things like terminal resizes and terminal width detection.

The options object can have the following properties, all of which are optional:

gauge.show(section | status, [completed])

The first argument is either the section, the name of the current thing contributing to progress, or an object with keys like section, subsection & completed (or any others you have types for in a custom template). If you don't want to update or set any of these you can pass null and it will be ignored.

The second argument is the percent completed as a value between 0 and 1. Without it, completion is just not updated. You'll also note that completion can be passed in as part of a status object as the first argument. If both it and the completed argument are passed in, the completed argument wins.

gauge.hide([cb])

Removes the gauge from the terminal. Optionally, callback cb after IO has had an opportunity to happen (currently this just means after setImmediate has called back.)

It turns out this is important when you're pausing the progress bar on one filehandle and printing to another– otherwise (with a big enough print) node can end up printing the "end progress bar" bits to the progress bar filehandle while other stuff is printing to another filehandle. These getting interleaved can cause corruption in some terminals.

gauge.pulse([subsection])

Spins the spinner in the gauge to show output. If subsection is included then it will be combined with the last name passed to gauge.show.

gauge.disable()

Hides the gauge and ignores further calls to show or pulse.

gauge.enable()

Shows the gauge and resumes updating when show or pulse is called.

gauge.isEnabled()

Returns true if the gauge is enabled.

gauge.setThemeset(themes)

Change the themeset to select a theme from. The same as the themes option used in the constructor. The theme will be reselected from this themeset.

gauge.setTheme(theme)

Change the active theme, will be displayed with the next show or pulse. This can be:

If no theme is selected then a default is picked using a combination of our best guesses at your OS, color support and unicode support.

gauge.setTemplate(template)

Change the active template, will be displayed with the next show or pulse

Tracking Completion

If you have more than one thing going on that you want to track completion of, you may find the related are-we-there-yet helpful. It's change event can be wired up to the show method to get a more traditional progress bar interface.

THEMES

var themes = require('gauge/themes')

// fetch the default color unicode theme for this platform
var ourTheme = themes({hasUnicode: true, hasColor: true})

// fetch the default non-color unicode theme for osx
var ourTheme = themes({hasUnicode: true, hasColor: false, platform: 'darwin'})

// create a new theme based on the color ascii theme for this platform
// that brackets the progress bar with arrows
var ourTheme = themes.newTheme(theme(hasUnicode: false, hasColor: true}), {
  preProgressbar: '→',
  postProgressbar: '←'
})

The object returned by gauge/themes is an instance of the ThemeSet class.

var ThemeSet = require('gauge/theme-set')
var themes = new ThemeSet()
// or
var themes = require('gauge/themes')
var mythemes = themes.newThemeset() // creates a new themeset based on the default themes

themes(opts)

themes.getDefault(opts)

Theme objects are a function that fetches the default theme based on platform, unicode and color support.

Options is an object with the following properties:

If no compatible theme can be found then an error will be thrown with a code of EMISSINGTHEME.

themes.addTheme(themeName, themeObj)

themes.addTheme(themeName, [parentTheme], newTheme)

Adds a named theme to the themeset. You can pass in either a theme object, as returned by themes.newTheme or the arguments you'd pass to themes.newTheme.

themes.getThemeNames()

Return a list of all of the names of the themes in this themeset. Suitable for use in themes.getTheme(…).

themes.getTheme(name)

Returns the theme object from this theme set named name.

If name does not exist in this themeset an error will be thrown with a code of EMISSINGTHEME.

themes.setDefault([opts], themeName)

opts is an object with the following properties.

themeName is the name of the theme (as given to addTheme) to use for this set of opts.

themes.newTheme([parentTheme,] newTheme)

Create a new theme object based on parentTheme. If no parentTheme is provided then a minimal parentTheme that defines functions for rendering the activity indicator (spinner) and progress bar will be defined. (This fallback parent is defined in gauge/base-theme.)

newTheme should be a bare object– we'll start by discussing the properties defined by the default themes:

More generally, themes can have any value that would be a valid value when rendering templates. The properties in the theme are used when their name matches a type in the template. Their values can be:

There are a couple of special prefixes:

And one special suffix:

themes.addToAllThemes(theme)

This mixes-in theme into all themes currently defined. It also adds it to the default parent theme for this themeset, so future themes added to this themeset will get the values from theme by default.

themes.newThemeset()

Copy the current themeset into a new one. This allows you to easily inherit one themeset from another.

TEMPLATES

A template is an array of objects and strings that, after being evaluated, will be turned into the gauge line. The default template is:

[
    {type: 'progressbar', length: 20},
    {type: 'activityIndicator', kerning: 1, length: 1},
    {type: 'section', kerning: 1, default: ''},
    {type: 'subsection', kerning: 1, default: ''}
]

The various template elements can either be plain strings, in which case they will be be included verbatum in the output, or objects with the following properties:

PLUMBING

This is the super simple, assume nothing, do no magic internals used by gauge to implement its ordinary interface.

var Plumbing = require('gauge/plumbing')
var gauge = new Plumbing(theme, template, width)

gauge.setTheme(theme)

Change the active theme.

gauge.setTemplate(template)

Change the active template.

gauge.setWidth(width)

Change the width to render at.

gauge.hide()

Return the string necessary to hide the progress bar

gauge.hideCursor()

Return a string to hide the cursor.

gauge.showCursor()

Return a string to show the cursor.

gauge.show(status)

Using status for values, render the provided template with the theme and return a string that is suitable for printing to update the gauge.

Apache/2.4.38 (Debian) Server at www.karls.computer Port 80