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

when print record format by lager:pr which has binary value, need space after '=' #554

Open
yidayoung opened this issue May 26, 2021 · 0 comments

Comments

@yidayoung
Copy link
Contributor

when print a record like #rec{field =<<"">>}, it will trans to string "#rec{field=<<"">>}"
every thing works fine, but when paste this string to shell will cause syntax error before: '=<'
because need space after '=' like this "#rec{field= <<"">>}"

so, can we change this format here

{FieldStr, FieldLen} = print(Field, Max - ExtraChars, Options),
{ValueStr, ValueLen} = print(Value, Max - (FieldLen + ExtraChars), Options),
{Final, FLen} = record_fields(T, Max - (FieldLen + ValueLen + ExtraChars), dec_depth(Options)),
{[FieldStr++"="++ValueStr++Terminator|Final], FLen + FieldLen + ValueLen + ExtraChars}.


one way is change binary print function

print(<<>>, _Max, #print_options{depth=1}) ->
{"<<>>", 4};
print(Bin, _Max, #print_options{depth=1}) when is_binary(Bin) ->
{"<<...>>", 7};
print(<<>>, _Max, Options) ->
case Options#print_options.force_strings of
true ->
{"", 0};
false ->
{"<<>>", 4}
end;
print(Binary, 0, _Options) when is_bitstring(Binary) ->
{"<<..>>", 6};
print(Bin, Max, _Options) when is_binary(Bin), Max < 2 ->
{"<<...>>", 7};
print(Binary, Max, Options) when is_binary(Binary) ->
B = binary_to_list(Binary, 1, lists:min([Max, byte_size(Binary)])),

but this may cause some other behavior changed

or just add ensure_space after print function, like this

    {FieldStr, FieldLen} = print(Field, Max - ExtraChars, Options),
    {ValueStr, ValueLen} = print(Value, Max - (FieldLen + ExtraChars), Options),
    {ValueStr2, ValueLen2} = ensure_space(Value, ValueStr, ValueLen),
    {Final, FLen} = record_fields(T, Max - (FieldLen + ValueLen + ExtraChars), dec_depth(Options)),
    {[FieldStr++"="++ValueStr2++Terminator|Final], FLen + FieldLen + ValueLen2 + ExtraChars}.

ensure_space(Value, ValueStr, ValueLen) when is_binary(Value) ->
    {" "+ValueStr, ValueLen+1};
ensure_space(_Value, ValueStr, ValueLen) ->
    {ValueStr, ValueLen}.

if add ensure_space is enough, i can make a pr for this

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

1 participant