Open jpwynn opened 7 years ago
I too, would also like this feature.
After a brief align
search into the codebase, I found these relevant files:
awesome_print/lib/awesome_print/formatters/hash_formatter.rb
awesome_print/lib/awesome_print/formatters/base_formatter.rb
Now 'base' would probably be used only in the case of strings, not hashes like my current use case concerns, but I am not sure, and don't expect that to be necessary for my use case.
When digging into the hash file, I found the functions printable_hash
, ruby19_syntax
, and pre_ruby19_syntax
have a width argument that most likely controls this behavior, which comes from the left_width
function call inside of printable_hash
.
I was thinking :justify_hash => false
to disable this behavior. I'm sure there are other combinations for the option key name to quickly think of as well.
This way, you can still have indentation, but don't require text layout justification with that extra spacing.
For my example, I wanted this:
2.1.5 (main):0 > ap({one: 1, two: 2, three: 3})
{
:one => 1,
:three => 3,
:two => 2
}
=> nil
2.1.5 (main):0 > ap({one: 1, two: 2, three: 3}, {justify_hash: false})
{
:one => 1,
:three => 3,
:two => 2
}
=> nil
where my use of the option in the second example denotes my requested behavior, where the '=>' symbols are not aligned with more than 1 preceding space, with the same affecting the values as well.
Seems unusable when you have nested hashes... the 'child' hash is actually displayed to the LEFT of the parent hash IF hash keys get long and descriptive:
h = { :why_int_the_world_does => "AP do", :this => { :non_sense => "with nested hashes?" } }
That's very hard to decipher indents when you display a hash with say 20 keys and 3 or 4 nesting levels!
IMO it needs an option to simply indent each KEY level of a hash by N spaces and let the VALUE fall where it may, right after the key, with no attempt at aligning the values
perhaps call it 'simple_indent'