|
|
@ -30,7 +30,7 @@ |
|
|
|
|
|
|
|
-spec fwrite(Format :: io:format(), Data :: [term()]) -> eFmt:chars(). |
|
|
|
fwrite(Format, Args) -> |
|
|
|
build(scan(Format, Args)). |
|
|
|
build(scan(Format, Args), []). |
|
|
|
|
|
|
|
-spec fwrite(Format :: io:format(), Data :: [term()], Options :: [{'chars_limit', CharsLimit :: integer()}]) -> eFmt:chars(). |
|
|
|
fwrite(Format, Args, Options) -> |
|
|
@ -56,7 +56,7 @@ doCollect(FmtBinStr, Args, Acc) -> |
|
|
|
[NotMatch] -> |
|
|
|
[NotMatch | Acc]; |
|
|
|
[FPart, LPart] -> |
|
|
|
doCollWidth(LPart, Args, 0, left, [FPart | Acc]) |
|
|
|
doCollWidth(LPart, Args, 0, right, [FPart | Acc]) |
|
|
|
end. |
|
|
|
|
|
|
|
doCollWidth(<<>>, _Args, _Width, _Adjust, Acc) -> |
|
|
@ -79,7 +79,7 @@ doCollWidth(LPart, Args, Width, Adjust, Acc) -> |
|
|
|
_ -> |
|
|
|
case Width == 0 of |
|
|
|
true -> |
|
|
|
doCollPrecision(LPart, Args, none, Adjust, Acc); |
|
|
|
doCollPrecision(LPart, Args, none, left, Acc); |
|
|
|
_ -> |
|
|
|
doCollPrecision(LPart, Args, Width, Adjust, Acc) |
|
|
|
end |
|
|
@ -102,7 +102,7 @@ doCollPrecision(LPart, Args, Width, Adjust, Precision, Acc) -> |
|
|
|
<<PrecisionInt:8/integer, LeftLPart/binary>> -> |
|
|
|
case PrecisionInt >= $0 andalso PrecisionInt =< $9 of |
|
|
|
true -> |
|
|
|
doCollPrecision(LeftLPart, Args, Width, Adjust, 10 * Precision + (PrecisionInt - $0)); |
|
|
|
doCollPrecision(LeftLPart, Args, Width, Adjust, 10 * Precision + (PrecisionInt - $0), Acc); |
|
|
|
_ -> |
|
|
|
case Precision == 0 of |
|
|
|
true -> |
|
|
@ -144,6 +144,7 @@ doCollStrings(LPart, Args, Width, Adjust, Precision, PadChar, Encoding, Acc) -> |
|
|
|
|
|
|
|
doCollCA(LPart, Args, Width, Adjust, Precision, PadChar, Encoding, Strings, Acc) -> |
|
|
|
<<CtlChar:8/integer, LeftLPart/binary>> = LPart, |
|
|
|
io:format("IMY*********************doCollCA:~p~p~n", [CtlChar, LPart]), |
|
|
|
case CtlChar of |
|
|
|
$w -> [OneArgs | LeftArgs] = Args, As = OneArgs, NextArgs = LeftArgs; |
|
|
|
$p ->[OneArgs | LeftArgs] = Args, As = OneArgs, NextArgs = LeftArgs; |
|
|
@ -165,6 +166,7 @@ doCollCA(LPart, Args, Width, Adjust, Precision, PadChar, Encoding, Strings, Acc) |
|
|
|
$i ->[OneArgs | LeftArgs] = Args, As = OneArgs, NextArgs = LeftArgs |
|
|
|
end, |
|
|
|
FmtSpec = #fmtSpec{ctlChar = CtlChar, args = As, width = Width, adjust = Adjust, precision = Precision, padChar = PadChar, encoding = Encoding, strings = Strings}, |
|
|
|
io:format("IMY***************~p~n", [FmtSpec]), |
|
|
|
doCollect(LeftLPart, NextArgs, [FmtSpec | Acc]). |
|
|
|
|
|
|
|
%% Build the output text for a pre-parsed format list. |
|
|
@ -177,10 +179,11 @@ build(Cs, Options) -> |
|
|
|
CharsLimit = getOpt(chars_limit, Options, -1), |
|
|
|
ResList = buildSmall(Cs, []), |
|
|
|
{P, S, W, Other} = cntSmall(ResList, 0, 0, 0, 0), |
|
|
|
case P + S + W of |
|
|
|
NumOfLimited = P + S + W, |
|
|
|
case NumOfLimited of |
|
|
|
0 -> |
|
|
|
ResList; |
|
|
|
NumOfLimited -> |
|
|
|
_ -> |
|
|
|
RemainChars = remainChars(CharsLimit, Other), |
|
|
|
buildLimited(ResList, P, NumOfLimited, RemainChars, 0, []) |
|
|
|
end. |
|
|
@ -351,13 +354,17 @@ term(BinStrOrIoList, Width, Adjust, Precision, PadChar) -> |
|
|
|
adjust(Adjust, BinStrOrIoList, makePadChars(PadChar, Precision - StrLen, <<>>)) |
|
|
|
end; |
|
|
|
true -> |
|
|
|
io:format("IMY****************1111 ~p ~n", [PadChar]), |
|
|
|
StrLen = eFmt:charsLen(BinStrOrIoList), |
|
|
|
NewPrecision = erlang:min(StrLen, case Precision of none -> Width; _ -> min(Precision, Width) end), |
|
|
|
if |
|
|
|
StrLen > NewPrecision -> |
|
|
|
adjust(Adjust, makePadChars($*, NewPrecision, <<>>), makePadChars(PadChar, Width - NewPrecision, <<>>)); |
|
|
|
true -> |
|
|
|
adjust(Adjust, BinStrOrIoList, makePadChars(PadChar, Width - StrLen, <<>>)) |
|
|
|
io:format("IMY****************22222~p ~p ~n", [BinStrOrIoList, PadChar]), |
|
|
|
A = adjust(Adjust, BinStrOrIoList, makePadChars(PadChar, Width - StrLen, <<>>)), |
|
|
|
io:format("IMY****************333 ~p ~p ~n", [A, PadChar]), |
|
|
|
A |
|
|
|
end |
|
|
|
end. |
|
|
|
|
|
|
@ -365,19 +372,38 @@ term(BinStrOrIoList, Width, Adjust, Precision, PadChar) -> |
|
|
|
%% Indentation) |
|
|
|
%% Print a term. Field width sets maximum line length, Precision sets |
|
|
|
%% initial indentation. |
|
|
|
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, |
|
|
|
Options = [ |
|
|
|
{chars_limit, CharsLimit}, |
|
|
|
{column, Precision}, |
|
|
|
{line_length, Width}, |
|
|
|
{depth, Depth}, |
|
|
|
{encoding, Encoding}, |
|
|
|
{strings, Strings} |
|
|
|
], |
|
|
|
io_lib_pretty:print(Term, Options). |
|
|
|
|
|
|
|
print(Term, Options) when is_list(Options) -> |
|
|
|
Col = get_option(column, Options, 1), |
|
|
|
Ll = get_option(line_length, Options, 80), |
|
|
|
D = get_option(depth, Options, -1), |
|
|
|
M = get_option(line_max_chars, Options, -1), |
|
|
|
T = get_option(chars_limit, Options, -1), |
|
|
|
RecDefFun = get_option(record_print_fun, Options, no_fun), |
|
|
|
Encoding = get_option(encoding, Options, epp:default_encoding()), |
|
|
|
Strings = get_option(strings, Options, true), |
|
|
|
print(Term, Col, Ll, D, M, T, RecDefFun, Encoding, Strings); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(T, D, none, Adj, P, Pad, E, Str, ChLim, I) -> |
|
|
|
print(T, D, 80, Adj, P, Pad, E, Str, ChLim, I); |
|
|
|
print(T, D, F, Adj, none, Pad, E, Str, ChLim, I) -> |
|
|
|
print(T, D, F, Adj, I + 1, Pad, E, Str, ChLim, I); |
|
|
|
print(T, D, F, right, P, _Pad, Enc, Str, ChLim, _I) -> |
|
|
|
Options = [{chars_limit, ChLim}, |
|
|
|
{column, P}, |
|
|
|
{line_length, F}, |
|
|
|
{depth, D}, |
|
|
|
{encoding, Enc}, |
|
|
|
{strings, Str}], |
|
|
|
eFmt_pretty:print(T, Options). |
|
|
|
|
|
|
|
floatE(Float, Width, Adjust, Precision, PadChar) -> |
|
|
|
case Precision of |
|
|
@ -475,10 +501,10 @@ strField(Str, Width, Adjust, StrLen, PadChar, Encoding) when StrLen > Width -> |
|
|
|
flatTrunc(List, Width, _Encoding) -> |
|
|
|
binary:part(iolist_to_binary(List), 0, Width). |
|
|
|
|
|
|
|
makePadChars(Char, Cnt, BinStr) -> |
|
|
|
makePadChars(PadChar, Cnt, BinStr) -> |
|
|
|
case Cnt > 0 of |
|
|
|
true -> |
|
|
|
makePadChars(Cnt - 1, Char, <<BinStr/binary, (integer_to_binary(Char))/binary>>); |
|
|
|
makePadChars(PadChar, Cnt - 1, <<BinStr/binary, PadChar:8>>); |
|
|
|
_ -> |
|
|
|
BinStr |
|
|
|
end. |
|
|
@ -533,7 +559,7 @@ prefixedInt(Int, Width, Adjust, Base, PadChar, Prefix, Prefix2, Lowercase) -> |
|
|
|
char(Char, Width, Adjust, Precision, PadChar) -> |
|
|
|
if |
|
|
|
Width == none andalso Precision == none -> |
|
|
|
integer_to_binary(Char); |
|
|
|
Char; |
|
|
|
Precision == none -> |
|
|
|
makePadChars(Char, Width, <<>>); |
|
|
|
Width == none -> |
|
|
@ -589,7 +615,7 @@ toUpperStr(BinStr) -> |
|
|
|
<<C>> |
|
|
|
end |
|
|
|
end || <<C:8>> <= BinStr |
|
|
|
>>. |
|
|
|
>>. |
|
|
|
|
|
|
|
toBinary(Value) when is_integer(Value) -> integer_to_binary(Value); |
|
|
|
toBinary(Value) when is_list(Value) -> list_to_binary(Value); |
|
|
|