-
Notifications
You must be signed in to change notification settings - Fork 47
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
Color messages #59
Color messages #59
Conversation
Oh and rainbow! I was trying to think of how to offer that as an option by splitting the text into 6 chunks and giving them red, orange, yellow, etc. -- maybe there's an easy way without |
thanks @aedobbyn !! some comments coming |
R/say.r
Outdated
|
||
switch(type, | ||
message = message(sprintf(who, what)), | ||
message = message(cat(color(sprintf(who, what)))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, does crayon still work if we don't use cat()
here? idea with message()
is that a user can still suppress a message with supressMessages()
- but that doesn't work if there's a cat()
inside message()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually yes it does! Good point, I'll remove the cat
README.Rmd
Outdated
@@ -1,3 +1,7 @@ | |||
--- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you remove this output yaml block, can just use knitr::knit("README.Rmd")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no problem -- I was having some trouble knitting it without that block but seems to be fine now if the keyboard shortcut isn't used
did you try yet? does it work or not work?
you mean for the quote bubble thing and they animal/thing?
right, i think that error is probably good enough |
It does work for warnings now that the As for strings, it attaches the color encoding to the string, like
which I guess could be helpful.
Yeah, exactly. So arguments would be like |
Looks good on the warning and string output. For failure behavior, how about adding an assertion that say(color = 5)
#> Error in crayon::make_style(color) :
#> is.character(style) && length(style) == 1 || is_rgb_matrix(style) && .... is not TRUE which isn't especially useful.
right. not sure how to change that. if you have any ideas go for it. Let's try |
Okay so the two color thing is a bit more complicated 😊 I know pretty much nothing about how coloring strings works this but it looks like the code at the beginning of a string applies to the rest of the string until it hits an escape sequence. If you run For instance,
That as a string is
If you What we want is the It looks like we can resume the So putting
I'd need to look more into what |
Oh and I like the idea of checking if color is character! I'll push that in a sec. |
Alright it's maybe a bit hacky, but two colors should work now. If any animals/things are added that don't follow the usual pattern we might want to go to I'm not totally sure why the string matching test is failing on Travis. Passes for me locally ¯\(ツ)/¯ |
Complicated indeed. No, I don't know much at all about coloring text. I"ll have a look at the two colors |
@@ -9,6 +9,21 @@ test_that("say types works as expected", { | |||
|
|||
# expect string on type=string | |||
expect_is(say(type = "string"), "character") | |||
|
|||
expect_equal( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this instead:
expect_equal(
length(suppressMessages(say("foo", by_color = "cyan"))) + 1,
length(suppressWarnings(say("foo", type = "warning")))
)
so that we don't get the stuff printed out in the test run
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh for sure. This test isn't even totally necessary so I'd be fine with scrapping it if you'd prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure on the failing test, but a suggested fix for another test
i'm guessing that the various parentheses and such need to be escaped? |
R/endless_horse.R
Outdated
endless_horse <- function(what="Hello world!", endless = TRUE, wait = 0.5, | ||
what_color = NULL, horse_color = NULL) { | ||
|
||
if (!is.null(what_color) & !is.character(what_color)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could pull all this stuff out into a util function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this stuff?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah all the checks since they're now used in endless_horse
and say
. It's not a ton of repetition so probably fine to leave it as is, imo
I thought it was because I merged the skipping on windows changes from dev into master. I rolled back dev now so master checks for |
yeah I truly have no idea why maybe something changed on the Appveyor side? anyway, looks like everything's working as it should |
completely unrelatedly 😆 what do you think about allowing the hypnotoad to say other things besides the only thing it can say now? so instead of
we could do something like this
or maybe I'm not hip enough to the memes and that's against the whole idea of the hypnotoad? |
I've no problem with hypnotoad saying other things, though should open a new issue/PR for that. maybe should check with @richfitz since he added it |
before we merge - any thoughts on when you'd be able to get multicolor to cran? cause we'd need it up there before we submit a new ver of this to cran :) |
ah good point. the only thing that I can see that would prevent totally, will open a new PR for the hypnotoad if @richfitz is on board |
I guess in theory that could be possible - not really sure why I wired it up li-ALL GLORY TO THE HYPNOTOAD |
the dankest of memes... |
thanks @aedobbyn i think we should wait to see what gabor says |
sounds good! |
another option @jimhester suggested was to use
and
this way we wouldn't need to wait for a new |
implemented this on multicolor's dev branch, and when that version is installed cowsay passes a check with 0 notes |
cool, sounds good about Jim's idea. Hadn't tried that before. So it doesn't throw any warnings or notes on r check? |
nope! 0 errors | 0 warnings | 0 notes |
looks like there's a conflict in |
oops yeah, was from the hypnotoad test addition |
So are we good to go then do you think? |
|
ok. before we send a new version of this to cran we will need |
thanks for all your work on this! LGTM |
no thank you! I'll try and get |
Love this package.
Not sure whether coloring messages is something you'd be interested in adding, but if so, here's a small PR. I left warnings and strings as they are, so this only applies to
type="message"
. The default color for messages remains whatever the user's default is.This doesn't currently take advantage of everything
crayon
offers, like allowing users to specify background colors or nest styles. Could be cool to incorporate that, or let users choose different colors for thewho
and thewhat
.We could also add more error handling for bad colors, though the current error is decently informative: