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

Refactor Colorize::Mode enum #11663

Merged

Conversation

straight-shoota
Copy link
Member

Extracted from #7690

This is mostly an internal refactoring. Only effect on the API is that invalid symbols are now a compile time error instead of runtime error. That could be considered a breaking change, but it's an improvement for error detection.

Co-Authored-By: r00ster91 <r00ster91@protonmail.com>
src/colorize.cr Outdated Show resolved Hide resolved
src/colorize.cr Outdated Show resolved Hide resolved
straight-shoota and others added 3 commits December 28, 2021 15:03
Co-authored-by: Sijawusz Pur Rahnama <sija@sija.pl>
src/colorize.cr Outdated Show resolved Hide resolved
src/colorize.cr Outdated Show resolved Hide resolved
straight-shoota and others added 2 commits December 29, 2021 15:25
Co-authored-by: Caspian Baska <email@caspian.computer>
src/colorize.cr Outdated Show resolved Hide resolved
src/colorize.cr Outdated Show resolved Hide resolved
@straight-shoota straight-shoota added this to the 1.4.0 milestone Dec 30, 2021
end

private def each_code(mode : Colorize::Mode)
yield '1' if mode.bold?
Copy link
Contributor

Choose a reason for hiding this comment

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

I know the result would be the same, but for readability I wish it was explicitly covering all enum members.

yield '1' if mode.bold? || mode.bright?

Maybe compiler could be (is) smart enough to make it noop, but humans would see all cases covered.
Or maybe just comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think the compiler can easily optimize this.

I'll add a comment to the member definition. That's probably more useful than here in this internal implementation.

@straight-shoota straight-shoota merged commit d2d815c into crystal-lang:master Jan 22, 2022
@straight-shoota straight-shoota deleted the refactor/colorize-mode branch January 22, 2022 14:58
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.

6 participants