DEV Community

Cover image for node.js: Text Positioning 101
Gergő Móricz
Gergő Móricz

Posted on

node.js: Text Positioning 101

Yesterday, we covered text coloring, but today is more interesting. We are positioning text.

The way to do it is another magic string. This time it is this:

console.log("\x1b[10;15H%s", "Hello World!");
Enter fullscreen mode Exit fullscreen mode

This would print "Hello World!" on the screen's 10th row, starting at the 15th column.

See, the formula is basically this:

Enter fullscreen mode Exit fullscreen mode

You just need to change "r" to the specified row and "c" to the specified column, and boom! You just positioned text.

Discussion (0)