Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ANSI rendering bug with "0;" #567

Closed
petermm opened this issue Sep 30, 2021 · 0 comments · Fixed by #569
Closed

ANSI rendering bug with "0;" #567

petermm opened this issue Sep 30, 2021 · 0 comments · Fixed by #569

Comments

@petermm
Copy link

petermm commented Sep 30, 2021

Environment

  • Elixir & Erlang/OTP versions (elixir --version): 1.12.3 24.1

  • Operating system: macOS

  • How have you started Livebook (mix phx.server, livebook CLI, Docker, etc): iex -S mix phx.server

  • Livebook version (use git show if running with mix): current latest - commit 026945e (HEAD -> main, origin/main, origin/HEAD)

  • Browsers that reproduce this bug (the more the merrier): All

  • Include what is logged in the browser console: n/a

  • Include what is logged to the server console: n/a

Current behavior

Notice ANSI bug and wrong rendering by doing:

Mix.install([
  {:eqrcode, "~> 0.1.10"}
])

"small qr"
|> EQRCode.encode()
|> EQRCode.render()

Screenshot 2021-09-30 at 10 15 01

Expected behavior

Correct ANSI rendering.

Context

the code failing is from https://github.com/SiliconJungles/eqrcode/blob/8ce379a07d260e74b88f0671b7b0ec4004e37c65/lib/eqrcode/render.ex#L30

eg the "\e[0;107m \e[0m" string:

iex()> "\e[0;107m  \e[0m" |> LivebookWeb.Helpers.ANSI.ansi_string_to_html()
{:safe, ["\e[0;107m  "]}

in contrast to:

iex()> "\e[40m  \e[0m" |> LivebookWeb.Helpers.ANSI.ansi_string_to_html()   
{:safe,
 [
   ["<span style=\"", "background-color: var(--ansi-color-black);", "\">", "  ",
    "</span>"]
 ]}

Hackish fix

adding string = string |> String.replace("0;", "0m\e[")
before this line does remedy it - but surely this is not the proper fix..

[head | ansi_prefixed_strings] = String.split(string, "\e")

Screenshot 2021-09-30 at 10 31 38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant