Skip to content

Commit 36e8a65

Browse files
Extend StreamFormatting to seperate linewrap and indenting
1 parent 3683acb commit 36e8a65

File tree

5 files changed

+159
-93
lines changed

5 files changed

+159
-93
lines changed

lib/custom_streams.gi

+3-6
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,8 @@ InstallMethod( PrintFormattingStatus, "output text custom",
343343
##
344344
InstallMethod( SetPrintFormattingStatus, "output text custom",
345345
[IsOutputTextCustomRep and IsOutputTextStream,
346-
IsBool],
346+
IsObject],
347347
function( str, stat)
348-
if stat = fail then
349-
Error("Print formatting status must be true or false");
350-
else
351-
str!.formatting := stat;
352-
fi;
348+
CheckValidPrintFormattingStatus(stat);
349+
str!.formatting := stat;
353350
end);

lib/streams.gd

+3-1
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ DeclareGlobalFunction( "InputOutputLocalProcess" );
10071007
## </ManSection>
10081008
## <#/GAPDoc>
10091009
##
1010-
DeclareOperation( "SetPrintFormattingStatus", [IsOutputStream, IsBool] );
1010+
DeclareOperation( "SetPrintFormattingStatus", [IsOutputStream, IsObject] );
10111011
DeclareOperation( "PrintFormattingStatus", [IsOutputStream] );
10121012

10131013

@@ -1251,3 +1251,5 @@ DeclareGlobalFunction( "InputFromUser" );
12511251
## <#/GAPDoc>
12521252
##
12531253
DeclareGlobalFunction( "OpenExternal" );
1254+
1255+
DeclareGlobalFunction( "CheckValidPrintFormattingStatus");

lib/streams.gi

+27-20
Original file line numberDiff line numberDiff line change
@@ -929,13 +929,10 @@ InstallMethod( PrintFormattingStatus, "output text string",
929929
##
930930
InstallMethod( SetPrintFormattingStatus, "output text string",
931931
[IsOutputTextStringRep and IsOutputTextStream,
932-
IsBool],
932+
IsObject],
933933
function( str, stat)
934-
if stat = fail then
935-
Error("Print formatting status must be true or false");
936-
else
937-
str![2] := stat;
938-
fi;
934+
CheckValidPrintFormattingStatus(stat);
935+
str![2] := stat;
939936
end);
940937

941938

@@ -1130,13 +1127,10 @@ InstallMethod( PrintFormattingStatus, "output text file",
11301127
##
11311128
InstallMethod( SetPrintFormattingStatus, "output text file",
11321129
[IsOutputTextFileRep and IsOutputTextStream,
1133-
IsBool],
1130+
IsObject],
11341131
function( str, stat)
1135-
if stat = fail then
1136-
Error("Print formatting status must be true or false");
1137-
else
1138-
str![3] := stat;
1139-
fi;
1132+
CheckValidPrintFormattingStatus(stat);
1133+
str![3] := stat;
11401134
end);
11411135

11421136
## formatting status for stdout or current output
@@ -1151,7 +1145,7 @@ function(str)
11511145
fi;
11521146
end);
11531147

1154-
InstallOtherMethod( SetPrintFormattingStatus, "for stdout", [IsString, IsBool],
1148+
InstallOtherMethod( SetPrintFormattingStatus, "for stdout", [IsString, IsObject],
11551149
function(str, status)
11561150
if str = "*stdout*" then
11571151
SET_PRINT_FORMATTING_STDOUT(status);
@@ -1255,9 +1249,7 @@ InstallMethod( SetPrintFormattingStatus, "output text none",
12551249
[IsOutputTextNoneRep and IsOutputTextNone,
12561250
IsBool],
12571251
function( str, stat)
1258-
if stat = fail then
1259-
Error("Print formatting status must be true or false");
1260-
fi;
1252+
CheckValidPrintFormattingStatus(stat);
12611253
end);
12621254

12631255

@@ -1676,14 +1668,29 @@ InstallMethod( SetPrintFormattingStatus, "for non-text output stream",
16761668
TryNextMethod();
16771669
fi;
16781670

1679-
if stat = true then
1680-
Error("non-text streams support onlyPrint formatting status false");
1681-
elif stat = fail then
1682-
Error("Print formatting status must be true or false");
1671+
CheckValidPrintFormattingStatus(stat);
1672+
if (( IsBool(stat) and stat = true ) or
1673+
( IsRecord(stat) and (stat.linewrap or stat.indent) ) ) then
1674+
Error("non-text streams do not support print formatting");
16831675
fi;
16841676
end);
16851677

16861678

1679+
InstallGlobalFunction( "CheckValidPrintFormattingStatus",
1680+
function(fs)
1681+
if IsBool(fs) then
1682+
if fs = fail then
1683+
Error("Formatting status cannot be 'fail'");
1684+
fi;
1685+
elif IsRecord(fs) then
1686+
if Set(RecNames(fs)) <> ["indent", "linewrap"] then
1687+
Error("Formatting status records must only contain 'indent' and 'linewarp'");
1688+
fi;
1689+
else
1690+
Error("Formatting status must be a Boolean or a Record");
1691+
fi;
1692+
end);
1693+
16871694
#############################################################################
16881695
##
16891696
#M FileDescriptorOfStream( <iostream-by-pty> )

0 commit comments

Comments
 (0)