You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -196,25 +196,35 @@ public struct CLTLogger : LogHandler {
196
196
case"color":return.color
197
197
case"emoji":return.emoji
198
198
case"text":return.text
199
-
default:(/* nop: The logger style is invalid, we infer the style as if the variable is not there. */)
199
+
default:(/* nop: The logger style is invalid, we infer the style as if the variable were not there. */)
200
200
}
201
201
}
202
-
letsupportsColor={
203
-
iflet s =getenv("__CFBundleIdentifier"),String(cString: s)=="com.apple.dt.Xcode"{
204
-
/* Xcode runs the programs in a tty, but does not support colors. */
205
-
returnfalse
206
-
}
207
-
ifisatty(fd.rawValue)!=0{
208
-
/* TODO: Check whether the tty actually supports colors.
209
-
* Hint: `tput colors` is able to return the numbers of colors supported in the terminal. How does it do it? */
210
-
returntrue
211
-
}
212
-
iflet s =getenv("GITHUB_ACTIONS"),String(cString: s)=="true"{
213
-
returntrue
202
+
203
+
/* * * The logging style is not defined specifically in the dedicated environment value: we try and detect a correct value depending on other environmental clues. * * */
204
+
205
+
/* Is the fd on which we write a tty?
206
+
* Most ttys nowadays support colors, with a notable exception: Xcode. */
207
+
ifisatty(fd.rawValue)!=0{
208
+
/* Xcode detection: it ain’t trivial.
209
+
* I found checking for the existence of the __XCODE_BUILT_PRODUCTS_DIR_PATHS env var to be a possible solution.
210
+
* We could also probably check for the existence of the TERM env var: Xcode does not set it.
211
+
* (When Package.swift is built we can check if the value of the __CFBundleIdentifier env var is "com.apple.dt.Xcode".)
212
+
* The solution we’re currently using is to check whether the fd on which we write has a foreground process group as Xcode does not set one.
213
+
* Note: If Xcode detection is changed here, it should also be changed in defaultConstantsByLogLevelForEmoji. */
214
+
iftcgetpgrp(fd.rawValue)==-1 && errno == ENOTTY {
215
+
/* We log using emojis in Xcode. */
216
+
return.emoji
214
217
}
215
-
returnfalse
218
+
/* If the TERM env var is not set we assume colors are not supported and return the text logging style.
219
+
* In theory we should use the curses database to check for colors (ncurses has the `has_colors` function for this). */
220
+
return(getenv("TERM")==nil?.text :.color)
216
221
}
217
-
return(supportsColor()?.color :.emoji)
222
+
iflet s =getenv("GITHUB_ACTIONS"),String(cString: s)=="true"{
223
+
/* GitHub does support colors. */
224
+
return.color
225
+
}
226
+
/* Unknown case: we return the text logging style. */
227
+
return.text
218
228
}
219
229
220
230
/* Do _not_ use os_unfair_lock, apparently it is bad in Swift:
@@ -254,17 +264,17 @@ public extension CLTLogger {
0 commit comments