Created
July 19, 2022 08:54
-
-
Save romainfrancois/2bb1980ae39dcf34f683cf5b9d640784 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# original issue: https://github.com/rstudio/rstudio/issues/1941 | |
library(purrr) | |
library(cli) | |
library(dplyr) | |
# test -------------------------------------------------------------------- | |
paint <- function(txt, palette) { | |
colors <- palette(nchar(txt), alpha = 1) | |
txt <- paste( | |
map2_chr(strsplit(txt, "")[[1]], colors, ~cli::make_ansi_style(.y)(.x)), | |
collapse = "" | |
) | |
txt | |
} | |
hyperlink_demo <- function() { | |
cats <- sample(filter(emo::jis, subgroup == "cat-face")$emoji, 20, replace = TRUE) | |
writeLines( | |
'Mine, says the cat, putting out his paw of darkness. | |
My lover, my friend, my slave, my toy, says | |
the cat making on your chest his gesture of drawing | |
milk from his mother’s forgotten breasts. | |
Let us walk in the woods, says the cat. | |
I’ll teach you to read the tabloid of scents, | |
to fade into shadow, wait like a trap, to hunt. | |
Now I lay this plump warm mouse on your mat. | |
You feed me, I try to feed you, we are friends, | |
says the cat, although I am more equal than you. | |
Can you leap twenty times the height of your body? | |
Can you run up and down trees? Jump between roofs? | |
Let us rub our bodies together and talk of touch. | |
My emotions are pure as salt crystals and as hard. | |
My lusts glow like my eyes. I sing to you in the mornings | |
walking round and round your bed and into your face. | |
Come I will teach you to dance as naturally | |
as falling asleep and waking and stretching long, long. | |
I speak greed with my paws and fear with my whiskers. | |
Envy lashes my tail. Love speaks me entire, a word | |
of fur. I will teach you to be still as an egg | |
and to slip like the ghost of wind through the grass. | |
', "cat_song") | |
cat_song <- paste0("file://", file.path(getwd(), "cat_song")) | |
txt <- paste0( | |
paint(cli::rule(line = "bar8"), rainbow), "\n", | |
paint(cli::rule(center = "Welcome to the hyperlink party", line = "bar8"), rainbow), "\n", | |
paint(cli::rule(center = paste(cats, collapse = ""), line = " "), rainbow), "\n", | |
paint(cli::rule(line = "bar8"), rainbow), | |
"\n\n- ", | |
cli::style_hyperlink("learn more about cats", "https://en.wikipedia.org/wiki/List_of_cat_breeds"), | |
"\n- a file with a ", | |
cli::style_hyperlink("cat song", cat_song), | |
" ... ", | |
cli::style_hyperlink("(or go to a specific line)", cat_song, c(line = 6)), | |
"\n- help for ", | |
cli::style_hyperlink("?cat", "ide:help:base::cat"), | |
"\n- vignettes: ", | |
cli::style_hyperlink("purrr", "ide:vignette", c(package = "purrr", topic = "other-langs")), | |
", ", | |
cli::style_hyperlink("dplyr", "ide:vignette:dplyr::dplyr"), | |
"\n- code to ", | |
cli::style_hyperlink("run", "ide:run:rlang::last_error()"), | |
" or ", | |
cli::style_hyperlink("copy", "ide:run:sessioninfo::session_info()"), | |
"\n\n", | |
paint(cli::rule(line = "bar8"), rainbow) | |
) | |
cat(txt) | |
} | |
hyperlink_demo() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment