Skip to content

Commit

Permalink
Extend StreamFormatting to seperate linewrap and indenting
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisJefferson committed Dec 18, 2023
1 parent 25a58b0 commit 511c041
Show file tree
Hide file tree
Showing 7 changed files with 226 additions and 103 deletions.
9 changes: 3 additions & 6 deletions lib/custom_streams.gi
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,8 @@ InstallMethod( PrintFormattingStatus, "output text custom",
##
InstallMethod( SetPrintFormattingStatus, "output text custom",
[IsOutputTextCustomRep and IsOutputTextStream,
IsBool],
IsObject],
function( str, stat)
if stat = fail then
Error("Print formatting status must be true or false");
else
str!.formatting := stat;
fi;
CheckValidPrintFormattingStatus(stat);
str!.formatting := stat;
end);
4 changes: 3 additions & 1 deletion lib/streams.gd
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ DeclareGlobalFunction( "InputOutputLocalProcess" );
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "SetPrintFormattingStatus", [IsOutputStream, IsBool] );
DeclareOperation( "SetPrintFormattingStatus", [IsOutputStream, IsObject] );
DeclareOperation( "PrintFormattingStatus", [IsOutputStream] );


Expand Down Expand Up @@ -1259,3 +1259,5 @@ DeclareGlobalFunction( "InputFromUser" );
## <#/GAPDoc>
##
DeclareGlobalFunction( "OpenExternal" );

DeclareGlobalFunction( "CheckValidPrintFormattingStatus");
53 changes: 33 additions & 20 deletions lib/streams.gi
Original file line number Diff line number Diff line change
Expand Up @@ -929,13 +929,10 @@ InstallMethod( PrintFormattingStatus, "output text string",
##
InstallMethod( SetPrintFormattingStatus, "output text string",
[IsOutputTextStringRep and IsOutputTextStream,
IsBool],
IsObject],
function( str, stat)
if stat = fail then
Error("Print formatting status must be true or false");
else
str![2] := stat;
fi;
CheckValidPrintFormattingStatus(stat);
str![2] := stat;
end);


Expand Down Expand Up @@ -1130,13 +1127,10 @@ InstallMethod( PrintFormattingStatus, "output text file",
##
InstallMethod( SetPrintFormattingStatus, "output text file",
[IsOutputTextFileRep and IsOutputTextStream,
IsBool],
IsObject],
function( str, stat)
if stat = fail then
Error("Print formatting status must be true or false");
else
str![3] := stat;
fi;
CheckValidPrintFormattingStatus(stat);
str![3] := stat;

Check warning on line 1133 in lib/streams.gi

View check run for this annotation

Codecov / codecov/patch

lib/streams.gi#L1132-L1133

Added lines #L1132 - L1133 were not covered by tests
end);

## formatting status for stdout or current output
Expand All @@ -1151,7 +1145,7 @@ function(str)
fi;
end);

InstallOtherMethod( SetPrintFormattingStatus, "for stdout", [IsString, IsBool],
InstallOtherMethod( SetPrintFormattingStatus, "for stdout", [IsString, IsObject],
function(str, status)
if str = "*stdout*" then
SET_PRINT_FORMATTING_STDOUT(status);
Expand Down Expand Up @@ -1255,9 +1249,7 @@ InstallMethod( SetPrintFormattingStatus, "output text none",
[IsOutputTextNoneRep and IsOutputTextNone,
IsBool],
function( str, stat)
if stat = fail then
Error("Print formatting status must be true or false");
fi;
CheckValidPrintFormattingStatus(stat);

Check warning on line 1252 in lib/streams.gi

View check run for this annotation

Codecov / codecov/patch

lib/streams.gi#L1252

Added line #L1252 was not covered by tests
end);


Expand Down Expand Up @@ -1676,14 +1668,35 @@ InstallMethod( SetPrintFormattingStatus, "for non-text output stream",
TryNextMethod();
fi;

if stat = true then
Error("non-text streams support onlyPrint formatting status false");
elif stat = fail then
Error("Print formatting status must be true or false");
CheckValidPrintFormattingStatus(stat);
if stat = true or
( IsRecord(stat) and (stat.linewrap or stat.indent) ) then
Error("non-text streams do not support print formatting");

Check warning on line 1674 in lib/streams.gi

View check run for this annotation

Codecov / codecov/patch

lib/streams.gi#L1674

Added line #L1674 was not covered by tests
fi;
end);


InstallGlobalFunction( "CheckValidPrintFormattingStatus",
function(fs)
local r;
if IsBool(fs) then
if fs = fail then
Error("Formatting status cannot be 'fail'");

Check warning on line 1684 in lib/streams.gi

View check run for this annotation

Codecov / codecov/patch

lib/streams.gi#L1684

Added line #L1684 was not covered by tests
fi;
elif IsRecord(fs) then
if Set(RecNames(fs)) <> ["indent", "linewrap"] then
Error("Formatting status records must contain exactly two components named 'indent' and 'linewrap'");
fi;
for r in ["indent","linewrap"] do
if not fs.(r) in [false, true] then
Error(Concatenation(r, " must be a Boolean in Formatting status"));
fi;
od;
else
Error("Formatting status must be a boolean or a record");

Check warning on line 1696 in lib/streams.gi

View check run for this annotation

Codecov / codecov/patch

lib/streams.gi#L1686-L1696

Added lines #L1686 - L1696 were not covered by tests
fi;
end);

#############################################################################
##
#M FileDescriptorOfStream( <iostream-by-pty> )
Expand Down
Loading

0 comments on commit 511c041

Please sign in to comment.