Skip to content

Commit

Permalink
fix: pass already colorized strings through
Browse files Browse the repository at this point in the history
  • Loading branch information
russmatney committed Apr 14, 2024
1 parent 792026f commit 0ca78cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 5 additions & 8 deletions addons/log/log.gd
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ static func color_scheme(opts={}):

static func color_wrap(s, opts={}):
var use_color = opts.get("use_color", true)
# support cutting off rebuilding the color scheme
# don't rebuild the color scheme every time
var colors = opts.get("built_color_scheme", color_scheme(opts))

if use_color:
Expand Down Expand Up @@ -241,8 +241,6 @@ static func to_pretty(msg, opts={}):
if not "built_color_scheme" in opts:
opts["built_color_scheme"] = color_scheme

# TODO set and attach color_scheme to opts

if not is_instance_valid(msg) and typeof(msg) == TYPE_OBJECT:
return str("invalid instance: ", msg)

Expand Down Expand Up @@ -315,13 +313,12 @@ static func to_pretty(msg, opts={}):

# strings
elif msg is String:
# TODO support (use as-is) already 'rich/colorized' strings
# maybe just a regex for [color=.*]?
if msg == "":
return '""'
# could check for supported tags in the string (see list above)
# if msg.contains("["):
# msg = "<ACTUAL-TEXT-REPLACED>"
if "[color=" in msg and "[/color]" in msg:
# assumes the string is already colorized
# NOT PERFECT! could use a regex for something more robust
return msg
return Log.color_wrap(msg, opts)
elif msg is StringName:
return str(Log.color_wrap("&", opts), '"%s"' % msg)
Expand Down
4 changes: 4 additions & 0 deletions test/log_test.gd
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func test_node_paths():
var val = Log.to_pretty(np)
assert_str(val).is_equal("[color=orange]^[/color]\"Some/Path/To/A/Node\"")

func test_already_colorized_string():
var val = Log.to_pretty("[color=blue]Something[/color]")
assert_str(val).is_equal("[color=blue]Something[/color]")

## color ##########################################

func test_color():
Expand Down

0 comments on commit 0ca78cc

Please sign in to comment.