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 Oct 19, 2022
1 parent 3683acb commit 62ff897
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 93 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 @@ -1007,7 +1007,7 @@ DeclareGlobalFunction( "InputOutputLocalProcess" );
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "SetPrintFormattingStatus", [IsOutputStream, IsBool] );
DeclareOperation( "SetPrintFormattingStatus", [IsOutputStream, IsObject] );
DeclareOperation( "PrintFormattingStatus", [IsOutputStream] );


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

DeclareGlobalFunction( "CheckValidPrintFormattingStatus");
47 changes: 27 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;
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);
end);


Expand Down Expand Up @@ -1676,14 +1668,29 @@ 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 (( IsBool(stat) and stat = true ) or
( IsRecord(stat) and (stat.linewrap or stat.indent) ) ) then
Error("non-text streams do not support print formatting");
fi;
end);


InstallGlobalFunction( "CheckValidPrintFormattingStatus",
function(fs)
if IsBool(fs) then
if fs = fail then
Error("Formatting status cannot be 'fail'");
fi;
elif IsRecord(fs) then
if Set(RecNames(fs)) <> ["indent", "linewrap"] then
Error("Formatting status records must contain only 'indent' and 'linewrap'");
fi;
else
Error("Formatting status must be a Boolean or a Record");
fi;
end);

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

0 comments on commit 62ff897

Please sign in to comment.