mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-12-19 22:49:23 +08:00
* Implement ANSI to HTML converter * Enable ANSI escape codes by default in the standalone runtime
34 lines
780 B
Elixir
34 lines
780 B
Elixir
defmodule LiveBook.Evaluator.StringFormatter do
|
|
@moduledoc false
|
|
|
|
# The formatter used by LiveBook for rendering the results.
|
|
|
|
@behaviour LiveBook.Evaluator.Formatter
|
|
|
|
@impl true
|
|
def format({:ok, value}) do
|
|
inspected = inspect(value, pretty: true, width: 100, syntax_colors: syntax_colors())
|
|
{:inspect, inspected}
|
|
end
|
|
|
|
def format({:error, kind, error, stacktrace}) do
|
|
formatted = Exception.format(kind, error, stacktrace)
|
|
{:error, formatted}
|
|
end
|
|
|
|
defp syntax_colors() do
|
|
[
|
|
atom: :blue,
|
|
binary: :light_black,
|
|
boolean: :magenta,
|
|
list: :light_black,
|
|
map: :light_black,
|
|
number: :blue,
|
|
nil: :magenta,
|
|
regex: :red,
|
|
string: :green,
|
|
tuple: :light_black,
|
|
reset: :reset
|
|
]
|
|
end
|
|
end
|