Share your repls and programming experiences

← Back to all posts
Node.js Terminal Apps Library
timmy_i_chen (1088)

Terminal Apps Library

Link to repl:

I made a library, inspired by p5.js, for terminal apps using Node.js and's Repl Run.


Make sure you are logged in and explorer mode is enabled.


All edits will probably go in the app.js file. There are four main functions to edit:

  • setup() - this function is run once at the beginning of your program.
  • loop() - this function is continually run at an interval of your choosing. You can press esc at any time to end your program.
  • onKeyPress(key) - this function fires whenever a key is pressed. key is a string representing the key that was pressed.
  • onMouseClick(event) - this function fires whenever the mouse is clicked. The event object contains properties for the row, column, and scroll (direction the mouse was scrolling in, if any).

When running, be sure to run using repl run. This will be fixed later as we roll xterm out to more languages.


API Docs


sleep(ms) - pauses execution (in the containing function only) for ms ms

print(value) - prints value at the cursor location without a newline. Converts value to a string.

printDebug(output [, atRow, length]) - printing for debugging purposes. Prints output at atRow rows down, clearing length lines underneath as well. Objects are pretty printed, otherwise the value is converted to a string.

randomInt(low, high) - generates and returns a random integer between low and high inclusive.


Color values are ANSI escape sequences that set color. These are usually printed with a string.

colors.[colorname] - sets the terminal foreground (text) color for subsequent outputs. e.g., colors.cyan.

All color choices: black, red, green, yellow, blue, magenta, cyan, white[colorname] - sets the terminal background color for subsequent outputs, e.g.

colors.reset - resets colors to terminal defaults.


Even those all of these represent ANSI escape sequences, they do not need to be printed. Just calling the function will execute it.

cursor.goto(row, col) - moves the cursor to row, col.

cursor.gotoColumn(col) - move the cursor to the specified col in the current row.

cursor.down(amt) / cursor.up(amt) / cursor.left(amt) / cursor.right(amt) - moves the cursor down/up/left/right byamt` - saves the position of the cursor

cursor.restore() - moves the cursor back to its last saved position

cursor.hide() - hides the cursor - shows the cursor (if hidden)


screen.clear() - clears the screen

screen.reset() - clears the screen and moves the cursor back to (0, 0)

screen.getWidth() - returns the number of columns on the screen (only works after resizing)

screen.getHeight - returns the number of rows on the screen (only works after resizing)

screen.clearLineToEnd() - clears content starting from the character ending at the end of the current row.


async fileIO.readFile(fileName) - returns the file contents as a string

async fileIO.writeFile(fileName, content) - writes content to file fileName.

async fileIO.appendFile(fileName, content) - appends content to file fileName.


Hope you enjoyed it! Please feel free to fork and modify. If you make something cool with it, I'd love to see it - share it here or make it in another post (but tag me!)

hoodgail (0)

why cant i do node index.js