CatCore

Text Mode

How to use text mode.

First, let's start by just outputting some text:

CatCore.text("Hello, World!");
$CatCore->text("Hello, World!");
CatCore.text("Hello, World!")

This was easy! And for multiple lines just use \n or anything else you would use normally.

You might want to customize this text. Here's an example of one of text's properties:

// Set value
CatCore.textOffset(16);

// Read value
var offset = CatCore.textOffset();
// Set value
$CatCore->textOffset(16);

// Read value
$offset = $CatCore->textOffset();
# Set value
CatCore.textOffset(16)

# Read value
offset = CatCore.textOffset()

This is just an example, here's the list of every single one, use them just as an example above:

ANSI

There's also one more function CatCore.enableANSI, which is a boolean. It controls whetever CatCore.text should parse and render ANSI escape sequences. Here's an example for you:

CatCore.enableANSI(true);
CatCore.text("This is \x1b[1mBOLD\x1b[0m!");
$CatCore->enableANSI(true);
$CatCore->text("This is \x1b[1mBOLD\x1b[0m!");
CatCore.enableANSI(true)
CatCore.text("This is \x1b[1mBOLD\x1b[0m!")

CatCore understands a lot of ANSI escape sequences: bold, dim/faint, italic, underline, inverted, striketrough, background and foreground colors (in 8/16/256/RGB color modes). Kitty image protocol and simillar are planned to be added in the future.

Keyboard Input

To make a terminal, user needs to not only read the output, but also input the commands! There's CatCore.keyboard object for that. Here's an example:

function keyholdHandler(event) {
  if (event.key == "Shift+Digit2") {
    // User pressed Shift + 2
  }
}

CatCore.keyboard.on("hold", keyholdHandler);
function $keyholdHandler($event) {
  if ($event->key == "Shift+Digit2") {
    // User pressed Shift + 2
  }
}

$CatCore->keyboard->on("hold", keyholdHandler);
def keyholdHandler(event)
  if event.key == "Shift+Digit2"
    # User pressed Shift + 2
  end
end

CatCore.keyboard.on("hold", keyholdHandler)

There's two events - hold and release, they trigger on user pressing and releasing the key.

When your callback gets called, it receives an event, which is an object:

Prop

Type

Knowing this, you can make a simple terminal:

// Variable to store last command outputs
var history = "";
// Variable to store current command that is being typed
var command = "";

// Render terminal on the screen
function renderTerminal() {
  CatCore.text(`${history}$ ${command}`);
}

function keyholdHandler(event) {
  if (event.key == "Enter") {
    // Split typed command into command itself and arguments
    var args = command.split(" ");
    var cmd = args.shift();
    // Execute the command
    switch(cmd) {
      case "test":
        history += `Test! You entered ${args.length} arguments.\n`;
        break;
      default:
        history += `Unknown command: ${cmd}.\n`;
    }
    command = "";
  } else if (event.key == "Backspace") {
    // Handle backspace to delete last character
    command = command.slice(0, -1);
  } else {
    // Add characters
    command += event.letter;
  }
  renderTerminal();
}
CatCore.keyboard.on("hold", keyholdHandler);

Work in Progress

Work in Progress

On this page