1
-
2
1
rstudio <- local({
3
-
4
2
standalone_env <- environment()
5
3
parent.env(standalone_env ) <- baseenv()
6
4
@@ -18,7 +16,8 @@ rstudio <- local({
18
16
" RSTUDIO_CONSOLE_COLOR" ,
19
17
" RSTUDIOAPI_IPC_REQUESTS_FILE" ,
20
18
" XPC_SERVICE_NAME" ,
21
- " ASCIICAST" )
19
+ " ASCIICAST"
20
+ )
22
21
23
22
d <- list (
24
23
pid = Sys.getpid(),
@@ -55,8 +54,10 @@ rstudio <- local({
55
54
if (clear_cache ) data <<- NULL
56
55
if (! is.null(data )) return (get_caps(data ))
57
56
58
- if ((rspid <- Sys.getenv(" RSTUDIO_SESSION_PID" )) != " " &&
59
- any(c(" ps" , " cli" ) %in% loadedNamespaces())) {
57
+ if (
58
+ (rspid <- Sys.getenv(" RSTUDIO_SESSION_PID" )) != " " &&
59
+ any(c(" ps" , " cli" ) %in% loadedNamespaces())
60
+ ) {
60
61
detect_new(rspid , clear_cache )
61
62
} else {
62
63
detect_old(clear_cache )
@@ -89,31 +90,26 @@ rstudio <- local({
89
90
90
91
# direct subprocess
91
92
new $ type <- if (rspid == parentpid ) {
92
-
93
93
if (pane == " job" ) {
94
94
" rstudio_job"
95
-
96
95
} else if (pane == " build" ) {
97
96
" rstudio_build_pane"
98
-
99
97
} else if (pane == " render" ) {
100
98
" rstudio_render_pane"
101
-
102
- } else if ( pane == " terminal" && new $ tty &&
103
- new $ envs [ " ASCIICAST " ] != " true " ) {
99
+ } else if (
100
+ pane == " terminal" && new $ tty && new $ envs [ " ASCIICAST " ] != " true "
101
+ ) {
104
102
# not possible, because there is a shell in between, just in case
105
103
" rstudio_terminal"
106
-
107
104
} else {
108
105
# don't know what kind of direct subprocess
109
106
" rstudio_subprocess"
110
107
}
111
-
112
- } else if ( pane == " terminal" && new $ tty &&
113
- new $ envs [[ " ASCIICAST " ]] != " true " ) {
108
+ } else if (
109
+ pane == " terminal" && new $ tty && new $ envs [[ " ASCIICAST " ]] != " true "
110
+ ) {
114
111
# not a direct subproces, so check other criteria as well
115
112
" rstudio_terminal"
116
-
117
113
} else {
118
114
# don't know what kind of subprocess
119
115
" rstudio_subprocess"
@@ -123,58 +119,55 @@ rstudio <- local({
123
119
}
124
120
125
121
detect_old <- function (clear_cache = FALSE ) {
126
-
127
122
# Cache unless told otherwise
128
123
cache <- TRUE
129
124
new <- get_data()
130
125
131
126
new $ type <- if (new $ envs [[" RSTUDIO" ]] != " 1" ) {
132
127
# 1. Not RStudio at all
133
128
" not_rstudio"
134
-
135
129
} else if (new $ gui == " RStudio" && new $ api ) {
136
130
# 2. RStudio console, properly initialized
137
131
" rstudio_console"
138
-
139
- } else if (! new $ api && basename(new $ args [1 ]) == " RStudio" ) {
132
+ } else if (! new $ api && basename(new $ args [1 ]) == " RStudio" ) {
140
133
# 3. RStudio console, initializing
141
134
cache <- FALSE
142
135
" rstudio_console_starting"
143
-
144
136
} else if (new $ gui == " Rgui" ) {
145
137
# Still not RStudio, but Rgui that was started from RStudio
146
138
" not_rstudio"
147
-
148
139
} else if (new $ tty && new $ envs [[" ASCIICAST" ]] != " true" ) {
149
140
# 4. R in the RStudio terminal
150
141
# This could also be a subprocess of the console or build pane
151
142
# with a pseudo-terminal. There isn't really a way to rule that
152
143
# out, without inspecting some process data with ps::ps_*().
153
144
# At least we rule out asciicast
154
145
" rstudio_terminal"
155
-
156
- } else if (! new $ tty &&
157
- new $ envs [[" RSTUDIO_TERM" ]] == " " &&
158
- new $ envs [[" R_BROWSER" ]] == " false" &&
159
- new $ envs [[" R_PDFVIEWER" ]] == " false" &&
160
- is_build_pane_command(new $ args )) {
146
+ } else if (
147
+ ! new $ tty &&
148
+ new $ envs [[" RSTUDIO_TERM" ]] == " " &&
149
+ new $ envs [[" R_BROWSER" ]] == " false" &&
150
+ new $ envs [[" R_PDFVIEWER" ]] == " false" &&
151
+ is_build_pane_command(new $ args )
152
+ ) {
161
153
# 5. R in the RStudio build pane
162
154
# https://github.com/rstudio/rstudio/blob/master/src/cpp/session/
163
155
# modules/build/SessionBuild.cpp#L231-L240
164
156
" rstudio_build_pane"
165
-
166
- } else if (new $ envs [[" RSTUDIOAPI_IPC_REQUESTS_FILE" ]] != " " &&
167
- grepl(" rstudio" , new $ envs [[" XPC_SERVICE_NAME" ]])) {
157
+ } else if (
158
+ new $ envs [[" RSTUDIOAPI_IPC_REQUESTS_FILE" ]] != " " &&
159
+ grepl(" rstudio" , new $ envs [[" XPC_SERVICE_NAME" ]])
160
+ ) {
168
161
# RStudio job, XPC_SERVICE_NAME=0 in the subprocess of a job
169
162
# process. Hopefully this is reliable.
170
163
" rstudio_job"
171
-
172
- } else if (new $ envs [[" RSTUDIOAPI_IPC_REQUESTS_FILE" ]] != " " &&
173
- any(grepl(" SourceWithProgress.R" , new $ args ))) {
164
+ } else if (
165
+ new $ envs [[" RSTUDIOAPI_IPC_REQUESTS_FILE" ]] != " " &&
166
+ any(grepl(" SourceWithProgress.R" , new $ args ))
167
+ ) {
174
168
# Or we can check SourceWithProgress.R in the command line, see
175
169
# https://github.com/r-lib/cli/issues/367
176
170
" rstudio_job"
177
-
178
171
} else {
179
172
# Otherwise it is a subprocess of the console, terminal or
180
173
# build pane, and it is hard to say which, so we do not try.
@@ -297,4 +290,4 @@ rstudio <- local({
297
290
)
298
291
})
299
292
300
- rstudio_detect <- function (... ) rstudio $ detect(... )
293
+ rstudio_detect <- function (... ) rstudio $ detect(... )
0 commit comments