For the latest version check
here.
This is an easily expandable console system for debugging and scripting, supports syntax colouring, log creation, parameter parsing and more.
Rem ***** Included Source File *****
TYPE Shell_Console
Shellmode AS BOOLEAN
Lines AS BYTE
Cur_Line AS DWORD
ENDTYPE
TYPE Shell_ConsoleCMD
CMD AS STRING
Colour AS DWORD
ENDTYPE
GLOBAL CMD_line
GLOBAL tempvar
REM ***** Main Source File *****
REM ***** Initializes console *****
REM ***** Parameters *****
REM lines (byte) = number of lines required (determines y size)
FUNCTION Shell_InitConsole( lines AS BYTE )
tempvar=lines
GOSUB Shell_CMDSubroute
ENDFUNCTION
Shell_CMDSubroute:
Shell_Console AS SHELL_CONSOLE
DIM Shell_ConsoleCMD ( 0 ) AS Shell_ConsoleCMD
// IF Shell.Active=1 THEN Shell_Console.Shellmode=1
Shell_Console.Lines = tempvar
RETURN
REM ***** ENDFUNCTION *****
REM ***** Draws console *****
REM ***** Parameters *****
REM alpha (byte) = transparency of console
FUNCTION Shell_DrawConsole( alpha AS BYTE )
IF Shell_Console.Shellmode=0
INK RGB( 16 , 16 , 16 ) , 0 : BOX 0 , 0 , SCREEN WIDTH( ) , ( TEXT HEIGHT( "#" ) * (Shell_Console.Lines+3) )
INK RGB( 125 , 125 , 125 ) , 0 : BOX 0 , 0 , SCREEN WIDTH( ) , 10
BOX 0 , 0 , 5 , ( TEXT HEIGHT( "#" ) * (Shell_Console.Lines+3) )
BOX SCREEN WIDTH( )-5 , 0 , SCREEN WIDTH( ) , ( TEXT HEIGHT( "#" ) * (Shell_Console.Lines+3) )
BOX 0 , ( TEXT HEIGHT( "#" ) * (Shell_Console.Lines+3) )-10 , SCREEN WIDTH( ) , ( TEXT HEIGHT( "#" ) * (Shell_Console.Lines+3) )
IF CMD_line>0
IF CMD_line>Shell_Console.Lines
StartLine = CMD_line - Shell_Console.Lines
EndLine = StartLine + Shell_Console.Lines
ELSE
StartLine = 1
EndLine = CMD_line
ENDIF
FOR t = StartLine TO Endline
INC internalLine , 1
INK Shell_ConsoleCMD( t ).Colour , 0 : TEXT 10 , 0 + ( TEXT HEIGHT( "#" ) * internalLine ) , Shell_ConsoleCMD( t ).CMD
NEXT t
ENDIF
ENDIF
ENDFUNCTION
REM ***** ENDFUNCTION *****
REM ***** Writes to console *****
REM ***** Parameters *****
REM CMDtext (string) = text to write to console
REM colour (dword) = colour of text
FUNCTION Shell_WriteConsole( CMDtext AS STRING , colour AS DWORD )
ARRAY INSERT AT BOTTOM Shell_ConsoleCMD( 1 ) : INC CMD_line , 1
Shell_ConsoleCMD( CMD_line ).CMD = CMDtext
Shell_ConsoleCMD( CMD_line ).colour = colour
ENDFUNCTION
REM ***** ENDFUNCTION *****
REM ***** Exports the console to a .log file *****
REM ***** Parameters *****
REM CMD (byte) = command to check
FUNCTION Shell_ExportConsole( Path AS STRING )
Shell_WriteConsole("["+get time$()+"] Console Terminate" , RGB (255,255,255))
filenum=1
while file open(filenum)=1
INC filenum , 1
endwhile
n=1
repeat
if file exist(Path+fill_string(3-len(str$(n)),"0")+str$(n)+".log")=0 then exit
n=n+1
until n=999
temp$=Path+fill_string(3-len(str$(n)),"0")+str$(n)+".log"
open to write filenum,temp$
for t=1 to CMD_line
write string filenum,Shell_ConsoleCMD(t).CMD
next t
close file filenum
ENDFUNCTION
REM ***** ENDFUNCTION *****
function fill_string(temp,temp$)
return$=""
for n=1 to temp
return$=return$+temp$
next n
endfunction return$
REM ***** Exeutes command line *****
REM ***** Parameters *****
REM CMD (string) = command to execute
FUNCTION Shell_ExecuteCommandLine( CMD AS STRING )
CMD = lower$( CMD )
IF CMD = "engine_version"
Shell_WriteConsole( "0.001" , RGB(255,255,255) )
ENDIF
IF LEFT$(CMD , 12 ) = "print_number"
CMD = RIGHT$ ( CMD , LEN( CMD ) - 12 )
IF VAL( CMD ) > 0
Shell_WriteConsole( CMD , RGB(255,255,255) )
ELSE
error = 2
EXITFUNCTION error
ENDIF
ELSE
error = 1
EXITFUNCTION error
ENDIF
ENDFUNCTION error
REM ***** ENDFUNCTION *****
REM ***** CHecks command line *****
REM ***** Parameters *****
REM CMD (byte) = command to check
FUNCTION Shell_GetCommandLineError( CMD AS BYTE )
IF CMD = 1
Error$ = "SYntax Error - Unknown command"
EXITFUNCTION Error$
ENDIF
IF CMD = 2
Error$ = "Parameter Mismatch - PRINT_NUMBER expects INTEGER"
EXITFUNCTION Error$
ENDIF
ENDFUNCTION Error$
REM ***** ENDFUNCTION *****
Shell_InitConsole( lines AS BYTE )
Initializes the console system and sets the height.
Shell_DrawConsole( alpha AS BYTE )
Updates/Draws the console to screen - Alpha value is not needed
Shell_WriteConsole( CMDtext AS STRING , colour AS DWORD )
Writes to the console in the given colour
Shell_ExportConsole( Path AS STRING )
Exports the console as a .log file
Shell_ExecuteCommandLine( CMD AS STRING )
Executes command line (command specified in this function as CMD). This is where you add your own custom functions, parsing is fairly simple for single parameter functions. Can be used in conjunction with Shell_WriteConsole() to print debug data to console.
[Edit] Can a mod please put [DBP] in the title? Sorry for ommitting that one :S [/Edit]