Shorten output
Henning Diedrich
hd2010@REDACTED
Sat May 15 00:03:31 CEST 2010
Hello list,
I would like to shorten any output to certain limit. ~W and ~P won't do.
I came up with the following but I am sure there is a much better solution.
Thanks,
Henning
%%%----------------------------------------------------------------------------
%%% cut any io:format parameters short
%%%----------------------------------------------------------------------------
-define(DELIMIT, 100).
delimited([]) ->
[];
delimited(List) when is_list(List), length(List) > ?DELIMIT ->
delimited(lists:append(lists:sublist(List, ?DELIMIT),"..."));
delimited(List) when is_list(List) ->
[ delimited(X) || X <- List ];
delimited(Tuple) when is_tuple(Tuple) ->
list_to_tuple([ delimited(X) || X <- tuple_to_list(Tuple) ]);
delimited(Item) when is_binary(Item), size(Item) > ?DELIMIT ->
<<Limited:?DELIMIT/binary, _/binary>> = Item,
<<Limited/binary, "...">>;
delimited(Item) ->
Item.
More information about the erlang-questions
mailing list