Skip to content

Commit

Permalink
Move loading of C library to .onAttach()
Browse files Browse the repository at this point in the history
  • Loading branch information
jalvesaq committed Feb 17, 2024
1 parent 5e1cce6 commit 1080187
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions R/colorout.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@


.onLoad <- function(libname, pkgname) {
library.dynam("colorout", pkgname, libname, local = FALSE);

if(is.null(getOption("colorout.anyterm")))
options(colorout.anyterm = FALSE)
if(is.null(getOption("colorout.dumb")))
Expand All @@ -22,12 +20,17 @@
options(colorout.notatty = FALSE)
if(is.null(getOption("colorout.verbose")))
options(colorout.verbose = 0)
return(invisible(NULL))
}

.onAttach <- function(libname, pkgname) {
msg <- testTermForColorOut()
if(msg == "OK")
if (msg == "OK") {
library.dynam("colorout", pkgname, libname, local = FALSE);
ColorOut()
else if(getOption("colorout.verbose") > 0){
msg <- paste(gettext("The R output will not be colorized because it seems that your terminal does not support ANSI escape codes.", domain = "R-colorout"),
} else if(getOption("colorout.verbose") > 0){
msg <- paste(gettext("The R output will not be colorized because it seems that your terminal does not support ANSI escape codes.",
domain = "R-colorout"),
msg)
warning(msg, call. = FALSE, immediate. = TRUE)
}
Expand Down Expand Up @@ -81,7 +84,10 @@ noColorOut <- function()

isColorOut <- function()
{
.Call("colorout_is_enabled", PACKAGE = "colorout")
is_it <- try(.Call("colorout_is_enabled", PACKAGE = "colorout"), silent = TRUE)
if (class(is_it)[1] == "try-error")

This comment has been minimized.

Copy link
@joshuaulrich

joshuaulrich Feb 24, 2024

Contributor

It's best practice to use if (inherits(is_it, "try-error")) here.

This comment has been minimized.

Copy link
@jalvesaq

jalvesaq Feb 25, 2024

Author Owner

Thanks! I will fix it,

return(FALSE)
return(is_it)
}

GetColorCode <- function(x, name)
Expand Down

0 comments on commit 1080187

Please sign in to comment.