$
This commit is contained in:
20
node_modules/gauge/LICENSE.md
generated
vendored
Normal file
20
node_modules/gauge/LICENSE.md
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
<!-- This file is automatically added by @npmcli/template-oss. Do not edit. -->
|
||||
|
||||
ISC License
|
||||
|
||||
Copyright npm, Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this
|
||||
software for any purpose with or without fee is hereby
|
||||
granted, provided that the above copyright notice and this
|
||||
permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND NPM DISCLAIMS ALL
|
||||
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
|
||||
EVENT SHALL NPM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
|
||||
USE OR PERFORMANCE OF THIS SOFTWARE.
|
402
node_modules/gauge/README.md
generated
vendored
Normal file
402
node_modules/gauge/README.md
generated
vendored
Normal file
@@ -0,0 +1,402 @@
|
||||
gauge
|
||||
=====
|
||||
|
||||
A nearly stateless terminal based horizontal gauge / progress bar.
|
||||
|
||||
```javascript
|
||||
var Gauge = require("gauge")
|
||||
|
||||
var gauge = new Gauge()
|
||||
|
||||
gauge.show("working…", 0)
|
||||
setTimeout(() => { gauge.pulse(); gauge.show("working…", 0.25) }, 500)
|
||||
setTimeout(() => { gauge.pulse(); gauge.show("working…", 0.50) }, 1000)
|
||||
setTimeout(() => { gauge.pulse(); gauge.show("working…", 0.75) }, 1500)
|
||||
setTimeout(() => { gauge.pulse(); gauge.show("working…", 0.99) }, 2000)
|
||||
setTimeout(() => gauge.hide(), 2300)
|
||||
```
|
||||
|
||||
See also the [demos](docs/demo.js):
|
||||
|
||||

|
||||
|
||||
|
||||
### 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.
|
||||
|
||||
[changelog]: CHANGELOG.md
|
||||
|
||||
### 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])
|
||||
```
|
||||
|
||||
* **stream** – *(optional, default STDERR)* A stream that progress bar
|
||||
updates are to be written to. Gauge honors backpressure and will pause
|
||||
most writing if it is indicated.
|
||||
* **options** – *(optional)* An option object.
|
||||
|
||||
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 versions 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 previously 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:
|
||||
|
||||
* **updateInterval**: How often gauge updates should be drawn, in milliseconds.
|
||||
* **fixedFramerate**: Defaults to false on node 0.8, true on everything
|
||||
else. When this is true a timer is created to trigger once every
|
||||
`updateInterval` ms, when false, updates are printed as soon as they come
|
||||
in but updates more often than `updateInterval` are ignored. The reason
|
||||
0.8 doesn't have this set to true is that it can't `unref` its timer and
|
||||
so it would stop your program from exiting– if you want to use this
|
||||
feature with 0.8 just make sure you call `gauge.disable()` before you
|
||||
expect your program to exit.
|
||||
* **themes**: A themeset to use when selecting the theme to use. Defaults
|
||||
to `gauge/themes`, see the [themes] documentation for details.
|
||||
* **theme**: Select a theme for use, it can be a:
|
||||
* Theme object, in which case the **themes** is not used.
|
||||
* The name of a theme, which will be looked up in the current *themes*
|
||||
object.
|
||||
* A configuration object with any of `hasUnicode`, `hasColor` or
|
||||
`platform` keys, which if will be used to override our guesses when making
|
||||
a default theme selection.
|
||||
|
||||
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.
|
||||
* **template**: Describes what you want your gauge to look like. The
|
||||
default is what npm uses. Detailed [documentation] is later in this
|
||||
document.
|
||||
* **hideCursor**: Defaults to true. If true, then the cursor will be hidden
|
||||
while the gauge is displayed.
|
||||
* **tty**: The tty that you're ultimately writing to. Defaults to the same
|
||||
as **stream**. This is used for detecting the width of the terminal and
|
||||
resizes. The width used is `tty.columns - 1`. If no tty is available then
|
||||
a width of `79` is assumed.
|
||||
* **enabled**: Defaults to true if `tty` is a TTY, false otherwise. If true
|
||||
the gauge starts enabled. If disabled then all update commands are
|
||||
ignored and no gauge will be printed until you call `.enable()`.
|
||||
* **Plumbing**: The class to use to actually generate the gauge for
|
||||
printing. This defaults to `require('gauge/plumbing')` and ordinarily you
|
||||
shouldn't need to override this.
|
||||
* **cleanupOnExit**: Defaults to true. Ordinarily we register an exit
|
||||
handler to make sure your cursor is turned back on and the progress bar
|
||||
erased when your process exits, even if you Ctrl-C out or otherwise exit
|
||||
unexpectedly. You can disable this and it won't register the exit handler.
|
||||
|
||||
[has-unicode]: https://www.npmjs.com/package/has-unicode
|
||||
[themes]: #themes
|
||||
[documentation]: #templates
|
||||
|
||||
#### `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])`
|
||||
|
||||
* **subsection** – *(optional)* The specific thing that triggered this pulse
|
||||
|
||||
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:
|
||||
|
||||
* Theme object, in which case the **themes** is not used.
|
||||
* The name of a theme, which will be looked up in the current *themes*
|
||||
object.
|
||||
* A configuration object with any of `hasUnicode`, `hasColor` or
|
||||
`platform` keys, which if will be used to override our guesses when making
|
||||
a default theme selection.
|
||||
|
||||
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.
|
||||
|
||||
[are-we-there-yet]: https://www.npmjs.com/package/are-we-there-yet
|
||||
|
||||
### 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(themes({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:
|
||||
|
||||
* **hasUnicode** - If true, fetch a unicode theme, if no unicode theme is
|
||||
available then a non-unicode theme will be used.
|
||||
* **hasColor** - If true, fetch a color theme, if no color theme is
|
||||
available a non-color theme will be used.
|
||||
* **platform** (optional) - Defaults to `process.platform`. If no
|
||||
platform match is available then `fallback` is used instead.
|
||||
|
||||
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.
|
||||
|
||||
* **platform** - Defaults to `'fallback'`. If your theme is platform
|
||||
specific, specify that here with the platform from `process.platform`, eg,
|
||||
`win32`, `darwin`, etc.
|
||||
* **hasUnicode** - Defaults to `false`. If your theme uses unicode you
|
||||
should set this to true.
|
||||
* **hasColor** - Defaults to `false`. If your theme uses color you should
|
||||
set this to true.
|
||||
|
||||
`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:
|
||||
|
||||
* **preProgressbar** - displayed prior to the progress bar, if the progress
|
||||
bar is displayed.
|
||||
* **postProgressbar** - displayed after the progress bar, if the progress bar
|
||||
is displayed.
|
||||
* **progressBarTheme** - The subtheme passed through to the progress bar
|
||||
renderer, it's an object with `complete` and `remaining` properties
|
||||
that are the strings you want repeated for those sections of the progress
|
||||
bar.
|
||||
* **activityIndicatorTheme** - The theme for the activity indicator (spinner),
|
||||
this can either be a string, in which each character is a different step, or
|
||||
an array of strings.
|
||||
* **preSubsection** - Displayed as a separator between the `section` and
|
||||
`subsection` when the latter is printed.
|
||||
|
||||
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:
|
||||
|
||||
* **strings & numbers** - They'll be included as is
|
||||
* **function (values, theme, width)** - Should return what you want in your output.
|
||||
*values* is an object with values provided via `gauge.show`,
|
||||
*theme* is the theme specific to this item (see below) or this theme object,
|
||||
and *width* is the number of characters wide your result should be.
|
||||
|
||||
There are a couple of special prefixes:
|
||||
|
||||
* **pre** - Is shown prior to the property, if its displayed.
|
||||
* **post** - Is shown after the property, if its displayed.
|
||||
|
||||
And one special suffix:
|
||||
|
||||
* **Theme** - Its value is passed to a function-type item as the theme.
|
||||
|
||||
#### 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:
|
||||
|
||||
```javascript
|
||||
[
|
||||
{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:
|
||||
|
||||
* *type* can be any of the following plus any keys you pass into `gauge.show` plus
|
||||
any keys you have on a custom theme.
|
||||
* `section` – What big thing you're working on now.
|
||||
* `subsection` – What component of that thing is currently working.
|
||||
* `activityIndicator` – Shows a spinner using the `activityIndicatorTheme`
|
||||
from your active theme.
|
||||
* `progressbar` – A progress bar representing your current `completed`
|
||||
using the `progressbarTheme` from your active theme.
|
||||
* *kerning* – Number of spaces that must be between this item and other
|
||||
items, if this item is displayed at all.
|
||||
* *maxLength* – The maximum length for this element. If its value is longer it
|
||||
will be truncated.
|
||||
* *minLength* – The minimum length for this element. If its value is shorter it
|
||||
will be padded according to the *align* value.
|
||||
* *align* – (Default: left) Possible values "left", "right" and "center". Works
|
||||
as you'd expect from word processors.
|
||||
* *length* – Provides a single value for both *minLength* and *maxLength*. If both
|
||||
*length* and *minLength or *maxLength* are specified then the latter take precedence.
|
||||
* *value* – A literal value to use for this template item.
|
||||
* *default* – A default value to use for this template item if a value
|
||||
wasn't otherwise passed in.
|
||||
|
||||
### 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)
|
||||
```
|
||||
|
||||
* **theme**: The theme to use.
|
||||
* **template**: The template to use.
|
||||
* **width**: How wide your gauge should be
|
||||
|
||||
#### `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.
|
18
node_modules/gauge/lib/base-theme.js
generated
vendored
Normal file
18
node_modules/gauge/lib/base-theme.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
'use strict'
|
||||
var spin = require('./spin.js')
|
||||
var progressBar = require('./progress-bar.js')
|
||||
|
||||
module.exports = {
|
||||
activityIndicator: function (values, theme, width) {
|
||||
if (values.spun == null) {
|
||||
return
|
||||
}
|
||||
return spin(theme, values.spun)
|
||||
},
|
||||
progressbar: function (values, theme, width) {
|
||||
if (values.completed == null) {
|
||||
return
|
||||
}
|
||||
return progressBar(theme, width, values.completed)
|
||||
},
|
||||
}
|
24
node_modules/gauge/lib/error.js
generated
vendored
Normal file
24
node_modules/gauge/lib/error.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
'use strict'
|
||||
var util = require('util')
|
||||
|
||||
var User = exports.User = function User (msg) {
|
||||
var err = new Error(msg)
|
||||
Error.captureStackTrace(err, User)
|
||||
err.code = 'EGAUGE'
|
||||
return err
|
||||
}
|
||||
|
||||
exports.MissingTemplateValue = function MissingTemplateValue (item, values) {
|
||||
var err = new User(util.format('Missing template value "%s"', item.type))
|
||||
Error.captureStackTrace(err, MissingTemplateValue)
|
||||
err.template = item
|
||||
err.values = values
|
||||
return err
|
||||
}
|
||||
|
||||
exports.Internal = function Internal (msg) {
|
||||
var err = new Error(msg)
|
||||
Error.captureStackTrace(err, Internal)
|
||||
err.code = 'EGAUGEINTERNAL'
|
||||
return err
|
||||
}
|
4
node_modules/gauge/lib/has-color.js
generated
vendored
Normal file
4
node_modules/gauge/lib/has-color.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
'use strict'
|
||||
var colorSupport = require('color-support')
|
||||
|
||||
module.exports = colorSupport().hasBasic
|
289
node_modules/gauge/lib/index.js
generated
vendored
Normal file
289
node_modules/gauge/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,289 @@
|
||||
'use strict'
|
||||
var Plumbing = require('./plumbing.js')
|
||||
var hasUnicode = require('has-unicode')
|
||||
var hasColor = require('./has-color.js')
|
||||
var onExit = require('signal-exit')
|
||||
var defaultThemes = require('./themes')
|
||||
var setInterval = require('./set-interval.js')
|
||||
var process = require('./process.js')
|
||||
var setImmediate = require('./set-immediate')
|
||||
|
||||
module.exports = Gauge
|
||||
|
||||
function callWith (obj, method) {
|
||||
return function () {
|
||||
return method.call(obj)
|
||||
}
|
||||
}
|
||||
|
||||
function Gauge (arg1, arg2) {
|
||||
var options, writeTo
|
||||
if (arg1 && arg1.write) {
|
||||
writeTo = arg1
|
||||
options = arg2 || {}
|
||||
} else if (arg2 && arg2.write) {
|
||||
writeTo = arg2
|
||||
options = arg1 || {}
|
||||
} else {
|
||||
writeTo = process.stderr
|
||||
options = arg1 || arg2 || {}
|
||||
}
|
||||
|
||||
this._status = {
|
||||
spun: 0,
|
||||
section: '',
|
||||
subsection: '',
|
||||
}
|
||||
this._paused = false // are we paused for back pressure?
|
||||
this._disabled = true // are all progress bar updates disabled?
|
||||
this._showing = false // do we WANT the progress bar on screen
|
||||
this._onScreen = false // IS the progress bar on screen
|
||||
this._needsRedraw = false // should we print something at next tick?
|
||||
this._hideCursor = options.hideCursor == null ? true : options.hideCursor
|
||||
this._fixedFramerate = options.fixedFramerate == null
|
||||
? !(/^v0\.8\./.test(process.version))
|
||||
: options.fixedFramerate
|
||||
this._lastUpdateAt = null
|
||||
this._updateInterval = options.updateInterval == null ? 50 : options.updateInterval
|
||||
|
||||
this._themes = options.themes || defaultThemes
|
||||
this._theme = options.theme
|
||||
var theme = this._computeTheme(options.theme)
|
||||
var template = options.template || [
|
||||
{ type: 'progressbar', length: 20 },
|
||||
{ type: 'activityIndicator', kerning: 1, length: 1 },
|
||||
{ type: 'section', kerning: 1, default: '' },
|
||||
{ type: 'subsection', kerning: 1, default: '' },
|
||||
]
|
||||
this.setWriteTo(writeTo, options.tty)
|
||||
var PlumbingClass = options.Plumbing || Plumbing
|
||||
this._gauge = new PlumbingClass(theme, template, this.getWidth())
|
||||
|
||||
this._$$doRedraw = callWith(this, this._doRedraw)
|
||||
this._$$handleSizeChange = callWith(this, this._handleSizeChange)
|
||||
|
||||
this._cleanupOnExit = options.cleanupOnExit == null || options.cleanupOnExit
|
||||
this._removeOnExit = null
|
||||
|
||||
if (options.enabled || (options.enabled == null && this._tty && this._tty.isTTY)) {
|
||||
this.enable()
|
||||
} else {
|
||||
this.disable()
|
||||
}
|
||||
}
|
||||
Gauge.prototype = {}
|
||||
|
||||
Gauge.prototype.isEnabled = function () {
|
||||
return !this._disabled
|
||||
}
|
||||
|
||||
Gauge.prototype.setTemplate = function (template) {
|
||||
this._gauge.setTemplate(template)
|
||||
if (this._showing) {
|
||||
this._requestRedraw()
|
||||
}
|
||||
}
|
||||
|
||||
Gauge.prototype._computeTheme = function (theme) {
|
||||
if (!theme) {
|
||||
theme = {}
|
||||
}
|
||||
if (typeof theme === 'string') {
|
||||
theme = this._themes.getTheme(theme)
|
||||
} else if (
|
||||
Object.keys(theme).length === 0 || theme.hasUnicode != null || theme.hasColor != null
|
||||
) {
|
||||
var useUnicode = theme.hasUnicode == null ? hasUnicode() : theme.hasUnicode
|
||||
var useColor = theme.hasColor == null ? hasColor : theme.hasColor
|
||||
theme = this._themes.getDefault({
|
||||
hasUnicode: useUnicode,
|
||||
hasColor: useColor,
|
||||
platform: theme.platform,
|
||||
})
|
||||
}
|
||||
return theme
|
||||
}
|
||||
|
||||
Gauge.prototype.setThemeset = function (themes) {
|
||||
this._themes = themes
|
||||
this.setTheme(this._theme)
|
||||
}
|
||||
|
||||
Gauge.prototype.setTheme = function (theme) {
|
||||
this._gauge.setTheme(this._computeTheme(theme))
|
||||
if (this._showing) {
|
||||
this._requestRedraw()
|
||||
}
|
||||
this._theme = theme
|
||||
}
|
||||
|
||||
Gauge.prototype._requestRedraw = function () {
|
||||
this._needsRedraw = true
|
||||
if (!this._fixedFramerate) {
|
||||
this._doRedraw()
|
||||
}
|
||||
}
|
||||
|
||||
Gauge.prototype.getWidth = function () {
|
||||
return ((this._tty && this._tty.columns) || 80) - 1
|
||||
}
|
||||
|
||||
Gauge.prototype.setWriteTo = function (writeTo, tty) {
|
||||
var enabled = !this._disabled
|
||||
if (enabled) {
|
||||
this.disable()
|
||||
}
|
||||
this._writeTo = writeTo
|
||||
this._tty = tty ||
|
||||
(writeTo === process.stderr && process.stdout.isTTY && process.stdout) ||
|
||||
(writeTo.isTTY && writeTo) ||
|
||||
this._tty
|
||||
if (this._gauge) {
|
||||
this._gauge.setWidth(this.getWidth())
|
||||
}
|
||||
if (enabled) {
|
||||
this.enable()
|
||||
}
|
||||
}
|
||||
|
||||
Gauge.prototype.enable = function () {
|
||||
if (!this._disabled) {
|
||||
return
|
||||
}
|
||||
this._disabled = false
|
||||
if (this._tty) {
|
||||
this._enableEvents()
|
||||
}
|
||||
if (this._showing) {
|
||||
this.show()
|
||||
}
|
||||
}
|
||||
|
||||
Gauge.prototype.disable = function () {
|
||||
if (this._disabled) {
|
||||
return
|
||||
}
|
||||
if (this._showing) {
|
||||
this._lastUpdateAt = null
|
||||
this._showing = false
|
||||
this._doRedraw()
|
||||
this._showing = true
|
||||
}
|
||||
this._disabled = true
|
||||
if (this._tty) {
|
||||
this._disableEvents()
|
||||
}
|
||||
}
|
||||
|
||||
Gauge.prototype._enableEvents = function () {
|
||||
if (this._cleanupOnExit) {
|
||||
this._removeOnExit = onExit(callWith(this, this.disable))
|
||||
}
|
||||
this._tty.on('resize', this._$$handleSizeChange)
|
||||
if (this._fixedFramerate) {
|
||||
this.redrawTracker = setInterval(this._$$doRedraw, this._updateInterval)
|
||||
if (this.redrawTracker.unref) {
|
||||
this.redrawTracker.unref()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Gauge.prototype._disableEvents = function () {
|
||||
this._tty.removeListener('resize', this._$$handleSizeChange)
|
||||
if (this._fixedFramerate) {
|
||||
clearInterval(this.redrawTracker)
|
||||
}
|
||||
if (this._removeOnExit) {
|
||||
this._removeOnExit()
|
||||
}
|
||||
}
|
||||
|
||||
Gauge.prototype.hide = function (cb) {
|
||||
if (this._disabled) {
|
||||
return cb && process.nextTick(cb)
|
||||
}
|
||||
if (!this._showing) {
|
||||
return cb && process.nextTick(cb)
|
||||
}
|
||||
this._showing = false
|
||||
this._doRedraw()
|
||||
cb && setImmediate(cb)
|
||||
}
|
||||
|
||||
Gauge.prototype.show = function (section, completed) {
|
||||
this._showing = true
|
||||
if (typeof section === 'string') {
|
||||
this._status.section = section
|
||||
} else if (typeof section === 'object') {
|
||||
var sectionKeys = Object.keys(section)
|
||||
for (var ii = 0; ii < sectionKeys.length; ++ii) {
|
||||
var key = sectionKeys[ii]
|
||||
this._status[key] = section[key]
|
||||
}
|
||||
}
|
||||
if (completed != null) {
|
||||
this._status.completed = completed
|
||||
}
|
||||
if (this._disabled) {
|
||||
return
|
||||
}
|
||||
this._requestRedraw()
|
||||
}
|
||||
|
||||
Gauge.prototype.pulse = function (subsection) {
|
||||
this._status.subsection = subsection || ''
|
||||
this._status.spun++
|
||||
if (this._disabled) {
|
||||
return
|
||||
}
|
||||
if (!this._showing) {
|
||||
return
|
||||
}
|
||||
this._requestRedraw()
|
||||
}
|
||||
|
||||
Gauge.prototype._handleSizeChange = function () {
|
||||
this._gauge.setWidth(this._tty.columns - 1)
|
||||
this._requestRedraw()
|
||||
}
|
||||
|
||||
Gauge.prototype._doRedraw = function () {
|
||||
if (this._disabled || this._paused) {
|
||||
return
|
||||
}
|
||||
if (!this._fixedFramerate) {
|
||||
var now = Date.now()
|
||||
if (this._lastUpdateAt && now - this._lastUpdateAt < this._updateInterval) {
|
||||
return
|
||||
}
|
||||
this._lastUpdateAt = now
|
||||
}
|
||||
if (!this._showing && this._onScreen) {
|
||||
this._onScreen = false
|
||||
var result = this._gauge.hide()
|
||||
if (this._hideCursor) {
|
||||
result += this._gauge.showCursor()
|
||||
}
|
||||
return this._writeTo.write(result)
|
||||
}
|
||||
if (!this._showing && !this._onScreen) {
|
||||
return
|
||||
}
|
||||
if (this._showing && !this._onScreen) {
|
||||
this._onScreen = true
|
||||
this._needsRedraw = true
|
||||
if (this._hideCursor) {
|
||||
this._writeTo.write(this._gauge.hideCursor())
|
||||
}
|
||||
}
|
||||
if (!this._needsRedraw) {
|
||||
return
|
||||
}
|
||||
if (!this._writeTo.write(this._gauge.show(this._status))) {
|
||||
this._paused = true
|
||||
this._writeTo.on('drain', callWith(this, function () {
|
||||
this._paused = false
|
||||
this._doRedraw()
|
||||
}))
|
||||
}
|
||||
}
|
50
node_modules/gauge/lib/plumbing.js
generated
vendored
Normal file
50
node_modules/gauge/lib/plumbing.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
'use strict'
|
||||
var consoleControl = require('console-control-strings')
|
||||
var renderTemplate = require('./render-template.js')
|
||||
var validate = require('aproba')
|
||||
|
||||
var Plumbing = module.exports = function (theme, template, width) {
|
||||
if (!width) {
|
||||
width = 80
|
||||
}
|
||||
validate('OAN', [theme, template, width])
|
||||
this.showing = false
|
||||
this.theme = theme
|
||||
this.width = width
|
||||
this.template = template
|
||||
}
|
||||
Plumbing.prototype = {}
|
||||
|
||||
Plumbing.prototype.setTheme = function (theme) {
|
||||
validate('O', [theme])
|
||||
this.theme = theme
|
||||
}
|
||||
|
||||
Plumbing.prototype.setTemplate = function (template) {
|
||||
validate('A', [template])
|
||||
this.template = template
|
||||
}
|
||||
|
||||
Plumbing.prototype.setWidth = function (width) {
|
||||
validate('N', [width])
|
||||
this.width = width
|
||||
}
|
||||
|
||||
Plumbing.prototype.hide = function () {
|
||||
return consoleControl.gotoSOL() + consoleControl.eraseLine()
|
||||
}
|
||||
|
||||
Plumbing.prototype.hideCursor = consoleControl.hideCursor
|
||||
|
||||
Plumbing.prototype.showCursor = consoleControl.showCursor
|
||||
|
||||
Plumbing.prototype.show = function (status) {
|
||||
var values = Object.create(this.theme)
|
||||
for (var key in status) {
|
||||
values[key] = status[key]
|
||||
}
|
||||
|
||||
return renderTemplate(this.width, this.template, values).trim() +
|
||||
consoleControl.color('reset') +
|
||||
consoleControl.eraseLine() + consoleControl.gotoSOL()
|
||||
}
|
3
node_modules/gauge/lib/process.js
generated
vendored
Normal file
3
node_modules/gauge/lib/process.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
'use strict'
|
||||
// this exists so we can replace it during testing
|
||||
module.exports = process
|
41
node_modules/gauge/lib/progress-bar.js
generated
vendored
Normal file
41
node_modules/gauge/lib/progress-bar.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
'use strict'
|
||||
var validate = require('aproba')
|
||||
var renderTemplate = require('./render-template.js')
|
||||
var wideTruncate = require('./wide-truncate')
|
||||
var stringWidth = require('string-width')
|
||||
|
||||
module.exports = function (theme, width, completed) {
|
||||
validate('ONN', [theme, width, completed])
|
||||
if (completed < 0) {
|
||||
completed = 0
|
||||
}
|
||||
if (completed > 1) {
|
||||
completed = 1
|
||||
}
|
||||
if (width <= 0) {
|
||||
return ''
|
||||
}
|
||||
var sofar = Math.round(width * completed)
|
||||
var rest = width - sofar
|
||||
var template = [
|
||||
{ type: 'complete', value: repeat(theme.complete, sofar), length: sofar },
|
||||
{ type: 'remaining', value: repeat(theme.remaining, rest), length: rest },
|
||||
]
|
||||
return renderTemplate(width, template, theme)
|
||||
}
|
||||
|
||||
// lodash's way of repeating
|
||||
function repeat (string, width) {
|
||||
var result = ''
|
||||
var n = width
|
||||
do {
|
||||
if (n % 2) {
|
||||
result += string
|
||||
}
|
||||
n = Math.floor(n / 2)
|
||||
/* eslint no-self-assign: 0 */
|
||||
string += string
|
||||
} while (n && stringWidth(result) < width)
|
||||
|
||||
return wideTruncate(result, width)
|
||||
}
|
222
node_modules/gauge/lib/render-template.js
generated
vendored
Normal file
222
node_modules/gauge/lib/render-template.js
generated
vendored
Normal file
@@ -0,0 +1,222 @@
|
||||
'use strict'
|
||||
var align = require('wide-align')
|
||||
var validate = require('aproba')
|
||||
var wideTruncate = require('./wide-truncate')
|
||||
var error = require('./error')
|
||||
var TemplateItem = require('./template-item')
|
||||
|
||||
function renderValueWithValues (values) {
|
||||
return function (item) {
|
||||
return renderValue(item, values)
|
||||
}
|
||||
}
|
||||
|
||||
var renderTemplate = module.exports = function (width, template, values) {
|
||||
var items = prepareItems(width, template, values)
|
||||
var rendered = items.map(renderValueWithValues(values)).join('')
|
||||
return align.left(wideTruncate(rendered, width), width)
|
||||
}
|
||||
|
||||
function preType (item) {
|
||||
var cappedTypeName = item.type[0].toUpperCase() + item.type.slice(1)
|
||||
return 'pre' + cappedTypeName
|
||||
}
|
||||
|
||||
function postType (item) {
|
||||
var cappedTypeName = item.type[0].toUpperCase() + item.type.slice(1)
|
||||
return 'post' + cappedTypeName
|
||||
}
|
||||
|
||||
function hasPreOrPost (item, values) {
|
||||
if (!item.type) {
|
||||
return
|
||||
}
|
||||
return values[preType(item)] || values[postType(item)]
|
||||
}
|
||||
|
||||
function generatePreAndPost (baseItem, parentValues) {
|
||||
var item = Object.assign({}, baseItem)
|
||||
var values = Object.create(parentValues)
|
||||
var template = []
|
||||
var pre = preType(item)
|
||||
var post = postType(item)
|
||||
if (values[pre]) {
|
||||
template.push({ value: values[pre] })
|
||||
values[pre] = null
|
||||
}
|
||||
item.minLength = null
|
||||
item.length = null
|
||||
item.maxLength = null
|
||||
template.push(item)
|
||||
values[item.type] = values[item.type]
|
||||
if (values[post]) {
|
||||
template.push({ value: values[post] })
|
||||
values[post] = null
|
||||
}
|
||||
return function ($1, $2, length) {
|
||||
return renderTemplate(length, template, values)
|
||||
}
|
||||
}
|
||||
|
||||
function prepareItems (width, template, values) {
|
||||
function cloneAndObjectify (item, index, arr) {
|
||||
var cloned = new TemplateItem(item, width)
|
||||
var type = cloned.type
|
||||
if (cloned.value == null) {
|
||||
if (!(type in values)) {
|
||||
if (cloned.default == null) {
|
||||
throw new error.MissingTemplateValue(cloned, values)
|
||||
} else {
|
||||
cloned.value = cloned.default
|
||||
}
|
||||
} else {
|
||||
cloned.value = values[type]
|
||||
}
|
||||
}
|
||||
if (cloned.value == null || cloned.value === '') {
|
||||
return null
|
||||
}
|
||||
cloned.index = index
|
||||
cloned.first = index === 0
|
||||
cloned.last = index === arr.length - 1
|
||||
if (hasPreOrPost(cloned, values)) {
|
||||
cloned.value = generatePreAndPost(cloned, values)
|
||||
}
|
||||
return cloned
|
||||
}
|
||||
|
||||
var output = template.map(cloneAndObjectify).filter(function (item) {
|
||||
return item != null
|
||||
})
|
||||
|
||||
var remainingSpace = width
|
||||
var variableCount = output.length
|
||||
|
||||
function consumeSpace (length) {
|
||||
if (length > remainingSpace) {
|
||||
length = remainingSpace
|
||||
}
|
||||
remainingSpace -= length
|
||||
}
|
||||
|
||||
function finishSizing (item, length) {
|
||||
if (item.finished) {
|
||||
throw new error.Internal('Tried to finish template item that was already finished')
|
||||
}
|
||||
if (length === Infinity) {
|
||||
throw new error.Internal('Length of template item cannot be infinity')
|
||||
}
|
||||
if (length != null) {
|
||||
item.length = length
|
||||
}
|
||||
item.minLength = null
|
||||
item.maxLength = null
|
||||
--variableCount
|
||||
item.finished = true
|
||||
if (item.length == null) {
|
||||
item.length = item.getBaseLength()
|
||||
}
|
||||
if (item.length == null) {
|
||||
throw new error.Internal('Finished template items must have a length')
|
||||
}
|
||||
consumeSpace(item.getLength())
|
||||
}
|
||||
|
||||
output.forEach(function (item) {
|
||||
if (!item.kerning) {
|
||||
return
|
||||
}
|
||||
var prevPadRight = item.first ? 0 : output[item.index - 1].padRight
|
||||
if (!item.first && prevPadRight < item.kerning) {
|
||||
item.padLeft = item.kerning - prevPadRight
|
||||
}
|
||||
if (!item.last) {
|
||||
item.padRight = item.kerning
|
||||
}
|
||||
})
|
||||
|
||||
// Finish any that have a fixed (literal or intuited) length
|
||||
output.forEach(function (item) {
|
||||
if (item.getBaseLength() == null) {
|
||||
return
|
||||
}
|
||||
finishSizing(item)
|
||||
})
|
||||
|
||||
var resized = 0
|
||||
var resizing
|
||||
var hunkSize
|
||||
do {
|
||||
resizing = false
|
||||
hunkSize = Math.round(remainingSpace / variableCount)
|
||||
output.forEach(function (item) {
|
||||
if (item.finished) {
|
||||
return
|
||||
}
|
||||
if (!item.maxLength) {
|
||||
return
|
||||
}
|
||||
if (item.getMaxLength() < hunkSize) {
|
||||
finishSizing(item, item.maxLength)
|
||||
resizing = true
|
||||
}
|
||||
})
|
||||
} while (resizing && resized++ < output.length)
|
||||
if (resizing) {
|
||||
throw new error.Internal('Resize loop iterated too many times while determining maxLength')
|
||||
}
|
||||
|
||||
resized = 0
|
||||
do {
|
||||
resizing = false
|
||||
hunkSize = Math.round(remainingSpace / variableCount)
|
||||
output.forEach(function (item) {
|
||||
if (item.finished) {
|
||||
return
|
||||
}
|
||||
if (!item.minLength) {
|
||||
return
|
||||
}
|
||||
if (item.getMinLength() >= hunkSize) {
|
||||
finishSizing(item, item.minLength)
|
||||
resizing = true
|
||||
}
|
||||
})
|
||||
} while (resizing && resized++ < output.length)
|
||||
if (resizing) {
|
||||
throw new error.Internal('Resize loop iterated too many times while determining minLength')
|
||||
}
|
||||
|
||||
hunkSize = Math.round(remainingSpace / variableCount)
|
||||
output.forEach(function (item) {
|
||||
if (item.finished) {
|
||||
return
|
||||
}
|
||||
finishSizing(item, hunkSize)
|
||||
})
|
||||
|
||||
return output
|
||||
}
|
||||
|
||||
function renderFunction (item, values, length) {
|
||||
validate('OON', arguments)
|
||||
if (item.type) {
|
||||
return item.value(values, values[item.type + 'Theme'] || {}, length)
|
||||
} else {
|
||||
return item.value(values, {}, length)
|
||||
}
|
||||
}
|
||||
|
||||
function renderValue (item, values) {
|
||||
var length = item.getBaseLength()
|
||||
var value = typeof item.value === 'function' ? renderFunction(item, values, length) : item.value
|
||||
if (value == null || value === '') {
|
||||
return ''
|
||||
}
|
||||
var alignWith = align[item.align] || align.left
|
||||
var leftPadding = item.padLeft ? align.left('', item.padLeft) : ''
|
||||
var rightPadding = item.padRight ? align.right('', item.padRight) : ''
|
||||
var truncated = wideTruncate(String(value), length)
|
||||
var aligned = alignWith(truncated, length)
|
||||
return leftPadding + aligned + rightPadding
|
||||
}
|
7
node_modules/gauge/lib/set-immediate.js
generated
vendored
Normal file
7
node_modules/gauge/lib/set-immediate.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
'use strict'
|
||||
var process = require('./process')
|
||||
try {
|
||||
module.exports = setImmediate
|
||||
} catch (ex) {
|
||||
module.exports = process.nextTick
|
||||
}
|
3
node_modules/gauge/lib/set-interval.js
generated
vendored
Normal file
3
node_modules/gauge/lib/set-interval.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
'use strict'
|
||||
// this exists so we can replace it during testing
|
||||
module.exports = setInterval
|
5
node_modules/gauge/lib/spin.js
generated
vendored
Normal file
5
node_modules/gauge/lib/spin.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = function spin (spinstr, spun) {
|
||||
return spinstr[spun % spinstr.length]
|
||||
}
|
87
node_modules/gauge/lib/template-item.js
generated
vendored
Normal file
87
node_modules/gauge/lib/template-item.js
generated
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
'use strict'
|
||||
var stringWidth = require('string-width')
|
||||
|
||||
module.exports = TemplateItem
|
||||
|
||||
function isPercent (num) {
|
||||
if (typeof num !== 'string') {
|
||||
return false
|
||||
}
|
||||
return num.slice(-1) === '%'
|
||||
}
|
||||
|
||||
function percent (num) {
|
||||
return Number(num.slice(0, -1)) / 100
|
||||
}
|
||||
|
||||
function TemplateItem (values, outputLength) {
|
||||
this.overallOutputLength = outputLength
|
||||
this.finished = false
|
||||
this.type = null
|
||||
this.value = null
|
||||
this.length = null
|
||||
this.maxLength = null
|
||||
this.minLength = null
|
||||
this.kerning = null
|
||||
this.align = 'left'
|
||||
this.padLeft = 0
|
||||
this.padRight = 0
|
||||
this.index = null
|
||||
this.first = null
|
||||
this.last = null
|
||||
if (typeof values === 'string') {
|
||||
this.value = values
|
||||
} else {
|
||||
for (var prop in values) {
|
||||
this[prop] = values[prop]
|
||||
}
|
||||
}
|
||||
// Realize percents
|
||||
if (isPercent(this.length)) {
|
||||
this.length = Math.round(this.overallOutputLength * percent(this.length))
|
||||
}
|
||||
if (isPercent(this.minLength)) {
|
||||
this.minLength = Math.round(this.overallOutputLength * percent(this.minLength))
|
||||
}
|
||||
if (isPercent(this.maxLength)) {
|
||||
this.maxLength = Math.round(this.overallOutputLength * percent(this.maxLength))
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
TemplateItem.prototype = {}
|
||||
|
||||
TemplateItem.prototype.getBaseLength = function () {
|
||||
var length = this.length
|
||||
if (
|
||||
length == null &&
|
||||
typeof this.value === 'string' &&
|
||||
this.maxLength == null &&
|
||||
this.minLength == null
|
||||
) {
|
||||
length = stringWidth(this.value)
|
||||
}
|
||||
return length
|
||||
}
|
||||
|
||||
TemplateItem.prototype.getLength = function () {
|
||||
var length = this.getBaseLength()
|
||||
if (length == null) {
|
||||
return null
|
||||
}
|
||||
return length + this.padLeft + this.padRight
|
||||
}
|
||||
|
||||
TemplateItem.prototype.getMaxLength = function () {
|
||||
if (this.maxLength == null) {
|
||||
return null
|
||||
}
|
||||
return this.maxLength + this.padLeft + this.padRight
|
||||
}
|
||||
|
||||
TemplateItem.prototype.getMinLength = function () {
|
||||
if (this.minLength == null) {
|
||||
return null
|
||||
}
|
||||
return this.minLength + this.padLeft + this.padRight
|
||||
}
|
122
node_modules/gauge/lib/theme-set.js
generated
vendored
Normal file
122
node_modules/gauge/lib/theme-set.js
generated
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = function () {
|
||||
return ThemeSetProto.newThemeSet()
|
||||
}
|
||||
|
||||
var ThemeSetProto = {}
|
||||
|
||||
ThemeSetProto.baseTheme = require('./base-theme.js')
|
||||
|
||||
ThemeSetProto.newTheme = function (parent, theme) {
|
||||
if (!theme) {
|
||||
theme = parent
|
||||
parent = this.baseTheme
|
||||
}
|
||||
return Object.assign({}, parent, theme)
|
||||
}
|
||||
|
||||
ThemeSetProto.getThemeNames = function () {
|
||||
return Object.keys(this.themes)
|
||||
}
|
||||
|
||||
ThemeSetProto.addTheme = function (name, parent, theme) {
|
||||
this.themes[name] = this.newTheme(parent, theme)
|
||||
}
|
||||
|
||||
ThemeSetProto.addToAllThemes = function (theme) {
|
||||
var themes = this.themes
|
||||
Object.keys(themes).forEach(function (name) {
|
||||
Object.assign(themes[name], theme)
|
||||
})
|
||||
Object.assign(this.baseTheme, theme)
|
||||
}
|
||||
|
||||
ThemeSetProto.getTheme = function (name) {
|
||||
if (!this.themes[name]) {
|
||||
throw this.newMissingThemeError(name)
|
||||
}
|
||||
return this.themes[name]
|
||||
}
|
||||
|
||||
ThemeSetProto.setDefault = function (opts, name) {
|
||||
if (name == null) {
|
||||
name = opts
|
||||
opts = {}
|
||||
}
|
||||
var platform = opts.platform == null ? 'fallback' : opts.platform
|
||||
var hasUnicode = !!opts.hasUnicode
|
||||
var hasColor = !!opts.hasColor
|
||||
if (!this.defaults[platform]) {
|
||||
this.defaults[platform] = { true: {}, false: {} }
|
||||
}
|
||||
this.defaults[platform][hasUnicode][hasColor] = name
|
||||
}
|
||||
|
||||
ThemeSetProto.getDefault = function (opts) {
|
||||
if (!opts) {
|
||||
opts = {}
|
||||
}
|
||||
var platformName = opts.platform || process.platform
|
||||
var platform = this.defaults[platformName] || this.defaults.fallback
|
||||
var hasUnicode = !!opts.hasUnicode
|
||||
var hasColor = !!opts.hasColor
|
||||
if (!platform) {
|
||||
throw this.newMissingDefaultThemeError(platformName, hasUnicode, hasColor)
|
||||
}
|
||||
if (!platform[hasUnicode][hasColor]) {
|
||||
if (hasUnicode && hasColor && platform[!hasUnicode][hasColor]) {
|
||||
hasUnicode = false
|
||||
} else if (hasUnicode && hasColor && platform[hasUnicode][!hasColor]) {
|
||||
hasColor = false
|
||||
} else if (hasUnicode && hasColor && platform[!hasUnicode][!hasColor]) {
|
||||
hasUnicode = false
|
||||
hasColor = false
|
||||
} else if (hasUnicode && !hasColor && platform[!hasUnicode][hasColor]) {
|
||||
hasUnicode = false
|
||||
} else if (!hasUnicode && hasColor && platform[hasUnicode][!hasColor]) {
|
||||
hasColor = false
|
||||
} else if (platform === this.defaults.fallback) {
|
||||
throw this.newMissingDefaultThemeError(platformName, hasUnicode, hasColor)
|
||||
}
|
||||
}
|
||||
if (platform[hasUnicode][hasColor]) {
|
||||
return this.getTheme(platform[hasUnicode][hasColor])
|
||||
} else {
|
||||
return this.getDefault(Object.assign({}, opts, { platform: 'fallback' }))
|
||||
}
|
||||
}
|
||||
|
||||
ThemeSetProto.newMissingThemeError = function newMissingThemeError (name) {
|
||||
var err = new Error('Could not find a gauge theme named "' + name + '"')
|
||||
Error.captureStackTrace.call(err, newMissingThemeError)
|
||||
err.theme = name
|
||||
err.code = 'EMISSINGTHEME'
|
||||
return err
|
||||
}
|
||||
|
||||
ThemeSetProto.newMissingDefaultThemeError =
|
||||
function newMissingDefaultThemeError (platformName, hasUnicode, hasColor) {
|
||||
var err = new Error(
|
||||
'Could not find a gauge theme for your platform/unicode/color use combo:\n' +
|
||||
' platform = ' + platformName + '\n' +
|
||||
' hasUnicode = ' + hasUnicode + '\n' +
|
||||
' hasColor = ' + hasColor)
|
||||
Error.captureStackTrace.call(err, newMissingDefaultThemeError)
|
||||
err.platform = platformName
|
||||
err.hasUnicode = hasUnicode
|
||||
err.hasColor = hasColor
|
||||
err.code = 'EMISSINGTHEME'
|
||||
return err
|
||||
}
|
||||
|
||||
ThemeSetProto.newThemeSet = function () {
|
||||
var themeset = function (opts) {
|
||||
return themeset.getDefault(opts)
|
||||
}
|
||||
return Object.assign(themeset, ThemeSetProto, {
|
||||
themes: Object.assign({}, this.themes),
|
||||
baseTheme: Object.assign({}, this.baseTheme),
|
||||
defaults: JSON.parse(JSON.stringify(this.defaults || {})),
|
||||
})
|
||||
}
|
56
node_modules/gauge/lib/themes.js
generated
vendored
Normal file
56
node_modules/gauge/lib/themes.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
'use strict'
|
||||
var color = require('console-control-strings').color
|
||||
var ThemeSet = require('./theme-set.js')
|
||||
|
||||
var themes = module.exports = new ThemeSet()
|
||||
|
||||
themes.addTheme('ASCII', {
|
||||
preProgressbar: '[',
|
||||
postProgressbar: ']',
|
||||
progressbarTheme: {
|
||||
complete: '#',
|
||||
remaining: '.',
|
||||
},
|
||||
activityIndicatorTheme: '-\\|/',
|
||||
preSubsection: '>',
|
||||
})
|
||||
|
||||
themes.addTheme('colorASCII', themes.getTheme('ASCII'), {
|
||||
progressbarTheme: {
|
||||
preComplete: color('bgBrightWhite', 'brightWhite'),
|
||||
complete: '#',
|
||||
postComplete: color('reset'),
|
||||
preRemaining: color('bgBrightBlack', 'brightBlack'),
|
||||
remaining: '.',
|
||||
postRemaining: color('reset'),
|
||||
},
|
||||
})
|
||||
|
||||
themes.addTheme('brailleSpinner', {
|
||||
preProgressbar: '(',
|
||||
postProgressbar: ')',
|
||||
progressbarTheme: {
|
||||
complete: '#',
|
||||
remaining: '⠂',
|
||||
},
|
||||
activityIndicatorTheme: '⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏',
|
||||
preSubsection: '>',
|
||||
})
|
||||
|
||||
themes.addTheme('colorBrailleSpinner', themes.getTheme('brailleSpinner'), {
|
||||
progressbarTheme: {
|
||||
preComplete: color('bgBrightWhite', 'brightWhite'),
|
||||
complete: '#',
|
||||
postComplete: color('reset'),
|
||||
preRemaining: color('bgBrightBlack', 'brightBlack'),
|
||||
remaining: '⠂',
|
||||
postRemaining: color('reset'),
|
||||
},
|
||||
})
|
||||
|
||||
themes.setDefault({}, 'ASCII')
|
||||
themes.setDefault({ hasColor: true }, 'colorASCII')
|
||||
themes.setDefault({ platform: 'darwin', hasUnicode: true }, 'brailleSpinner')
|
||||
themes.setDefault({ platform: 'darwin', hasUnicode: true, hasColor: true }, 'colorBrailleSpinner')
|
||||
themes.setDefault({ platform: 'linux', hasUnicode: true }, 'brailleSpinner')
|
||||
themes.setDefault({ platform: 'linux', hasUnicode: true, hasColor: true }, 'colorBrailleSpinner')
|
31
node_modules/gauge/lib/wide-truncate.js
generated
vendored
Normal file
31
node_modules/gauge/lib/wide-truncate.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
'use strict'
|
||||
var stringWidth = require('string-width')
|
||||
var stripAnsi = require('strip-ansi')
|
||||
|
||||
module.exports = wideTruncate
|
||||
|
||||
function wideTruncate (str, target) {
|
||||
if (stringWidth(str) === 0) {
|
||||
return str
|
||||
}
|
||||
if (target <= 0) {
|
||||
return ''
|
||||
}
|
||||
if (stringWidth(str) <= target) {
|
||||
return str
|
||||
}
|
||||
|
||||
// We compute the number of bytes of ansi sequences here and add
|
||||
// that to our initial truncation to ensure that we don't slice one
|
||||
// that we want to keep in half.
|
||||
var noAnsi = stripAnsi(str)
|
||||
var ansiSize = str.length + noAnsi.length
|
||||
var truncated = str.slice(0, target + ansiSize)
|
||||
|
||||
// we have to shrink the result to account for our ansi sequence buffer
|
||||
// (if an ansi sequence was truncated) and double width characters.
|
||||
while (stringWidth(truncated) > target) {
|
||||
truncated = truncated.slice(0, -1)
|
||||
}
|
||||
return truncated
|
||||
}
|
17
node_modules/gauge/node_modules/is-fullwidth-code-point/index.d.ts
generated
vendored
Normal file
17
node_modules/gauge/node_modules/is-fullwidth-code-point/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
Check if the character represented by a given [Unicode code point](https://en.wikipedia.org/wiki/Code_point) is [fullwidth](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms).
|
||||
|
||||
@param codePoint - The [code point](https://en.wikipedia.org/wiki/Code_point) of a character.
|
||||
|
||||
@example
|
||||
```
|
||||
import isFullwidthCodePoint from 'is-fullwidth-code-point';
|
||||
|
||||
isFullwidthCodePoint('谢'.codePointAt(0));
|
||||
//=> true
|
||||
|
||||
isFullwidthCodePoint('a'.codePointAt(0));
|
||||
//=> false
|
||||
```
|
||||
*/
|
||||
export default function isFullwidthCodePoint(codePoint: number): boolean;
|
50
node_modules/gauge/node_modules/is-fullwidth-code-point/index.js
generated
vendored
Normal file
50
node_modules/gauge/node_modules/is-fullwidth-code-point/index.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
/* eslint-disable yoda */
|
||||
'use strict';
|
||||
|
||||
const isFullwidthCodePoint = codePoint => {
|
||||
if (Number.isNaN(codePoint)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Code points are derived from:
|
||||
// http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt
|
||||
if (
|
||||
codePoint >= 0x1100 && (
|
||||
codePoint <= 0x115F || // Hangul Jamo
|
||||
codePoint === 0x2329 || // LEFT-POINTING ANGLE BRACKET
|
||||
codePoint === 0x232A || // RIGHT-POINTING ANGLE BRACKET
|
||||
// CJK Radicals Supplement .. Enclosed CJK Letters and Months
|
||||
(0x2E80 <= codePoint && codePoint <= 0x3247 && codePoint !== 0x303F) ||
|
||||
// Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
|
||||
(0x3250 <= codePoint && codePoint <= 0x4DBF) ||
|
||||
// CJK Unified Ideographs .. Yi Radicals
|
||||
(0x4E00 <= codePoint && codePoint <= 0xA4C6) ||
|
||||
// Hangul Jamo Extended-A
|
||||
(0xA960 <= codePoint && codePoint <= 0xA97C) ||
|
||||
// Hangul Syllables
|
||||
(0xAC00 <= codePoint && codePoint <= 0xD7A3) ||
|
||||
// CJK Compatibility Ideographs
|
||||
(0xF900 <= codePoint && codePoint <= 0xFAFF) ||
|
||||
// Vertical Forms
|
||||
(0xFE10 <= codePoint && codePoint <= 0xFE19) ||
|
||||
// CJK Compatibility Forms .. Small Form Variants
|
||||
(0xFE30 <= codePoint && codePoint <= 0xFE6B) ||
|
||||
// Halfwidth and Fullwidth Forms
|
||||
(0xFF01 <= codePoint && codePoint <= 0xFF60) ||
|
||||
(0xFFE0 <= codePoint && codePoint <= 0xFFE6) ||
|
||||
// Kana Supplement
|
||||
(0x1B000 <= codePoint && codePoint <= 0x1B001) ||
|
||||
// Enclosed Ideographic Supplement
|
||||
(0x1F200 <= codePoint && codePoint <= 0x1F251) ||
|
||||
// CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
|
||||
(0x20000 <= codePoint && codePoint <= 0x3FFFD)
|
||||
)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
module.exports = isFullwidthCodePoint;
|
||||
module.exports.default = isFullwidthCodePoint;
|
9
node_modules/gauge/node_modules/is-fullwidth-code-point/license
generated
vendored
Normal file
9
node_modules/gauge/node_modules/is-fullwidth-code-point/license
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
42
node_modules/gauge/node_modules/is-fullwidth-code-point/package.json
generated
vendored
Normal file
42
node_modules/gauge/node_modules/is-fullwidth-code-point/package.json
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "is-fullwidth-code-point",
|
||||
"version": "3.0.0",
|
||||
"description": "Check if the character represented by a given Unicode code point is fullwidth",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/is-fullwidth-code-point",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd-check"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"fullwidth",
|
||||
"full-width",
|
||||
"full",
|
||||
"width",
|
||||
"unicode",
|
||||
"character",
|
||||
"string",
|
||||
"codepoint",
|
||||
"code",
|
||||
"point",
|
||||
"is",
|
||||
"detect",
|
||||
"check"
|
||||
],
|
||||
"devDependencies": {
|
||||
"ava": "^1.3.1",
|
||||
"tsd-check": "^0.5.0",
|
||||
"xo": "^0.24.0"
|
||||
}
|
||||
}
|
39
node_modules/gauge/node_modules/is-fullwidth-code-point/readme.md
generated
vendored
Normal file
39
node_modules/gauge/node_modules/is-fullwidth-code-point/readme.md
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
# is-fullwidth-code-point [](https://travis-ci.org/sindresorhus/is-fullwidth-code-point)
|
||||
|
||||
> Check if the character represented by a given [Unicode code point](https://en.wikipedia.org/wiki/Code_point) is [fullwidth](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms)
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install is-fullwidth-code-point
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const isFullwidthCodePoint = require('is-fullwidth-code-point');
|
||||
|
||||
isFullwidthCodePoint('谢'.codePointAt(0));
|
||||
//=> true
|
||||
|
||||
isFullwidthCodePoint('a'.codePointAt(0));
|
||||
//=> false
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### isFullwidthCodePoint(codePoint)
|
||||
|
||||
#### codePoint
|
||||
|
||||
Type: `number`
|
||||
|
||||
The [code point](https://en.wikipedia.org/wiki/Code_point) of a character.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
29
node_modules/gauge/node_modules/string-width/index.d.ts
generated
vendored
Normal file
29
node_modules/gauge/node_modules/string-width/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
declare const stringWidth: {
|
||||
/**
|
||||
Get the visual width of a string - the number of columns required to display it.
|
||||
|
||||
Some Unicode characters are [fullwidth](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) and use double the normal width. [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) are stripped and doesn't affect the width.
|
||||
|
||||
@example
|
||||
```
|
||||
import stringWidth = require('string-width');
|
||||
|
||||
stringWidth('a');
|
||||
//=> 1
|
||||
|
||||
stringWidth('古');
|
||||
//=> 2
|
||||
|
||||
stringWidth('\u001B[1m古\u001B[22m');
|
||||
//=> 2
|
||||
```
|
||||
*/
|
||||
(string: string): number;
|
||||
|
||||
// TODO: remove this in the next major version, refactor the whole definition to:
|
||||
// declare function stringWidth(string: string): number;
|
||||
// export = stringWidth;
|
||||
default: typeof stringWidth;
|
||||
}
|
||||
|
||||
export = stringWidth;
|
47
node_modules/gauge/node_modules/string-width/index.js
generated
vendored
Normal file
47
node_modules/gauge/node_modules/string-width/index.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
'use strict';
|
||||
const stripAnsi = require('strip-ansi');
|
||||
const isFullwidthCodePoint = require('is-fullwidth-code-point');
|
||||
const emojiRegex = require('emoji-regex');
|
||||
|
||||
const stringWidth = string => {
|
||||
if (typeof string !== 'string' || string.length === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
string = stripAnsi(string);
|
||||
|
||||
if (string.length === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
string = string.replace(emojiRegex(), ' ');
|
||||
|
||||
let width = 0;
|
||||
|
||||
for (let i = 0; i < string.length; i++) {
|
||||
const code = string.codePointAt(i);
|
||||
|
||||
// Ignore control characters
|
||||
if (code <= 0x1F || (code >= 0x7F && code <= 0x9F)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore combining characters
|
||||
if (code >= 0x300 && code <= 0x36F) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Surrogates
|
||||
if (code > 0xFFFF) {
|
||||
i++;
|
||||
}
|
||||
|
||||
width += isFullwidthCodePoint(code) ? 2 : 1;
|
||||
}
|
||||
|
||||
return width;
|
||||
};
|
||||
|
||||
module.exports = stringWidth;
|
||||
// TODO: remove this in the next major version
|
||||
module.exports.default = stringWidth;
|
9
node_modules/gauge/node_modules/string-width/license
generated
vendored
Normal file
9
node_modules/gauge/node_modules/string-width/license
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
56
node_modules/gauge/node_modules/string-width/package.json
generated
vendored
Normal file
56
node_modules/gauge/node_modules/string-width/package.json
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"name": "string-width",
|
||||
"version": "4.2.3",
|
||||
"description": "Get the visual width of a string - the number of columns required to display it",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/string-width",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"string",
|
||||
"character",
|
||||
"unicode",
|
||||
"width",
|
||||
"visual",
|
||||
"column",
|
||||
"columns",
|
||||
"fullwidth",
|
||||
"full-width",
|
||||
"full",
|
||||
"ansi",
|
||||
"escape",
|
||||
"codes",
|
||||
"cli",
|
||||
"command-line",
|
||||
"terminal",
|
||||
"console",
|
||||
"cjk",
|
||||
"chinese",
|
||||
"japanese",
|
||||
"korean",
|
||||
"fixed-width"
|
||||
],
|
||||
"dependencies": {
|
||||
"emoji-regex": "^8.0.0",
|
||||
"is-fullwidth-code-point": "^3.0.0",
|
||||
"strip-ansi": "^6.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^1.4.1",
|
||||
"tsd": "^0.7.1",
|
||||
"xo": "^0.24.0"
|
||||
}
|
||||
}
|
50
node_modules/gauge/node_modules/string-width/readme.md
generated
vendored
Normal file
50
node_modules/gauge/node_modules/string-width/readme.md
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
# string-width
|
||||
|
||||
> Get the visual width of a string - the number of columns required to display it
|
||||
|
||||
Some Unicode characters are [fullwidth](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) and use double the normal width. [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) are stripped and doesn't affect the width.
|
||||
|
||||
Useful to be able to measure the actual width of command-line output.
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install string-width
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const stringWidth = require('string-width');
|
||||
|
||||
stringWidth('a');
|
||||
//=> 1
|
||||
|
||||
stringWidth('古');
|
||||
//=> 2
|
||||
|
||||
stringWidth('\u001B[1m古\u001B[22m');
|
||||
//=> 2
|
||||
```
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [string-width-cli](https://github.com/sindresorhus/string-width-cli) - CLI for this module
|
||||
- [string-length](https://github.com/sindresorhus/string-length) - Get the real length of a string
|
||||
- [widest-line](https://github.com/sindresorhus/widest-line) - Get the visual width of the widest line in a string
|
||||
|
||||
|
||||
---
|
||||
|
||||
<div align="center">
|
||||
<b>
|
||||
<a href="https://tidelift.com/subscription/pkg/npm-string-width?utm_source=npm-string-width&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
||||
</b>
|
||||
<br>
|
||||
<sub>
|
||||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
||||
</sub>
|
||||
</div>
|
14
node_modules/gauge/node_modules/wide-align/LICENSE
generated
vendored
Normal file
14
node_modules/gauge/node_modules/wide-align/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
Copyright (c) 2015, Rebecca Turner <me@re-becca.org>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
47
node_modules/gauge/node_modules/wide-align/README.md
generated
vendored
Normal file
47
node_modules/gauge/node_modules/wide-align/README.md
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
wide-align
|
||||
----------
|
||||
|
||||
A wide-character aware text alignment function for use in terminals / on the
|
||||
console.
|
||||
|
||||
### Usage
|
||||
|
||||
```
|
||||
var align = require('wide-align')
|
||||
|
||||
// Note that if you view this on a unicode console, all of the slashes are
|
||||
// aligned. This is because on a console, all narrow characters are
|
||||
// an en wide and all wide characters are an em. In browsers, this isn't
|
||||
// held to and wide characters like "古" can be less than two narrow
|
||||
// characters even with a fixed width font.
|
||||
|
||||
console.log(align.center('abc', 10)) // ' abc '
|
||||
console.log(align.center('古古古', 10)) // ' 古古古 '
|
||||
console.log(align.left('abc', 10)) // 'abc '
|
||||
console.log(align.left('古古古', 10)) // '古古古 '
|
||||
console.log(align.right('abc', 10)) // ' abc'
|
||||
console.log(align.right('古古古', 10)) // ' 古古古'
|
||||
```
|
||||
|
||||
### Functions
|
||||
|
||||
#### `align.center(str, length)` → `str`
|
||||
|
||||
Returns *str* with spaces added to both sides such that that it is *length*
|
||||
chars long and centered in the spaces.
|
||||
|
||||
#### `align.left(str, length)` → `str`
|
||||
|
||||
Returns *str* with spaces to the right such that it is *length* chars long.
|
||||
|
||||
### `align.right(str, length)` → `str`
|
||||
|
||||
Returns *str* with spaces to the left such that it is *length* chars long.
|
||||
|
||||
### Origins
|
||||
|
||||
These functions were originally taken from
|
||||
[cliui](https://npmjs.com/package/cliui). Changes include switching to the
|
||||
MUCH faster pad generation function from
|
||||
[lodash](https://npmjs.com/package/lodash), making center alignment pad
|
||||
both sides and adding left alignment.
|
65
node_modules/gauge/node_modules/wide-align/align.js
generated
vendored
Normal file
65
node_modules/gauge/node_modules/wide-align/align.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
'use strict'
|
||||
var stringWidth = require('string-width')
|
||||
|
||||
exports.center = alignCenter
|
||||
exports.left = alignLeft
|
||||
exports.right = alignRight
|
||||
|
||||
// lodash's way of generating pad characters.
|
||||
|
||||
function createPadding (width) {
|
||||
var result = ''
|
||||
var string = ' '
|
||||
var n = width
|
||||
do {
|
||||
if (n % 2) {
|
||||
result += string;
|
||||
}
|
||||
n = Math.floor(n / 2);
|
||||
string += string;
|
||||
} while (n);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function alignLeft (str, width) {
|
||||
var trimmed = str.trimRight()
|
||||
if (trimmed.length === 0 && str.length >= width) return str
|
||||
var padding = ''
|
||||
var strWidth = stringWidth(trimmed)
|
||||
|
||||
if (strWidth < width) {
|
||||
padding = createPadding(width - strWidth)
|
||||
}
|
||||
|
||||
return trimmed + padding
|
||||
}
|
||||
|
||||
function alignRight (str, width) {
|
||||
var trimmed = str.trimLeft()
|
||||
if (trimmed.length === 0 && str.length >= width) return str
|
||||
var padding = ''
|
||||
var strWidth = stringWidth(trimmed)
|
||||
|
||||
if (strWidth < width) {
|
||||
padding = createPadding(width - strWidth)
|
||||
}
|
||||
|
||||
return padding + trimmed
|
||||
}
|
||||
|
||||
function alignCenter (str, width) {
|
||||
var trimmed = str.trim()
|
||||
if (trimmed.length === 0 && str.length >= width) return str
|
||||
var padLeft = ''
|
||||
var padRight = ''
|
||||
var strWidth = stringWidth(trimmed)
|
||||
|
||||
if (strWidth < width) {
|
||||
var padLeftBy = parseInt((width - strWidth) / 2, 10)
|
||||
padLeft = createPadding(padLeftBy)
|
||||
padRight = createPadding(width - (strWidth + padLeftBy))
|
||||
}
|
||||
|
||||
return padLeft + trimmed + padRight
|
||||
}
|
33
node_modules/gauge/node_modules/wide-align/package.json
generated
vendored
Normal file
33
node_modules/gauge/node_modules/wide-align/package.json
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "wide-align",
|
||||
"version": "1.1.5",
|
||||
"description": "A wide-character aware text alignment function for use on the console or with fixed width fonts.",
|
||||
"main": "align.js",
|
||||
"scripts": {
|
||||
"test": "tap --coverage test/*.js"
|
||||
},
|
||||
"keywords": [
|
||||
"wide",
|
||||
"double",
|
||||
"unicode",
|
||||
"cjkv",
|
||||
"pad",
|
||||
"align"
|
||||
],
|
||||
"author": "Rebecca Turner <me@re-becca.org> (http://re-becca.org/)",
|
||||
"license": "ISC",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/iarna/wide-align"
|
||||
},
|
||||
"//": "But not version 5 of string-width, as that's ESM only",
|
||||
"dependencies": {
|
||||
"string-width": "^1.0.2 || 2 || 3 || 4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tap": "*"
|
||||
},
|
||||
"files": [
|
||||
"align.js"
|
||||
]
|
||||
}
|
66
node_modules/gauge/package.json
generated
vendored
Normal file
66
node_modules/gauge/package.json
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
{
|
||||
"name": "gauge",
|
||||
"version": "4.0.4",
|
||||
"description": "A terminal based horizontal gauge",
|
||||
"main": "lib",
|
||||
"scripts": {
|
||||
"test": "tap",
|
||||
"lint": "eslint \"**/*.js\"",
|
||||
"postlint": "template-oss-check",
|
||||
"lintfix": "npm run lint -- --fix",
|
||||
"preversion": "npm test",
|
||||
"postversion": "npm publish",
|
||||
"prepublishOnly": "git push origin --follow-tags",
|
||||
"snap": "tap",
|
||||
"posttest": "npm run lint",
|
||||
"template-oss-apply": "template-oss-apply --force"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/npm/gauge.git"
|
||||
},
|
||||
"keywords": [
|
||||
"progressbar",
|
||||
"progress",
|
||||
"gauge"
|
||||
],
|
||||
"author": "GitHub Inc.",
|
||||
"license": "ISC",
|
||||
"bugs": {
|
||||
"url": "https://github.com/npm/gauge/issues"
|
||||
},
|
||||
"homepage": "https://github.com/npm/gauge",
|
||||
"dependencies": {
|
||||
"aproba": "^1.0.3 || ^2.0.0",
|
||||
"color-support": "^1.1.3",
|
||||
"console-control-strings": "^1.1.0",
|
||||
"has-unicode": "^2.0.1",
|
||||
"signal-exit": "^3.0.7",
|
||||
"string-width": "^4.2.3",
|
||||
"strip-ansi": "^6.0.1",
|
||||
"wide-align": "^1.1.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@npmcli/eslint-config": "^3.0.1",
|
||||
"@npmcli/template-oss": "3.2.0",
|
||||
"readable-stream": "^3.6.0",
|
||||
"tap": "^16.0.1"
|
||||
},
|
||||
"files": [
|
||||
"bin/",
|
||||
"lib/"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
|
||||
},
|
||||
"tap": {
|
||||
"branches": 79,
|
||||
"statements": 89,
|
||||
"functions": 92,
|
||||
"lines": 90
|
||||
},
|
||||
"templateOSS": {
|
||||
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
|
||||
"version": "3.2.0"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user