From 6fc48ac9d94acfe48e336c71fc4a29eab09b284c Mon Sep 17 00:00:00 2001 From: stefanocoretta Date: Mon, 18 Dec 2023 19:50:40 +0000 Subject: [PATCH] add argument to set custom font family --- DESCRIPTION | 4 ++-- NEWS.md | 5 +++++ R/activate.R | 10 ++++++++- R/customise.R | 38 +++++++++++++++++++++++++++++++++++ inst/resources/darkstudio.css | 5 ++++- man/activate.Rd | 13 +++++++++--- man/customise.Rd | 14 +++++++++++++ 7 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 NEWS.md create mode 100644 R/customise.R create mode 100644 man/customise.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 898af43..21002af 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: darkstudio Type: Package Title: An Alternative Look for RStudio's Modern and Sky Themes -Version: 0.2.0 +Version: 0.3.0 Author: Riley Roach Maintainer: Riley Roach Description: Modifies RStudio's Modern and Sky themes to use grey rather than blue. @@ -11,4 +11,4 @@ LazyData: true Imports: rstudioapi, fs -RoxygenNote: 7.1.1 +RoxygenNote: 7.2.3 diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..c52906a --- /dev/null +++ b/NEWS.md @@ -0,0 +1,5 @@ +# darkstudio v0.3.0 + +## Added + +- Users can now select a font family of their choice for the UI. diff --git a/R/activate.R b/R/activate.R index 2f094b7..d5ce104 100644 --- a/R/activate.R +++ b/R/activate.R @@ -9,6 +9,9 @@ #' @param type character: #' Accepts 'user' or NULL. If 'user', \code{activate()} will look for RStudio #' in \code{/Users/xxx/Applications} instead of \code{/Applications} on macOS. +#' @param font_family character: +#' Name of the font family to use for the RStudio UI. If \code{NULL}, uses +#' to darkstudio defaults. If \code{"rstudio"}, uses default RStudio fonts. #' #' daRkStudio modifies \code{index.htm}, a file used by RStudio to construct #' it's DOM (Document Object Model). @@ -34,6 +37,9 @@ #' # Default: #' activate() #' +#' # Set UI font +#' activate(font_family = "Noto Sans") +#' #' # macOS: #' path_index <- "/Applications/RStudio.app/Contents/Resources/www/index.htm" #' activate(path = path_index, backup = TRUE) @@ -46,7 +52,7 @@ #' @return TRUE #' @return Returns \code{TRUE} if the operation is successful. #' @export -activate <- function(path = NULL, backup = TRUE, type = NULL) { +activate <- function(path = NULL, backup = TRUE, type = NULL, font_family = NULL) { # Fail quickly if the RStudio API is not available if (!rstudioapi::isAvailable()) { stop("RStudio must be running in order to install darkstudio.") @@ -78,6 +84,8 @@ activate <- function(path = NULL, backup = TRUE, type = NULL) { fs::path_package(package = "darkstudio"), "resources/darkstudio.css" ) + customise(ds_css, font_family) + fs::file_copy(path = ds_css, new_path = ds_dir, overwrite = TRUE) file_index <- index$read(path = path_index) diff --git a/R/customise.R b/R/customise.R new file mode 100644 index 0000000..77a40f2 --- /dev/null +++ b/R/customise.R @@ -0,0 +1,38 @@ +#' custom.R +#' Created by Stefano Coretta on 2023-12-18 +#' @keywords internal +customise <- function(ds_css, font_family) { + + # read darkstudio.css + css_lines <- readLines(ds_css) + + if (is.null(font_family)) { + ui_font_line <- grep("-apple-system", css_lines) + # use original darkstudio fonts + css_lines[ui_font_line] <- paste0( + "--ds-ui-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, + Arial, sans-serif;") + + writeLines(css_lines, ds_css) + + } else if (font_family == "rstudio") { + ui_font_line <- grep("-apple-system", css_lines) + # use RStudio default UI fonts + css_lines[ui_font_line] <- paste0( + "--ds-ui-font: 'Lucida Grande', 'Lucida Sans Unicode', Helvetica, sans-serif;") + + writeLines(css_lines, ds_css) + + } else if (!is.null(font_family)) { + ui_font_line <- grep("-apple-system", css_lines) + # add user font; hard-coded from original .css + css_lines[ui_font_line] <- paste0( + "--ds-ui-font: '", font_family, "', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, + Arial, sans-serif;") + + writeLines(css_lines, ds_css) + + } else { + + } +} diff --git a/inst/resources/darkstudio.css b/inst/resources/darkstudio.css index e0af462..1564167 100644 --- a/inst/resources/darkstudio.css +++ b/inst/resources/darkstudio.css @@ -1,7 +1,10 @@ /* -------- FONTS --------- */ :root { - --ds-ui-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, +--ds-ui-font: 'Lato', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, + Arial, sans-serif; + Arial, sans-serif; + Arial, sans-serif; Arial, sans-serif; --ds-ui-bg: #2c2c2c; --ds-ui-font-fg: #ffffff; diff --git a/man/activate.Rd b/man/activate.Rd index 9edbe84..b8a16a6 100644 --- a/man/activate.Rd +++ b/man/activate.Rd @@ -4,7 +4,7 @@ \alias{activate} \title{Activate daRkStudio} \usage{ -activate(path = NULL, backup = TRUE, type = NULL) +activate(path = NULL, backup = TRUE, type = NULL, font_family = NULL) } \arguments{ \item{path}{character: @@ -16,8 +16,12 @@ TRUE or FALSE. Copies the default \code{index.htm} file to \code{index.htm.pre-ds}. Defaults to TRUE.} \item{type}{character: - Accepts 'user' or NULL. If 'user', \code{activate()} will look for RStudio - in \code{/Users/xxx/Applications} instead of \code{/Applications} on macOS. +Accepts 'user' or NULL. If 'user', \code{activate()} will look for RStudio +in \code{/Users/xxx/Applications} instead of \code{/Applications} on macOS.} + +\item{font_family}{character: + Name of the font family to use for the RStudio UI. If \code{NULL}, uses + to darkstudio defaults. If \code{"rstudio"}, uses default RStudio fonts. daRkStudio modifies \code{index.htm}, a file used by RStudio to construct it's DOM (Document Object Model). @@ -50,6 +54,9 @@ Activate daRkStudio # Default: activate() +# Set UI font +activate(font_family = "Noto Sans") + # macOS: path_index <- "/Applications/RStudio.app/Contents/Resources/www/index.htm" activate(path = path_index, backup = TRUE) diff --git a/man/customise.Rd b/man/customise.Rd new file mode 100644 index 0000000..49aaeb3 --- /dev/null +++ b/man/customise.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/customise.R +\name{customise} +\alias{customise} +\title{custom.R +Created by Stefano Coretta on 2023-12-18} +\usage{ +customise(ds_css, font_family) +} +\description{ +custom.R +Created by Stefano Coretta on 2023-12-18 +} +\keyword{internal}