awesome-print / awesome_print

Pretty print your Ruby objects with style -- in full color and with proper indentation
http://github.com/michaeldv/awesome_print
MIT License
4.07k stars 454 forks source link

New lines not converted on output #143

Open keithrbennett opened 10 years ago

keithrbennett commented 10 years ago

I'd like to be able to print a multiline string, but even when changing the multiline setting, awesome_print prints a literal "\n" rather than issuing a new line. Here's a pry session illustrating what I mean:

[2] pry(main)> ap "a\nb", multiline: false
"a\nb"
=> nil

[3] pry(main)> ap "a\nb", multiline: true
"a\nb"

[4] pry(main)> puts "a\nb"
a
b

Is there a way to get it to do the new line instead of '\n'?

tyre commented 10 years ago

:+1:

searls commented 8 years ago

:+1: -- I've been banging my head against a wall trying to figure out how to get this to work.

keithrbennett commented 8 years ago

Here's a method that would kind of work around it, except that it puts quotes around every line, and you'd have to monkey patch Kernel.ap:

def apx(obj)
  obj.is_a?(String) ? puts(obj.split("\n").map(&:ai).join("\n")) : ap obj
end

# apx("a\b") =>
"a"
"b"