1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-13 23:07:41 +00:00

Extend environment variable behavior to NO_COLOR and JANET_PROFILE

Env vars set to empty strings should behave the same as unset variables.
This commit is contained in:
Calvin Rose
2025-10-04 13:12:29 -05:00
parent c901edbfb9
commit db7f741dad

View File

@@ -4556,7 +4556,10 @@
### ###
# conditional compilation for reduced os # conditional compilation for reduced os
(def- getenv-alias (if-let [entry (in root-env 'os/getenv)] (entry :value) (fn [&]))) (def- getenv-raw (if-let [entry (in root-env 'os/getenv)] (entry :value) (fn [&])))
(defn- getenv-alias [env-var &opt dflt]
(def x (getenv-raw env-var dflt))
(if (= x "") nil x)) # empty string is coerced to nil
(defn- run-main (defn- run-main
[env subargs arg] [env subargs arg]
@@ -4634,12 +4637,11 @@
(var expect-image false) (var expect-image false)
(when-let [jp (getenv-alias "JANET_PATH")] (when-let [jp (getenv-alias "JANET_PATH")]
(unless (empty? jp) (def path-sep (if (index-of (os/which) [:windows :mingw]) ";" ":"))
(def path-sep (if (index-of (os/which) [:windows :mingw]) ";" ":")) (def paths (reverse! (string/split path-sep jp)))
(def paths (reverse! (string/split path-sep jp))) (for i 1 (length paths)
(for i 1 (length paths) (module/add-syspath (get paths i)))
(module/add-syspath (get paths i))) (setdyn *syspath* (first paths)))
(setdyn *syspath* (first paths))))
(if-let [jprofile (getenv-alias "JANET_PROFILE")] (setdyn *profilepath* jprofile)) (if-let [jprofile (getenv-alias "JANET_PROFILE")] (setdyn *profilepath* jprofile))
(set colorize (and (set colorize (and
(not (getenv-alias "NO_COLOR")) (not (getenv-alias "NO_COLOR"))