garthk
Pretty - inspect values with syntax colors despite your remote console
Pretty addresses two surprises you’ll encounter trying to dump data to the remote console
like you did during development with iex -S mix:
-
IO.inspect/1et al work fine at theiex>prompt but somehow not when called from a:telemetryhandler function or other troubleshooting mechanism… unless you think to look at the log output -
The syntax colors aren’t working like you think they should, either
-
The inspection width is 80… just like
iex, now that you think of it
You don’t need Pretty to deal with this—it’s enough to know to call Process.group_leader/0 to get a device to hand to IO.puts/2, for example—but by the time you solve all three problems it’s chunky enough you might plausibly add a dependency rather than paste a snippet:
bind = fn opts ->
device = Process.group_leader()
width = with {:ok, n} <- :io.columns(device), do: n, else: (_ -> %Inspect.Opts{}.width)
opts = Keyword.merge(:rpc.call(:erlang.node(device), IEx.Config, :inspect_opts, []), opts)
opts = Keyword.merge(opts, pretty: true, width: width)
reset = Enum.find_value(Keyword.get(opts, :syntax_colors, []), [], fn _ -> IO.ANSI.reset() end)
fn term -> IO.puts(device, [Kernel.inspect(term, opts), reset]); term end
end
If nothing else, y’all might enjoy the explanation of what’s going on.
Trending in Announcing
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #performance










First Post!
dimitarvp
Pretty good, I’ll use that, thank you.