[erlang-patches] [PATCH] [observer] Escape control characters in Table Viewer

Peti Gömöri gomoripeti@REDACTED
Wed Jun 13 18:43:10 CEST 2012


Similar behaviour to old tv.
Objects in tables supposed to be printed in a single line
and it looks ugly when a [...,10,...] integer list
creates a new-line.
---
 lib/observer/src/observer_tv_table.erl |   20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/lib/observer/src/observer_tv_table.erl
b/lib/observer/src/observer_tv_table.erl
index d339a85..97d18ec 100644
--- a/lib/observer/src/observer_tv_table.erl
+++ b/lib/observer/src/observer_tv_table.erl
@@ -762,7 +762,7 @@ format_tuple(_Tuple, 1, 0) ->
 format_list([]) -> "[]";
 format_list(List) ->
     case printable_list(List) of
-       true ->  io_lib:format("\"~ts\"", [List]);
+       true ->  io_lib:format("\"~ts\"", [map_printable_list(List)]);
        false -> [$[ | make_list(List)]
     end.

@@ -771,6 +771,24 @@ make_list([Last]) ->
 make_list([Head|Tail]) ->
     [format(Head), $,|make_list(Tail)].

+map_printable_list([$\n|Cs]) ->
+    [$\\, $n|map_printable_list(Cs)];
+map_printable_list([$\r|Cs]) ->
+    [$\\, $r|map_printable_list(Cs)];
+map_printable_list([$\t|Cs]) ->
+    [$\\, $t|map_printable_list(Cs)];
+map_printable_list([$\v|Cs]) ->
+    [$\\, $v|map_printable_list(Cs)];
+map_printable_list([$\b|Cs]) ->
+    [$\\, $b|map_printable_list(Cs)];
+map_printable_list([$\f|Cs]) ->
+    [$\\, $f|map_printable_list(Cs)];
+map_printable_list([$\e|Cs]) ->
+    [$\\, $e|map_printable_list(Cs)];
+map_printable_list([]) -> [];
+map_printable_list([C|Cs]) ->
+    [C|map_printable_list(Cs)].
+
 %% printable_list([Char]) -> bool()
 %%  Return true if CharList is a list of printable characters, else
 %%  false.
-- 
1.7.10.1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-patches/attachments/20120613/d2c1574f/attachment.htm>


More information about the erlang-patches mailing list