Add functions to style text (colors, weight, etc)#140
Add functions to style text (colors, weight, etc)#140gustavothecoder wants to merge 4 commits intodry-rb:mainfrom
Conversation
|
Maybe this API is a better idea because it looks more like Ruby: stylize("Hi!").red.on_white.boldIn this case, |
First of all, thanks for doing this! When I first read this PR, I also thought of this API :) Want to go for it? Also, can you extract some constants like |
Yeah, I'll let you know when I'm done refactoring. |
c5934e3 to
ad75bc1
Compare
|
Hey @cllns, I'm done refactoring and I think that the solution is better now, what you think? |
cllns
left a comment
There was a problem hiding this comment.
Thanks for that refactoring! In reviewing it, I found a few more we can do as well
ad75bc1 to
d8f3907
Compare
Thanks for the feedback! Can you review it again, please? |
|
Sweet, thanks! Can you try to use recursion instead of mutation? In dry-rb, we prefer to leverage immutability, as we find it easier to reason about. To spell it out, calling The Does that make sense? |
3d59bc2 to
ed66def
Compare
It does, the code is simpler now: def chainable_update!(style, new_text)
StyledText.new(
select_graphic_rendition(style) + new_text,
select_graphic_rendition(RESET)
)
end |
- Changed the API to `stylize("string").bold.blue.on_white`
- Moved magic numbers to constants
- Improve code reuse and legibility
- Change `StyledText` to be immutable
ed66def to
179527e
Compare
|
@cllns do you think we can proceed with this? |

Inspired by the issue #121, I added a module with functions to change text style. The doc
docsite/source/styling-your-output.html.mddemonstrate how it works. I used thethorimplementation as a basis, but I changed the API to make combinations shorter:Resolve #121