nietaki / rexbug

A thin Elixir wrapper for the redbug Erlang tracing debugger.
https://hexdocs.pm/rexbug/
MIT License
252 stars 15 forks source link

Proposal: Pretty format #49

Open Dkendal opened 3 years ago

Dkendal commented 3 years ago

Hey, first of all thanks for your work on Rexbug - I use it a lot and it adds a lot of value for me.

I've written a "pretty" formatter using Inspect.Algebra that also accepts printing options like Kernel.inspect/2 and I was wondering if this is something you'd consider merging upstream?

If this is something you're interested in I can put together a proposal PR - just let me know if you you'd prefer for it to replace the existing formatter in Rexbug.Printing, be opt-in or any other suggestions.

This is what the tracing output looks like for calls, returns and stack traces:

screenshot of pretty formatter for rexbug

triggered from this example test:

defmodule DemoTest do
  use ExUnit.Case

  test "demo" do
    import Debug

    {:ok, _} = trace(":maps :: stack;return")

    lower_ansi_map = for(c <- ?a..?z, do: {<<c>>, c}, into: %{})
    upper_ansi_map = for(c <- ?A..?Z, do: {<<c>>, c}, into: %{})

    Map.merge(lower_ansi_map, upper_ansi_map)

    trace_stop_sync()
  end
end
ghost commented 3 years ago

Looks nice - my 2c - printing option infinity rather than truncate any output - frequently use tools like rexbug whilst hunting for the proverbial needle in the haystack

Dkendal commented 3 years ago

My trace/3 function has the signature:

  @spec trace(Rexbug.trace_pattern(), Keyword.t(), Inspect.Opts.t()) ::
          Rexbug.rexbug_return()
  def trace(pattern, trace_opts \\ [], inspect_opts \\ [])

So any limit can be passed into inspect_opts, but yea that default could be :infinity, likewise ansi color codes can be disabled with syntax_colors: [].

vanvoljg commented 3 years ago

@bryanhuntesl The default actually is required to be :infinity, or some non-zero integer as of Elixir 1.11.0. They made some changes to the guards in Inspect.Algebra. I have a PR open that sets the default, but it hasn't been addressed in this repo.

@Dkendal I would be extremely interested in that PR. I'm tired of spending half an hour or more trying to space and indent to get into the depths of a huge data structure! If you're okay with opening it against my fork, peek-travel/rexbug, then I'll merge it on my side and open a PR back to this repo for when the author has time.

nietaki commented 3 years ago

Hey @Dkendal, sorry I didn't reply sooner, my Github notifications weren't configured right and I missed the issue altogether.

A pretty printer for Rexbug sounds great - making the tracing output more readable might in many situations make a huge difference when you need it the most.

I'd be down to make it an option for Rexbug and I'd be happy to help.

I have one ask I'd like to make in advance - It was always important to me that Rexbug doesn't have any hard dependencies other than redbug. If the pretty printing ends up being provided by an external library, I'd like the dependency to be optional and for Rexbug to be usable (without the pretty printing, naturally) without it.

axelson commented 9 months ago

@Dkendal do you have that code in a fork somewhere? I'm not seeing anything on your GitHub.

Dkendal commented 9 months ago

I’ll take a look for it this weekend, i have it in a gist somewhere.

Best regards, Dylan

On Sat, Jan 13, 2024 at 2:16 PM Jason Axelson @.***> wrote:

@Dkendal https://github.com/Dkendal do you have that code in a fork somewhere? I'm not seeing anything on your GitHub.

— Reply to this email directly, view it on GitHub https://github.com/nietaki/rexbug/issues/49#issuecomment-1890738638, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAYEBO7IHUKTTM4UAO7GKLTYOLMPDAVCNFSM4XBRSPM2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBZGA3TGOBWGM4A . You are receiving this because you were mentioned.Message ID: @.***>

axelson commented 9 months ago

That would be much appreciated!

Dkendal commented 9 months ago

@axelson I believe it was in this Gist: https://gist.github.com/Dkendal/116063f23ab70ba764a0aa17a9fa3eb7