Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions R/width.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
#' * We are _not_ using the `RSTUDIO_CONSOLE_WIDTH` environment variable
#' if we are in the RStudio console.
#'
#' If we cannot determine the size of the terminal or console window, then
#' we use the `width` option. If the `width` option is not set, then
#' we return 80L.
#' If we cannot determine the size of the terminal or console window (e.g. if
#' `console_width()` is called in a startup `.Rprofile` script before a console
#' is present), then we use the `width` option. If the `width` option is not
#' set, then we return 80L.
#'
#' @return Integer scalar, the console with, in number of characters.
#'
Expand Down Expand Up @@ -102,7 +103,9 @@ tty_size <- function() {
}

terminal_width <- function() {
if (isTRUE(clienv$notaconsole)) return(NULL)
if (isTRUE(clienv$notaconsole)) {
return(NULL)
}
w <- tryCatch(
tty_size()[["width"]],
error = function(e) {
Expand All @@ -112,7 +115,9 @@ terminal_width <- function() {
)

# this is probably a pty that does not set the width, use st sensible
if (!is.null(w) && w == 0) w <- 80L
if (!is.null(w) && w == 0) {
w <- 80L
}
w
}

Expand Down
7 changes: 4 additions & 3 deletions man/console_width.Rd

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

Loading