From 9bc308532f0a3fa698dbcb0d9ff815d64ad4ae4f Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sat, 10 Jan 2026 13:42:45 -0600 Subject: [PATCH] Make varfn correctly handle verbose metadata. The macro would previously choke on `(varfn abc {:abc 123} ...)` due to mishandling of structs and tables as metadata. This caused issues when running `janet -d` with spork. --- CHANGELOG.md | 2 ++ src/boot/boot.janet | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dcbd0ba..32d3fcfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. ## Unreleased - ??? +- Use color in script output if color is being used in REPL output. +- Fix `varfn` macros handling of extra metadata. - Add linting for unused bindings. - Add `janet_optuinteger` and `janet_optuinteger64` to the C API. - Add `cms` combinator to PEGs. diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 7c05f42a..e2befd3d 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -2403,6 +2403,7 @@ (cond (keyword? m) (put metadata m true) (string? m) (put metadata :doc m) + (dictionary? m) (merge-into metadata m) (error (string "invalid metadata " m)))) (with-syms [entry old-entry f] ~(let [,old-entry (,dyn ',name)] @@ -4682,6 +4683,11 @@ (setdyn *err-color* (if colorize true)) (setdyn *doc-color* (if colorize true))) +(defn- getstdin [prompt buf _] + (file/write stdout prompt) + (file/flush stdout) + (file/read stdin :line buf)) + (defn cli-main `Entrance for the Janet CLI tool. Call this function with the command line arguments as an array or tuple of strings to invoke the CLI interface.` @@ -4705,10 +4711,10 @@ (module/add-syspath (get paths i))) (setdyn *syspath* (first paths))) (if-let [jprofile (getenv-alias "JANET_PROFILE")] (setdyn *profilepath* jprofile)) - (when (and - (not (getenv-alias "NO_COLOR")) - (os/isatty stdout)) - (apply-color true)) + (apply-color + (and + (not (getenv-alias "NO_COLOR")) + (os/isatty stdout))) (defn- get-lint-level [i] @@ -4861,10 +4867,6 @@ (when-let [custom-prompt (get env *repl-prompt*)] (break (custom-prompt p))) (def [line] (parser/where p)) (string "repl:" line ":" (parser/state p :delimiters) "> ")) - (defn getstdin [prompt buf _] - (file/write stdout prompt) - (file/flush stdout) - (file/read stdin :line buf)) (def getter (if raw-stdin getstdin getline)) (defn getchunk [buf p] (getter (getprompt p) buf env))