Skip to content

Commit

Permalink
🔧 Do not convert Crayon to string using string
Browse files Browse the repository at this point in the history
  • Loading branch information
ronisbr committed Mar 19, 2022
1 parent 47a6529 commit abfcb7e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
17 changes: 15 additions & 2 deletions src/backends/text/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,23 @@ function _write_to_display!(
# Notice that all text printed with crayon is reset right after the string.
# Hence, if the crayon is empty (`_default_crayon`) or if it is a reset,
# then we can just print as if the terminal does not support color.
buf_line = display.buf_line

if (crayon != _default_crayon) && (crayon != _reset_crayon) && display.has_color
print(display.buf_line, crayon, str, _reset_crayon, suffix)
# If we convert the crayon to string using `string`, it calls `print`
# which checks if the Base has colors, leading to inference problems.
# For more information, see:
#
# https://github.com/KristofferC/Crayons.jl/issues/62
write(buf_line, Crayons.CSI)
Crayons._print(buf_line, crayon)
write(buf_line, Crayons.END_ANSI)

write(buf_line, str)
write(buf_line, _reset_crayon_str)
write(buf_line, suffix)
else
print(display.buf_line, str, suffix)
write(buf_line, str, suffix)
end

# Update the current column in the display.
Expand Down
5 changes: 3 additions & 2 deletions src/backends/text/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,6 @@ end
################################################################################

# Crayon used to reset all the styling.
const _default_crayon = Crayon()
const _reset_crayon = Crayon(reset = true)
const _default_crayon = Crayon()
const _reset_crayon = Crayon(reset = true)
const _reset_crayon_str = string(_reset_crayon)

0 comments on commit abfcb7e

Please sign in to comment.