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

Proposal: Pretty format #49

Open
Dkendal opened this issue Feb 3, 2021 · 8 comments
Open

Proposal: Pretty format #49

Dkendal opened this issue Feb 3, 2021 · 8 comments

Comments

@Dkendal
Copy link

Dkendal commented Feb 3, 2021

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
Copy link

ghost commented Feb 3, 2021

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
Copy link
Author

Dkendal commented Feb 3, 2021

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
Copy link
Contributor

@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
Copy link
Owner

nietaki commented Apr 12, 2021

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
Copy link

axelson commented Jan 13, 2024

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

@Dkendal
Copy link
Author

Dkendal commented Jan 13, 2024 via email

@axelson
Copy link

axelson commented Jan 13, 2024

That would be much appreciated!

@Dkendal
Copy link
Author

Dkendal commented Jan 15, 2024

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

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

No branches or pull requests

4 participants