ok merci.
J'obtiens quelques résultats avec colorette mais tout ne fonctionne pas (pas de soulignement possible par exemple).
Sinon il semblerait que Chalk soit très utilisé (Comparison and Benchmarks of Node.js libraries to colorize text in terminal - DEV Community)
chalk
Donc j'ai fait installé Chalk et tenter un const { red, black, inverse, green, cyan, reset } = nativeRequire('chalk');
et j'obtiens l'erreur suivante :
(INFO) Custom module changed: N:\sonicpi\_2023-2024-college\documents\o-s-c\abletonOSC-custom-module.js
(INFO) Reloading custom module...
(ERROR) Custom module loading error
node:internal/modules/cjs/loader:1128
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
^
Error: Must use import to load ES Module: N:\sonicpi\_2023-2024-college\documents\o-s-c\node_modules\chalk\source\index.js
require() of ES modules is not supported.
require() of N:\sonicpi\_2023-2024-college\documents\o-s-c\node_modules\chalk\source\index.js from C:\Users\nlb\Downloads\open-stage-control_1.25.5_win32-x64 (2)\open-stage-control_1.25.5_win32-x64\resources\app\server\open-stage-control-server.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from N:\sonicpi\_2023-2024-college\documents\o-s-c\node_modules\chalk\package.json.
at new NodeError (node:internal/errors:370:5)
ansis
j'obtiens bien des couleurs mais tout ce qui est inversion ou avec un background ça ne marche pas
Ne marche pas non plus la lecture d'une variable avec les "Template literals"
console.log(`Beat : + {args[0].value}`);
console.log("Beat : " + args[0].value);
voici le code du custom module
function formatDate(date, format) {
const map = {
HH: date.getHours(),
mm: date.getMinutes(),
ss: date.getSeconds(),
ms: date.getMilliseconds(),
MM: date.getMonth() + 1,
dd: date.getDate(2),
yy: date.getFullYear().toString().slice(-2),
yyyy: date.getFullYear()
}
return format.replace(/ms|HH|mm|ss|MM|dd|yy|yyyy/gi, matched => map[matched])
}
function displayTime() {
console.log(colours.fg.yellow, colours.bg.white, formatDate(new Date(), '>> HH:mm:ss'), colours.reset);
}
const colours = {
reset: "\x1b[0m",
bright: "\x1b[1m",
dim: "\x1b[2m",
underscore: "\x1b[4m",
blink: "\x1b[5m",
reverse: "\x1b[7m",
hidden: "\x1b[8m",
fg: {
black: "\x1b[30m",
red: "\x1b[31m",
green: "\x1b[32m",
yellow: "\x1b[33m",
blue: "\x1b[34m",
magenta: "\x1b[35m",
cyan: "\x1b[36m",
white: "\x1b[37m",
gray: "\x1b[90m",
},
bg: {
black: "\x1b[40m",
red: "\x1b[41m",
green: "\x1b[42m",
yellow: "\x1b[43m",
blue: "\x1b[44m",
magenta: "\x1b[45m",
cyan: "\x1b[46m",
white: "\x1b[47m",
gray: "\x1b[100m",
crimson: "\x1b[48m"
}
};
// https://github.com/webdiscus/ansis
const { red, black, inverse, green, cyan, reset } = nativeRequire('ansis/colors');
// chalk ne marche pas erreur au chargement
// const { red, black, inverse, green, cyan, reset } = nativeRequire('chalk');
// const { blue, bold, underline, red } = nativeRequire('colorette');
module.exports = {
oscInFilter: (data)=>{
if (data.address === '/live/song/beat') {
console.log( green`Hello ${inverse`ANSI`} World!
${black.bgYellow`Warning:`} ${cyan`/path/to/file.js`} ${red`not found!`}`);
console.log(cyan("Total: $%f"), 1.99)
/*
console.log(blue("En bleu")) //=> \x1b[34mI'm blue\x1b[39m
console.log(red(`Red Shirt ${blue("Blue Shirt")} Red Shirt`))
console.log(`
There's a ${underline(blue("house"))},
With a ${bold(blue("window"))},
And a ${blue("corvette")}
And everything is blue`)
*/
var {address, args, host, port} = data
displayTime();
console.log(`Beat : + {args[0].value}`);
console.log("Beat : " + args[0].value);
// console.log(colours.fg.yellow, colours.bg.white, `{new Date()} > Beat : + {args[0].value}`, colours.reset);
}
// rediriger vers un port toutes les data reçues sur le port OSC pour par exemple le monitorer via Protokol
send('127.0.0.1', 11001, data.address, ...data.args)
// traduire la requete WIP
if (data.address === '/live/track/get/volume') {
data.address = '/live/track/set/volume'
}
return data
}
}
ps : je crois que j'ai mis un sacré bazar dans le post vu le sujet d'origine. Peut-être créer un post How to color the console ?