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

Default console width when api is unavailable #38

Conversation

adfoster-r7
Copy link
Contributor

Alternative implementation to #34

@adfoster-r7 adfoster-r7 force-pushed the default-console-width-when-api-unavailable branch from 58372c6 to 0e1313c Compare January 18, 2021 19:46
@@ -70,8 +71,7 @@ def initialize(opts = {})
# updated below if we got a "Rows" option
self.rows = []

# TODO: Discuss a cleaner way to handle this information
self.width = opts['Width'] || ::IO.console.winsize[1]
self.width = opts['Width'] || ::IO.console&.winsize&.[](1) || ::BigDecimal::INFINITY
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Safe navigation of arrays has quirky syntax IMO. I believe if console is defined, winsize should be a valid array:

Suggested change
self.width = opts['Width'] || ::IO.console&.winsize&.[](1) || ::BigDecimal::INFINITY
self.width = opts['Width'] || ::IO.console&.winsize[1] || ::BigDecimal::INFINITY

However - I'll err on the side of caution though, in case there's cross-platform differences.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checking the code it doesn't seem like this scenario should arise, but i'm not strongly opinionated

https://github.com/ruby/ruby/blob/83e62d77981adeb2968a49c3176a7a940c8ee29e/ext/io/console/console.c#L780-L799

@zeroSteiner
Copy link
Contributor

Confirmed that this fixes my original issue. Thanks!

@adfoster-r7 adfoster-r7 force-pushed the default-console-width-when-api-unavailable branch from 0e1313c to b6c799e Compare January 19, 2021 22:06
@adfoster-r7 adfoster-r7 force-pushed the default-console-width-when-api-unavailable branch from b6c799e to 17f6728 Compare January 19, 2021 22:08
@@ -42,31 +42,32 @@ def with_whitespace_highlighted(string)

describe Rex::Text::Table do
let(:formatter) do
Formatter = Class.new do
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just fixing these whilst I'm here, this was creating constant warnings

@jmartin-tech jmartin-tech merged commit 35805c8 into rapid7:master Jan 19, 2021
@adfoster-r7 adfoster-r7 deleted the default-console-width-when-api-unavailable branch January 19, 2021 23: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.

None yet

3 participants