Last active
August 29, 2015 14:18
-
-
Save olexandr-konovalov/15d744ed1c0cb7aa3c39 to your computer and use it in GitHub Desktop.
Demonstration mode for GAP with coloured input and output.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ColorDemo := function( file ) | |
# | |
# This function provides a demonstration mode for GAP. To run a demo, | |
# read this function GAP and call it as | |
# | |
# ColorDemo("demofile.g"); | |
# | |
# where "demofile.g" is the name of your input file. The input file | |
# should contain only GAP input (no GAP prompts and no output). If | |
# you can run the input file by reading it into GAP or pasting it | |
# into the GAP session, then you should be able to run it in the | |
# demo mode. | |
# | |
# In the demo mode, GAP will run one command at a time, and display | |
# the input and the output. | |
# To continue to the next command, press <Enter>. | |
# To quit the demo, press 'q'. | |
# | |
# You will not be able to use demo mode if the GAP session is logged | |
# into a log file. First you would have to call LogTo() with no | |
# arguments to stop logging. | |
# | |
local input, keyboard, result; | |
input := InputTextFile( file ); | |
while input = fail do | |
Error( "Cannot open file ", file ); | |
od; | |
Print( "\nStart of demonstration.\n\n" ); | |
InputLogTo( "*stdout*" ); | |
keyboard := InputTextUser(); | |
# Use the following line in two places if you wish | |
# GAP prompt and input displayed in bold | |
# Print( "\033[1m\033[34m", "demo> \c", "\033[0m" ); | |
Print( "\033[34m", "demo> \c", "\033[0m" ); | |
while CHAR_INT( ReadByte( keyboard ) ) <> 'q' do | |
result:=READ_COMMAND( input, true ); # Executing the command. | |
if result <> SuPeRfail then | |
View(result); | |
Print("\n" ); | |
fi; | |
if IsEndOfStream( input ) then | |
break; | |
fi; | |
Print( "\033[34m", "demo> \c", "\033[0m" ); | |
od; | |
Print( "\nEnd of demonstration.\n\n", "\033[0m"); | |
CloseStream( keyboard ); | |
CloseStream( input ); | |
InputLogTo(); | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment