diff --git a/src/trunc_io.erl b/src/trunc_io.erl index 06e2972..23d4080 100644 --- a/src/trunc_io.erl +++ b/src/trunc_io.erl @@ -172,6 +172,9 @@ print(Atom, _Max) when is_atom(Atom) -> print(<<>>, _Max) -> {"<<>>", 4}; +print(Binary, 0) when is_binary(Binary) -> + {"<<..>>", 6}; + print(Binary, Max) when is_binary(Binary) -> B = binary_to_list(Binary, 1, lists:min([Max, size(Binary)])), {L, Len} = alist_start(B, Max-4), @@ -181,9 +184,16 @@ print(Float, _Max) when is_float(Float) -> L = float_to_list(Float), {L, length(L)}; -print(Fun, _Max) when is_function(Fun) -> +print(Fun, Max) when is_function(Fun) -> L = erlang:fun_to_list(Fun), - {L, length(L)}; + case length(L) > Max of + true -> + S = erlang:max(5, Max), + Res = string:substr(L, 1, S) ++ "..>", + {Res, length(Res)}; + _ -> + {L, length(L)} + end; print(Integer, _Max) when is_integer(Integer) -> L = integer_to_list(Integer), diff --git a/test/trunc_io_eqc.erl b/test/trunc_io_eqc.erl index 85bd7c8..4b96aab 100644 --- a/test/trunc_io_eqc.erl +++ b/test/trunc_io_eqc.erl @@ -115,7 +115,7 @@ gen_fun() -> prop_format() -> ?FORALL({FmtArgs, MaxLen}, {gen_fmt_args(), gen_max_len()}, begin - FudgeLen = 31, %% trunc_io does not correctly calc safe size of pid/port/numbers + FudgeLen = 31, %% trunc_io does not correctly calc safe size of pid/port/numbers/funs {FmtStr, Args} = build_fmt_args(FmtArgs), try Str = lists:flatten(trunc_io:format(FmtStr, Args, MaxLen)),