Navigation
« »

English | Español | Deutsch | Português | Cymraeg

JS-Terminal

Ein in JavaScript geschriebenes Retro-Terminalfenster.















README

JS-Terminal

A retro terminal window written in JavaScript.

Initialization

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) ;
}

Built-in commands

All commands that accept arguments support "strings of text", (expression evaluation), and $variables.

  • (number) - Add a line to the stored program
    • lineNumber expression
    • Example: 10 PRINT HELLO WORLD
  • ADD - Add two numbers together
    • Example: ADD 5 7
  • ALIAS - List, recall, or delete saved aliases
  • ASSIGN - Assign value to a named variable
    • ASSIGN value TO variable
    • ASSIGN (expression) TO variable
    • ASSIGN "string of text" TO variable
  • CLR - Clear the screen
  • COLOR - Set terminal text output color
    • COLOR [WHITE|BLUE|RED|GREEN|YELLOW|PURPLE]
  • DELETE - Delete a line in the stored program
    • DELETE lineNumber
  • DIVIDE - Divide the first number by the second number
    • Example: DIVIDE 10 4
  • DOWNLOAD - Download the stored program as a text file
  • EXIT - Exit out of input loop
  • EXP - Exponentiate a base by a factor
    • Example: EXP 2 10
  • GOTO - Go to a specified line number during stored program execution
    • Note: does nothing when executed as a standalone command
    • Example: 20 GOTO 10
  • GT - Determine if operand on left is greater than operand on right
    • Example: GT 2 10
  • INPUT - Accept user input and assign it to a variable
    • Example: INPUT -U -P "CONTINUE? (Y/N)" USERINPUT
  • LOGARITHM - Determine logarithm an argument by a base (default base is e)
    • Example: LOGARITHM 8 2
  • LT - Determine if operand on left is less than operand on right
    • Example: LT 2 10
  • MOVE - Move a line in the stored program to another line
    • MOVE oldLineNumber newLineNumber
  • HELP - Print help text
    • HELP [CMD]
  • LIST - Print the stored program
  • MULTIPLY - Multiply two numbers together
    • Example: MULTIPLY 10 10
  • PRINT - Print a string of text
    • PRINT [TEXT TO PRINT...]
  • RESET - Delete the stored program and reset the terminal
  • RND - Generate a random number between 0 and [MAX] (default 10)
    • RND [MAX]
  • RUN - Execute the stored program
  • SAVE - Save the current stored program as an alias
  • SETCURSOR - Set the terminal cursor position
    • SETCURSOR X Y
  • SQRT - Root a radicand by a base (default base is 2)
    • Example: SQRT 9 2
  • SUBTRACT - Subtract the second number from the first number
    • Example: SUBTRACT 10 3
  • SYSTEM - Print a system property
    • Available properties: ROWS, COLS, X, Y, STATUS, DEBUG, PROMPT
    • Example: SYSTEM ROWS
  • UNASSIGN - Remove an assigned variable
  • VARS - List all declared variables

Additional commands

Additional 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
  }
}) ;

Schreibe einen Kommentar