Skip to content

Conversation

@schneems
Copy link
Collaborator

In #91 the behavior of dead_end is now optimized to output values based on if the io object is a TTY (interactive terminal) or not.

This behavior is awesome. The way we were checking default values though introduces a subtle bug, in Ruby nil and false are usually assumed to have the same/similar behavior (being falsey). This updates the logic to use a Object.new value to indicate a default value rather than rely on specific contents. It will reduce the chance the programmer accidentally passes in a value that triggers the default behavior.

I also REALLY wanted to find a way to assert the inverse of the test added in "passing --terminal will force color codes" but it turns out it's really hard (if not impossible). I asked on twitter as well https://twitter.com/schneems/status/1452814816456945672.

Instead I added some unit tests to at least assert that calling DisplayInvalidBlocks with default args defaulted to io.isatty.

I also got rid of the describe block for now as there's only one thing in there. It makes diffs a bit more muddled if the contents of the tests get moved around. (Personal preference)

In #91 the behavior of dead_end is now optimized to output values based on if the io object is a TTY (interactive terminal) or not.

This behavior is awesome. The way we were checking default values though introduces a subtle bug, in Ruby `nil` and `false` are usually assumed to have the same/similar behavior (being falsey). This updates the logic to use a `Object.new` value to indicate a default value rather than rely on specific contents. It will reduce the chance the programmer accidentally passes in a value that triggers the default behavior.

I also REALLY wanted to find a way to assert the inverse of the test added in "passing --terminal will force color codes" but it turns out it's really hard (if not impossible). I asked on twitter as well https://twitter.com/schneems/status/1452814816456945672.

Instead I added some unit tests to at least assert that calling DisplayInvalidBlocks with default args defaulted to `io.isatty`.

I also got rid of the describe block for now as there's only one thing in there. It makes diffs a bit more muddled if the contents of the tests get moved around. (Personal preference)
@schneems schneems force-pushed the schneems/terminal-tty-too branch from 903018d to 8327c6b Compare October 26, 2021 02:21
@schneems schneems marked this pull request as ready for review October 26, 2021 02:21
Copy link
Contributor

@stoivo stoivo left a comment

Choose a reason for hiding this comment

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

👍

end
end

describe "terminal coloring" do
Copy link
Contributor

Choose a reason for hiding this comment

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

I tried to write some specs here for testing tty, but came to the same conclusion as you did. It's hard.

module DeadEnd
# Used to indicate a default value that cannot
# be confused with another input
DEFAULT_VALUE = Object.new.freeze
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably a good idea. I was thinking of merging the IO object and terminal into one argument, but didn't since I wasn't sure it is a good idea. Using nil/false/true might be a bit fragile.

@schneems schneems merged commit e770a4b into main Oct 26, 2021
@schneems schneems deleted the schneems/terminal-tty-too branch October 26, 2021 13:36
@schneems
Copy link
Collaborator Author

Thanks for the review and the initial PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants