A retro terminal window written in JavaScript.
Include the two JavaScript dependencies. These require jQuery 3.6.0+.
<script src="js/terminal.js"></script>
<script src="js/commands.js"></script>
Initialize the terminal window with the specified number of rows and columns and the specified timeout interval (in milliseconds) that determines the speed at which each character is displayed on the terminal (0
for no delay).
try {
let terminal = new JSTerminal(
numRows,
numColumns,
defaultTimeout,
{
promptChar, // default: "$"
printPath, // default: true
printAccount, // default: true
autoPauseOnOverflow, // default: true
debugMode // default: false
}
);
registerDefaultCommands(terminal);
await terminal.startInputLoop() ;
} catch(e) {
console.error(e) ;
}
All commands that accept arguments support "strings of text"
, (expression evaluation)
, and $variables
.
(number)
- Add a line to the stored programlineNumber expression
10 PRINT HELLO WORLD
ADD
- Add two numbers togetherADD 5 7
ALIAS
- List, recall, or delete saved aliasesASSIGN
- Assign value to a named variableASSIGN value TO variable
ASSIGN (expression) TO variable
ASSIGN "string of text" TO variable
CLR
- Clear the screenCOLOR
- Set terminal text output colorCOLOR [WHITE|BLUE|RED|GREEN|YELLOW|PURPLE]
DELETE
- Delete a line in the stored programDELETE lineNumber
DIVIDE
- Divide the first number by the second numberDIVIDE 10 4
DOWNLOAD
- Download the stored program as a text fileEXIT
- Exit out of input loopEXP
- Exponentiate a base by a factorEXP 2 10
GOTO
- Go to a specified line number during stored program execution20 GOTO 10
GT
- Determine if operand on left is greater than operand on rightGT 2 10
INPUT
- Accept user input and assign it to a variableINPUT -U -P "CONTINUE? (Y/N)" USERINPUT
LOGARITHM
- Determine logarithm an argument by a base (default base is e)LOGARITHM 8 2
LT
- Determine if operand on left is less than operand on rightLT 2 10
MOVE
- Move a line in the stored program to another lineMOVE oldLineNumber newLineNumber
HELP
- Print help textHELP [CMD]
LIST
- Print the stored programMULTIPLY
- Multiply two numbers togetherMULTIPLY 10 10
PRINT
- Print a string of textPRINT [TEXT TO PRINT...]
RESET
- Delete the stored program and reset the terminalRND
- Generate a random number between 0
and [MAX]
(default 10
)RND [MAX]
RUN
- Execute the stored programSAVE
- Save the current stored program as an aliasSETCURSOR
- Set the terminal cursor positionSETCURSOR X Y
SQRT
- Root a radicand by a base (default base is 2)SQRT 9 2
SUBTRACT
- Subtract the second number from the first numberSUBTRACT 10 3
SYSTEM
- Print a system propertyROWS, COLS, X, Y, STATUS, DEBUG, PROMPT
SYSTEM ROWS
UNASSIGN
- Remove an assigned variableVARS
- List all declared variablesAdditional commands may be added using registerCmd()
.
async function testCmd(args) {
await this.println("This is a test command; here are your args: " + args.slice(1).join(", ")) ;
return "" ;
}
async function testCmdTab(args) {
return args[0] + " TEST_COMPLETION" ;
}
terminal.registerCmd( "TEST", {
args: [ "args" ],
callback: testCmd.bind(terminal),
ontab: testCmdTab.bind(terminal),
help: {
location: "./man/help.json",
hide: false,
program: false
}
}) ;