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

Change process.stdout.cursorTo to readline.cursorTo #2

Merged
merged 2 commits into from
Feb 15, 2018
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
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function parseName(nameVersion) {
* @param {string[]} args
* @return {string[]} prompt choices
*/
function getChoises(command, args) {
function getChoices(command, args) {
return [
`Install (${colors.bold(`${command} ${args.join(' ')}`)})`,
`Impact`,
Expand All @@ -61,7 +61,7 @@ function getChoises(command, args) {
*/
function promptNextAction(name, versionLoose, packages) {
return getInstallCommand().then(({ command, args }) => {
const choices = getChoises(command, args);
const choices = getChoices(command, args);
return inquirer.prompt({
type: `list`,
name: `next`,
Expand Down
9 changes: 5 additions & 4 deletions lib/getPackageDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const getLicenseStr = require('./getLicenseStr');
const getLicenseType = require('./getLicenseType');
const url = require('url');
const colors = require('colors/safe');
const readline = require('readline');

const packageDetailsCache = {};
const registryUrl = `https://registry.npmjs.org/`;
Expand Down Expand Up @@ -58,8 +59,8 @@ module.exports = function getPackageDetails(
) {
const versionUrlObj = url.parse(versionLoose);
if (versionUrlObj.protocol) {
process.stdout.cursorTo(0);
process.stdout.clearLine(1);
readline.cursorTo(process.stdout, 0);
readline.clearLine(process.stdout, 1);
console.error(
colors.red(`${
versionUrlObj.protocol.replace(':', '')
Expand All @@ -71,8 +72,8 @@ module.exports = function getPackageDetails(
const key = `${name}@${versionLoose}`;
const infoUrl = `${registryUrl}${name.replace(`/`, `%2f`)}`;
if (!packageDetailsCache[key]) {
process.stdout.cursorTo(0);
process.stdout.clearLine(1);
readline.cursorTo(process.stdout, 0);
readline.clearLine(process.stdout, 1);
process.stdout.write(`GET ${infoUrl}`);
packageDetailsCache[key] = fetch(infoUrl).then(checkResponse).then((packageInfo) => {
let version;
Expand Down
5 changes: 3 additions & 2 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const formatLicenseType = require('./formatLicenseType');
const filesize = require('filesize');
const getSimpleTable = require('./getSimpleTable');
const program = require('commander');
const readline = require('readline');

/**
* indicates if any limits of test config are not satisfied
Expand Down Expand Up @@ -121,8 +122,8 @@ function showPackageStats(
}, packages
) {
const { count, size, licenseTypes } = getPackagesStats(packages);
process.stdout.clearLine();
process.stdout.cursorTo(0);
readline.cursorTo(process.stdout, 0);
readline.clearLine(process.stdout);
const table = getSimpleTable();
table.push(
['Packages', count, '', getLimitResult(
Expand Down
7 changes: 5 additions & 2 deletions lib/showImpact.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const walkDependencies = require('./walkDependencies');
const getPackagesStats = require('./getPackagesStats');
const filesize = require('filesize');
const getSimpleTable = require('./getSimpleTable');
const readline = require('readline');

/**
* @param {Object} impactLicenses license -> count
Expand Down Expand Up @@ -85,8 +86,10 @@ module.exports = function showImpact(
impactPackagesStats.licenses,
currentPackagesStats.licenses
);
process.stdout.clearLine();
process.stdout.cursorTo(0);

readline.cursorTo(process.stdout, 0);
readline.clearLine(process.stdout);

const table = getSimpleTable();
table.push([
'Packages',
Expand Down
5 changes: 3 additions & 2 deletions lib/showQuickStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ const getPackagesStats = require('./getPackagesStats');
const formatLicenseType = require('./formatLicenseType');
const filesize = require('filesize');
const getSimpleTable = require('./getSimpleTable');
const readline = require('readline');

/**
* @param {Object} packages
*/
module.exports = function showQuickStats(packages) {
const { count, size, licenseTypes } = getPackagesStats(packages);
process.stdout.clearLine();
process.stdout.cursorTo(0);
readline.cursorTo(process.stdout, 0);
readline.clearLine(process.stdout);
const table = getSimpleTable();
table.push(
['Packages', count, ''],
Expand Down