Use logging colors and start with green

Change-Id: I98178fd80c782895615f81e61f97119b86a821fa
diff --git a/R/KorAPCorpusStats.R b/R/KorAPCorpusStats.R
index 575be8a..820a248 100644
--- a/R/KorAPCorpusStats.R
+++ b/R/KorAPCorpusStats.R
@@ -15,7 +15,9 @@
 setClass("KorAPCorpusStats", slots=c(vc="character", documents="numeric", tokens="numeric", sentences="numeric", paragraphs="numeric", webUIRequestUrl="character" ))
 
 log_info <- function(v,  ...) {
-  cat(ifelse(v, paste0(...), ""))
+  green <- "\033[32m"
+  reset <- "\033[0m"
+  cat(ifelse(v, paste0(green, ..., reset), ""))
 }
 setGeneric("corpusStats", function(kco, ...)  standardGeneric("corpusStats") )
 
diff --git a/R/KorAPQuery.R b/R/KorAPQuery.R
index 60f0729..ad634a9 100644
--- a/R/KorAPQuery.R
+++ b/R/KorAPQuery.R
@@ -201,11 +201,10 @@
         paste(fields, collapse = ","),
         if (metadataOnly) '&access-rewrite-disabled=true' else ''
       )
-      log_info(verbose, "Searching \"", query, "\" in \"", vc, "\"", sep =
+      log_info(verbose, "\rSearching \"", query, "\" in \"", vc, "\"", sep =
                  "")
       res = apiCall(kco, paste0(requestUrl, '&count=0'))
       if (is.null(res)) {
-        log_info(verbose, " [failed]\n")
         message("API call failed.")
         totalResults <- 0
       } else {
@@ -214,7 +213,10 @@
         if(!is.null(res$meta$cached))
           log_info(verbose, " [cached]\n")
         else
-          log_info(verbose, ", took ", res$meta$benchmark, "\n", sep = "")
+          if(! is.null(res$meta$benchmark))
+            log_info(verbose, ", took ", res$meta$benchmark, "\n", sep = "")
+          else
+            log_info(verbose, "\n")
       }
       if (as.df)
         data.frame(
@@ -313,7 +315,7 @@
     }
 
     if ("fields" %in% colnames(res$matches) && (is.na(use_korap_api) || as.numeric(use_korap_api) >= 1.0)) {
-      if (verbose) cat("Using fields API: ")
+      log_info(verbose, "Using fields API: ")
       currentMatches <- res$matches$fields %>%
         purrr::map(~ mutate(.x, value = repair_data_strcuture(value))) %>%
         tibble::enframe() %>%
@@ -349,8 +351,7 @@
     } else {
       collectedMatches <- bind_rows(collectedMatches, currentMatches)
     }
-    if (verbose) {
-      cat(paste0(
+      log_info(verbose, paste0(
         "Retrieved page ",
         ceiling(nrow(collectedMatches) / res$meta$itemsPerPage),
         "/",
@@ -362,7 +363,7 @@
         res$meta$benchmark,
         '\n'
       ))
-    }
+
     page <- page + 1
     results <- results + res$meta$itemsPerPage
     if (nrow(collectedMatches) >= kqo@totalResults || (!is.na(maxFetch) && results >= maxFetch)) {
diff --git a/tests/testthat/test-corpusQuery.R b/tests/testthat/test-corpusQuery.R
index 1c8b3ea..82011f4 100644
--- a/tests/testthat/test-corpusQuery.R
+++ b/tests/testthat/test-corpusQuery.R
@@ -23,7 +23,7 @@
   kco@indexRevision <- NULL
   frequencyQuery(kco, "Ameisenplage", "pubDate since 2014")
   kco@indexRevision <- as.character(Sys.time())
-  expect_output(frequencyQuery(kco, "Ameisenplage", "pubDate since 2014"), "took ")
+  expect_output(frequencyQuery(kco, "Ameisenplage", "pubDate since 2014"), "Searching")
   expect_output(frequencyQuery(kco, "Ameisenplage", "pubDate since 2014"), "cached")
 })