Skip to content

Commit 85aabe6

Browse files
Respect Julia's color settings in error messages
This PR fixes issue #194 by checking the IOContext's :color property before using printstyled with colors. When Julia is run with --color=no, error messages will now display without ANSI color codes. Changes: - Check `get(io, :color, false)` before using printstyled with colors - Fall back to plain print() when colors are disabled - Applied to both CommonKwargError and checkkwargs warning messages Fixes #194 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d878c48 commit 85aabe6

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/solve.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,11 @@ function Base.showerror(io::IO, e::CommonKwargError)
131131
notin = collect(map(x -> x allowedkeywords, keys(e.kwargs)))
132132
unrecognized = collect(keys(e.kwargs))[notin]
133133
print(io, "Unrecognized keyword arguments: ")
134-
printstyled(io, unrecognized; bold = true, color = :red)
134+
if get(io, :color, false)
135+
printstyled(io, unrecognized; bold = true, color = :red)
136+
else
137+
print(io, unrecognized)
138+
end
135139
print(io, "\n\n")
136140
println(io, TruncatedStacktraces.VERBOSE_MSG)
137141
end
@@ -1261,7 +1265,11 @@ function checkkwargs(kwargshandle; kwargs...)
12611265
@warn KWARGWARN_MESSAGE
12621266
unrecognized = setdiff(keys(kwargs), allowedkeywords)
12631267
print("Unrecognized keyword arguments: ")
1264-
printstyled(unrecognized; bold = true, color = :red)
1268+
if get(stdout, :color, false)
1269+
printstyled(unrecognized; bold = true, color = :red)
1270+
else
1271+
print(unrecognized)
1272+
end
12651273
print("\n\n")
12661274
else
12671275
@assert kwargshandle == KeywordArgSilent

0 commit comments

Comments
 (0)