@@ -929,13 +929,10 @@ InstallMethod( PrintFormattingStatus, "output text string",
929
929
# #
930
930
InstallMethod( SetPrintFormattingStatus, " output text string" ,
931
931
[ IsOutputTextStringRep and IsOutputTextStream,
932
- IsBool ] ,
932
+ IsObject ] ,
933
933
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;
939
936
end );
940
937
941
938
@@ -1130,13 +1127,10 @@ InstallMethod( PrintFormattingStatus, "output text file",
1130
1127
# #
1131
1128
InstallMethod( SetPrintFormattingStatus, " output text file" ,
1132
1129
[ IsOutputTextFileRep and IsOutputTextStream,
1133
- IsBool ] ,
1130
+ IsObject ] ,
1134
1131
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;
1140
1134
end );
1141
1135
1142
1136
# # formatting status for stdout or current output
@@ -1151,7 +1145,7 @@ function(str)
1151
1145
fi ;
1152
1146
end );
1153
1147
1154
- InstallOtherMethod( SetPrintFormattingStatus, " for stdout" , [ IsString, IsBool ] ,
1148
+ InstallOtherMethod( SetPrintFormattingStatus, " for stdout" , [ IsString, IsObject ] ,
1155
1149
function (str, status )
1156
1150
if str = " *stdout*" then
1157
1151
SET_PRINT_FORMATTING_STDOUT(status);
@@ -1255,9 +1249,7 @@ InstallMethod( SetPrintFormattingStatus, "output text none",
1255
1249
[ IsOutputTextNoneRep and IsOutputTextNone,
1256
1250
IsBool] ,
1257
1251
function ( str, stat )
1258
- if stat = fail then
1259
- Error(" Print formatting status must be true or false" );
1260
- fi ;
1252
+ CheckValidPrintFormattingStatus(stat);
1261
1253
end );
1262
1254
1263
1255
@@ -1676,14 +1668,29 @@ InstallMethod( SetPrintFormattingStatus, "for non-text output stream",
1676
1668
TryNextMethod ();
1677
1669
fi ;
1678
1670
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 " );
1683
1675
fi ;
1684
1676
end );
1685
1677
1686
1678
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
+
1687
1694
# ############################################################################
1688
1695
# #
1689
1696
# M FileDescriptorOfStream( <iostream-by-pty> )
0 commit comments