Skip to content

Commit da9fa64

Browse files
committed
Clarify a situation where console width cannot be determined
Fixes #578
1 parent 14bb86c commit da9fa64

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

R/width.R

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
#' * We are _not_ using the `RSTUDIO_CONSOLE_WIDTH` environment variable
2121
#' if we are in the RStudio console.
2222
#'
23-
#' If we cannot determine the size of the terminal or console window, then
24-
#' we use the `width` option. If the `width` option is not set, then
25-
#' we return 80L.
23+
#' If we cannot determine the size of the terminal or console window (e.g. if
24+
#' `console_width()` is called in a startup `.Rprofile` script before a console
25+
#' is present), then we use the `width` option. If the `width` option is not
26+
#' set, then we return 80L.
2627
#'
2728
#' @return Integer scalar, the console with, in number of characters.
2829
#'
@@ -102,7 +103,9 @@ tty_size <- function() {
102103
}
103104

104105
terminal_width <- function() {
105-
if (isTRUE(clienv$notaconsole)) return(NULL)
106+
if (isTRUE(clienv$notaconsole)) {
107+
return(NULL)
108+
}
106109
w <- tryCatch(
107110
tty_size()[["width"]],
108111
error = function(e) {
@@ -112,7 +115,9 @@ terminal_width <- function() {
112115
)
113116

114117
# this is probably a pty that does not set the width, use st sensible
115-
if (!is.null(w) && w == 0) w <- 80L
118+
if (!is.null(w) && w == 0) {
119+
w <- 80L
120+
}
116121
w
117122
}
118123

man/console_width.Rd

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)