Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disable bar support in the absence of a tty #506

Merged
merged 1 commit into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import prettyMs from 'pretty-ms';
import minimatch from 'minimatch';
import filenamify from 'filenamify';
import TimeFormat from 'hh-mm-ss';
import ProgressBar from 'xprogress';
import countryData from 'country-data';
import {publicIp} from 'public-ip';
import {isBinaryFile} from 'isbinaryfile';
import {fileTypeFromFile} from 'file-type';
import {program as commander} from 'commander';
import {decode as entityDecode} from 'html-entities';
import {createFFmpeg, fetchFile} from '@ffmpeg/ffmpeg';
import ProgressBar, {getPersistentStdout} from 'xprogress';

import _merge from 'lodash.merge';
import _mergeWith from 'lodash.mergewith';
Expand Down Expand Up @@ -165,10 +165,11 @@ function prePadNum(val, total, min = 2) {
return `${val}`.padStart(Math.max(`${total}`.length, min), '0');
}

function prepProgressGen(options) {
function prepProgressGen(options, writeStream) {
return (size, slots, opts, indentLen, isFragment) => {
const forceFirst = options.singleBar || slots.length === 1 || slots.length > 20;
return ProgressBar.stream(size, slots, {
writeStream,
forceFirst,
length: 47,
pulsate: options.pulsateBar || !Number.isFinite(size),
Expand Down Expand Up @@ -709,6 +710,9 @@ async function init(packageJson, queries, options) {
(a, b, k) => (k === 'sources' && [a, b].every(Array.isArray) ? Array.from(new Set(b.concat(a))) : undefined),
);

let barWriteStream;
if (options.bar && null === (barWriteStream = getPersistentStdout())) options.bar = false;

if (Config.opts.netCheck && !(await isOnline()))
stackLogger.error('\x1b[31m[!]\x1b[0m Failed To Detect An Internet Connection'), process.exit(4);

Expand Down Expand Up @@ -824,7 +828,7 @@ async function init(packageJson, queries, options) {
}

let progressGen;
if (options.bar) progressGen = prepProgressGen(options);
if (options.bar) progressGen = prepProgressGen(options, barWriteStream);

function downloadToStream({urlOrFragments, outputFile, logger, opts}) {
opts = {
Expand Down
56 changes: 28 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"hh-mm-ss": "^1.2.0",
"html-entities": "^2.3.3",
"isbinaryfile": "^5.0.0",
"libxget": "^0.10.0",
"libxget": "^0.11.0",
"lodash.merge": "^4.6.2",
"lodash.mergewith": "^4.6.2",
"lodash.sortby": "^4.7.0",
Expand All @@ -87,7 +87,7 @@
"stringd-colors": "^1.10.0",
"stripchar": "^1.2.1",
"xbytes": "^1.8.0",
"xprogress": "^0.19.1",
"xprogress": "^0.20.0",
"youtube-dl-exec": "^2.4.0",
"yt-search": "^2.10.3"
},
Expand Down
30 changes: 15 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1585,7 +1585,7 @@ is-wsl@^2.2.0:
isarray@~1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
integrity sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=
integrity sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==

isbinaryfile@^5.0.0:
version "5.0.0"
Expand Down Expand Up @@ -1671,10 +1671,10 @@ levn@^0.4.1:
prelude-ls "^1.2.1"
type-check "~0.4.0"

libxget@^0.10.0:
version "0.10.0"
resolved "https://registry.npmjs.org/libxget/-/libxget-0.10.0.tgz"
integrity sha512-kJv2pYpbmL+pVHdK69GIFj/8kXYUOXj59cUfaIV+jKWkBFug59fEa0zkSU2yADfUWT0W72ZyPj/N5wHY8lJXNA==
libxget@^0.11.0:
version "0.11.0"
resolved "https://registry.npmjs.org/libxget/-/libxget-0.11.0.tgz"
integrity sha512-qWw/N8BwL0wldWMBKzsPHlDBHZ1N/397GBjI6ZaEFg/jhSrIPksjYmJyQgE3SpzixgJNm5jfztY4ql+0/Wm1UA==
dependencies:
axios "^0.26.0"
commander "^6.2.1"
Expand All @@ -1687,7 +1687,7 @@ libxget@^0.10.0:
mime-types "^2.1.28"
stringd-colors "^1.10.0"
xbytes "^1.7.0"
xprogress "^0.19.1"
xprogress "^0.20.0"
xresilient "^0.8.2"

linkedlist@^1.0.1:
Expand Down Expand Up @@ -2126,7 +2126,7 @@ process-nextick-args@~2.0.0:
progress-stream@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/progress-stream/-/progress-stream-2.0.0.tgz"
integrity sha1-+sY6Cz0R3qy7CWmrzJOyFLzhntU=
integrity sha512-xJwOWR46jcXUq6EH9yYyqp+I52skPySOeHfkxOZ2IY1AiBi/sFJhbhAKHoV3OTw/omQ45KTio9215dRJ2Yxd3Q==
dependencies:
speedometer "~1.0.0"
through2 "~2.0.3"
Expand Down Expand Up @@ -2201,9 +2201,9 @@ readable-stream@^3.6.0:
util-deprecate "^1.0.1"

readable-stream@~2.3.6:
version "2.3.7"
resolved "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz"
integrity sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==
version "2.3.8"
resolved "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz"
integrity sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==
dependencies:
core-util-is "~1.0.0"
inherits "~2.0.3"
Expand Down Expand Up @@ -2414,7 +2414,7 @@ speedometer@^1.1.0:
speedometer@~1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/speedometer/-/speedometer-1.0.0.tgz"
integrity sha1-zWccsGdSwivKM3Di8zREC+T8YuI=
integrity sha512-lgxErLl/7A5+vgIIXsh9MbeukOaCb2axgQ+bKCdIE+ibNT4XNYGNCR1qFEGq6F+YDASXK3Fh/c5FgtZchFolxw==

spotify-uri@^3.0.2:
version "3.0.3"
Expand Down Expand Up @@ -2734,10 +2734,10 @@ xbytes@^1.6.1, xbytes@^1.7.0, xbytes@^1.8.0:
resolved "https://registry.npmjs.org/xbytes/-/xbytes-1.8.0.tgz"
integrity sha512-o/8qiLr54dYJaX/OB47vvb6cfkqFCdoXXhQdzPc8pF7ulsBGOHRTjgFqVceaw+EcjX1fskToTdFHAUhoeZB6xg==

xprogress@^0.19.1:
version "0.19.1"
resolved "https://registry.npmjs.org/xprogress/-/xprogress-0.19.1.tgz"
integrity sha512-wW+6UIZoC/od7ErcgbVvz1XSASc6R7h/XBSUf6DLHAnJMhgDv7QP7NgXzPIcsUg2RmWZKylN5wyWnSRxqezFTA==
xprogress@^0.20.0:
version "0.20.0"
resolved "https://registry.npmjs.org/xprogress/-/xprogress-0.20.0.tgz"
integrity sha512-maZcSG60gayzUvQCiloytWTBc5IN0Yl7MZBoKl9lbigCHCr85FHYHdDHKa9ngPGdro13ZGc7Gyn9DDdhwby+/A==
dependencies:
lodash.merge "^4.6.2"
pad-ratio "^2.0.0"
Expand Down