'How can I change the Colours of a Character at Cursor Position in a node.js Console/Terminal Application?
This question is not concerned with how to define and print out text in colour in node.js.
I'd like to know whether it's possible, most likely by using the readline/stdout stream, to change the colour of the character at the current cursor position.
Lets say I place the cursor at col 10, row 10 e.g. with readline:
const readline = require('readline');
const rl = readline.createInterface({
input: inputStream,
output: outputStream,
});
readline.cursorTo(process.stdout, 1, 1);
const whiteOnRed = '\x1b[38;5;15mx1b[48;5;1mTEST_OUT\n';
process.stdout.write(whiteOnRed);
readline.cursorTo(process.stdout, 1, 1);
// Here I'd like to change the color of the
// first character of TEST_OUT, which is a "T"
// and change it to yellow foreground and blue
// background which is
// \x1b[38;5;11mx1b[48;5;4m
I've placed this example, just clarify the problem and to prevent getting comments how to set TTY colours. I know how they work.
I'd like to find out, how to change colours, after they have been assigned to a character/glyph position.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
