nx.js

Console

Logging to the Console for text based applications

If your application is purely text-based, you can use the familiar global console object to write textual data to the screen of the application in the terminal-like interface that libnx provides.

Tip

To draw more intricate graphics, your application should use canvas rendering mode.

Example

src/main.ts
console.log('Hello World!');
console.log(' - <3 nx.js');
console.log('');
console.log('Press the + button to exit...');
Screenshot

ANSI Escape Codes

Listed below is a (non-exhaustive) list of npm modules known to work well with nx.js when using console rendering mode:

  • kluer - Output colored text with ANSI escape codes
  • sisteransi - ANSI escape sequences for moving the cursor

Limitations

It is worth noting that the terminal interface that libnx provides has dimensions of 80 x 45 characters, supports a limited set of unicode characters, and provides no customization options for the appearance of the text.

There is a work-in-progress @nx.js/terminal package (see #112), which will provide a more full-featured terminal interface powered by xterm.js, which will allow for more control over the visual appearance of your application.

On this page