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: add fallback for window width #45

Merged
merged 4 commits into from
Dec 18, 2017
Merged

feat: add fallback for window width #45

merged 4 commits into from
Dec 18, 2017

Conversation

maxrimue
Copy link
Member

This adds a little fallback which returns the window width of the current window when no width is passed using the API.

If this PR gets merged, we could just not pass any width to cliui in yargs instead of requiring the rather expensive window-size.

@bcoe
Copy link
Member

bcoe commented Dec 1, 2016

@maxrimue I'll work on landing this this weekend, managed to lose track of it 👍

Copy link
Member

@bcoe bcoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good, I think it would be worth adding a safety for non-node environments.

@@ -310,7 +310,7 @@ module.exports = function (opts) {
opts = opts || {}

return new UI({
width: (opts || {}).width || 80,
width: (opts || {}).width || process.stdout.columns || 80,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some folks run yargs in the browser, so process/process.stdout might not exist. Let's pull this into a helper method that looks something like this:

function defaultWidth () {
  width = null
  if (process && process.stdout && process.stdout.columns) width = process.stdout.columns
  return width
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bcoe Agree, done

Copy link
Member

@bcoe bcoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one tiny nit, otherwise I approve of this 👍

@@ -282,6 +282,10 @@ function _minWidth (col) {
return minWidth
}

function getWindowWidth () {
if (process && process.stdout && process.stdout.columns) return process.stdout.columns
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super small nit, let's go with typeof process === 'object', rather than just checking if process is truthy. Otherwise, this is looking great.

@bcoe
Copy link
Member

bcoe commented Jan 19, 2017

looks good to me 👍

@bcoe bcoe merged commit d064922 into master Dec 18, 2017
@bcoe bcoe deleted the feat/fallback branch December 18, 2017 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants