Skip to content

Commit

Permalink
Improve messages
Browse files Browse the repository at this point in the history
  • Loading branch information
dieghernan committed Jan 21, 2024
1 parent 086f702 commit 083830a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
16 changes: 9 additions & 7 deletions R/resmush_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
#' tmp_jpg <- tempfile(fileext = ".jpg")
#'
#' # Silently returns a data frame
#' resmush_file(jpg_file, outfile = tmp_png, verbose = TRUE)
#' resmush_file(jpg_file, outfile = tmp_png, verbose = TRUE, qlty = 10)
#' resmush_file(jpg_file, outfile = tmp_jpg, verbose = TRUE)
#' resmush_file(jpg_file, outfile = tmp_jpg, verbose = TRUE, qlty = 10)
#' }
resmush_file <- function(file, outfile = file, qlty = 92, verbose = FALSE) {
# Master table with results
Expand Down Expand Up @@ -139,16 +139,18 @@ resmush_file <- function(file, outfile = file, qlty = 92, verbose = FALSE) {

res$dest_size <- out_size_pretty
# Reduction ratio
red_ratio <- as.integer(out_size) / as.integer(src_size)
red_ratio <- 1 - as.integer(out_size) / as.integer(src_size)
res$compress_ratio <- sprintf("%0.1f%%", red_ratio * 100)
res$notes <- "OK ;)"

if (verbose) {
cli::cli_alert_success(paste0(
"{.file {file}} optimized: {res$src_size}",
" => {res$dest_size} ({res$compress_ratio})"
cli::cli_alert_success("Optimizing {.file {file}}:")

cli::cli_bullets(c(
"i" = "Effective compression ratio: {res$compress_ratio}",
"i" = "Current size: {res$dest_size} (was {res$src_size})",
"i" = "Output: {.file {outfile}}"
))
cli::cli_alert_info("Check output: {.file {outfile}}")
}
return(invisible(res))
}
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
},
"SystemRequirements": null
},
"fileSize": "444.818KB",
"fileSize": "444.88KB",
"releaseNotes": "https://github.com/dieghernan/resmush/blob/master/NEWS.md",
"readme": "https://github.com/dieghernan/resmush/blob/main/README.md",
"contIntegration": ["https://github.com/dieghernan/resmush/actions/workflows/check-full.yaml", "https://app.codecov.io/gh/dieghernan/resmush"],
Expand Down
4 changes: 2 additions & 2 deletions man/resmush_file.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/test-resmush_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ test_that("Test opts with png", {
outf,
verbose = TRUE
),
"optimized:"
"Optimizing"
)

expect_true(file.exists(outf))
Expand Down Expand Up @@ -151,7 +151,7 @@ test_that("Test qlty par with jpg", {
outf,
verbose = TRUE
),
"optimized:"
"Optimizing"
)

expect_true(file.exists(outf))
Expand Down

0 comments on commit 083830a

Please sign in to comment.