rexbug icon indicating copy to clipboard operation
rexbug copied to clipboard

Proposal: Pretty format

Open Dkendal opened this issue 4 years ago • 8 comments

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

Dkendal avatar Feb 03 '21 20:02 Dkendal

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

bryanhuntesl avatar Feb 03 '21 21:02 bryanhuntesl

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: [].

Dkendal avatar Feb 03 '21 21:02 Dkendal

@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.

vanvoljg avatar Feb 11 '21 22:02 vanvoljg

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.

nietaki avatar Apr 12 '21 11:04 nietaki

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

axelson avatar Jan 13 '24 19:01 axelson

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: @.***>

Dkendal avatar Jan 13 '24 19:01 Dkendal

That would be much appreciated!

axelson avatar Jan 13 '24 19:01 axelson

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

Dkendal avatar Jan 15 '24 19:01 Dkendal