From 29222a138e1b7dc640b6b467ad0d74a0636fd45c Mon Sep 17 00:00:00 2001 From: SisMaker <1713699517@qq.com> Date: Mon, 22 Feb 2021 01:05:15 +0800 Subject: [PATCH] =?UTF-8?q?ft:=E6=A8=A1=E5=9D=97=E8=9E=8D=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/eFmt.erl | 38 +++++++++++++++++++++++--------------- src/eFmtPretty.erl | 12 ++++-------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/eFmt.erl b/src/eFmt.erl index a957610..af2a323 100644 --- a/src/eFmt.erl +++ b/src/eFmt.erl @@ -487,12 +487,12 @@ ctlLimited($s, Args, Width, Adjust, Precision, PadChar, Encoding, _Strings, Char case Encoding of latin1 -> BinStr = erlang:iolist_to_binary(Args); - _ -> - BinStr = case catch unicode:characters_to_binary(Args, unicode) of - Str when is_binary(Str) -> Str; - _ -> toBinary(Args) - end + BinStr = + case catch unicode:characters_to_binary(Args, unicode) of + Str when is_binary(Str) -> Str; + _ -> toBinary(Args) + end end, TemBinStr = strToChars(BinStr, Width, CharsLimit), string(TemBinStr, ?IIF(CharsLimit < 0 orelse Width =:= none, Width, max(3, min(Width, CharsLimit))), Adjust, Precision, PadChar, Encoding); @@ -533,14 +533,21 @@ term(BinStrOrIoList, Width, Adjust, Precision, PadChar) -> print(Term, Depth, Width, _Adjust, Precision, _PadChar, Encoding, Strings, CharsLimit, I) -> if - Width == none -> NewWidth = 80; - true -> NewWidth = Width - end, - if - Precision == none -> NewPrecision = I + 1; - true -> NewPrecision = Precision - end, - eFmtPretty:print(Term, NewPrecision, NewWidth, Depth, -1, CharsLimit, no_fun, Encoding, Strings). + Width == none -> + if + Precision == none -> + eFmtPretty:print(Term, I + 1, 80, Depth, -1, CharsLimit, no_fun, Encoding, Strings); + true -> + eFmtPretty:print(Term, Precision, 80, Depth, -1, CharsLimit, no_fun, Encoding, Strings) + end; + true -> + if + Precision == none -> + eFmtPretty:print(Term, I + 1, Width, Depth, -1, CharsLimit, no_fun, Encoding, Strings); + true -> + eFmtPretty:print(Term, Precision, Width, Depth, -1, CharsLimit, no_fun, Encoding, Strings) + end + end. floatE(Float, Width, Adjust, Precision, PadChar) -> case Precision of @@ -609,8 +616,9 @@ string(Str, Width, Adjust, Precision, PadChar, Encoding) -> StrLen = charsLen(Str), if Width > Precision -> - if StrLen > Precision -> - adjust(Adjust, flatTrunc(Str, Precision, Encoding), makePadChars(PadChar, Width - Precision, <<>>)); + if + StrLen > Precision -> + adjust(Adjust, flatTrunc(Str, Precision, Encoding), makePadChars(PadChar, Width - Precision, <<>>)); StrLen < Precision -> adjust(Adjust, [Str | makePadChars(PadChar, Precision - StrLen, <<>>)], makePadChars(PadChar, Width - Precision, <<>>)); true -> % N == P diff --git a/src/eFmtPretty.erl b/src/eFmtPretty.erl index 28959cf..782b699 100644 --- a/src/eFmtPretty.erl +++ b/src/eFmtPretty.erl @@ -93,6 +93,8 @@ pPrint(Term, Col, Ll, D, M, RecDefFun) -> %% Col = current column, default 1 %% Ll = line length/~p field width, default 80 %% M = CHAR_MAX (-1 if no max, 60 when printing from shell) +%%Term, Precision, Width, Depth, -1, CharsLimit, no_fun, Encoding, Strings + print(_, _, _, 0, _M, _T, _RF, _Enc, _Str) -> "..."; print(_, _, _, _D, _M, 0, _RF, _Enc, _Str) -> "..."; print(Term, Col, Ll, D, M, T, RecDefFun, Enc, Str) when Col =< 0 -> @@ -100,10 +102,7 @@ print(Term, Col, Ll, D, M, T, RecDefFun, Enc, Str) when Col =< 0 -> print(Term, 1, Ll, D, M, T, RecDefFun, Enc, Str); print(Atom, _Col, _Ll, _D, _M, _T, _RF, Enc, _Str) when is_atom(Atom) -> write_atom(Atom, Enc); -print(Term, Col, Ll, D, M0, T, RecDefFun, Enc, Str) when is_tuple(Term); - is_list(Term); - is_map(Term); - is_bitstring(Term) -> +print(Term, Col, Ll, D, M0, T, RecDefFun, Enc, Str) when is_tuple(Term); is_list(Term); is_map(Term); is_bitstring(Term) -> %% preprocess and compute total number of chars {_, Len, _Dots, _} = If = case T < 0 of @@ -539,10 +538,7 @@ print_length(<<_/bitstring>> = Bin, 1, _T, RF, Enc, Str) -> print_length(<<_/bitstring>> = Bin, D, T, RF, Enc, Str) -> D1 = D - 1, case - Str andalso - (bit_size(Bin) rem 8) =:= 0 andalso - printable_bin0(Bin, D1, tsub(T, 6), Enc) - of + Str andalso (bit_size(Bin) rem 8) =:= 0 andalso printable_bin0(Bin, D1, tsub(T, 6), Enc) of {true, List} when is_list(List) -> S = io_lib:write_string(List, $"), %" {[$<, $<, S, $>, $>], 4 + length(S), 0, no_more};