From e4de8af189735e2f6227898419bda7fdb50e35a2 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sun, 10 Nov 2024 02:39:20 -0800 Subject: [PATCH] add colors to node scanner example --- examples/node/package.json | 3 +++ examples/node/ts/scanner.ts | 14 +++++++++++++- yarn.lock | 5 +++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/examples/node/package.json b/examples/node/package.json index 3063869..70a5753 100644 --- a/examples/node/package.json +++ b/examples/node/package.json @@ -15,5 +15,8 @@ "build": "npx tsc", "lint": "yarn run eslint ./ts/*.ts && yarn run prettier ./ts/*.ts --check", "format": "yarn run prettier --write ./ts/*" + }, + "dependencies": { + "ansi-colors": "^4.1.3" } } diff --git a/examples/node/ts/scanner.ts b/examples/node/ts/scanner.ts index c9a3f09..4160f0a 100644 --- a/examples/node/ts/scanner.ts +++ b/examples/node/ts/scanner.ts @@ -1,6 +1,7 @@ import * as readline from "readline/promises"; import * as fs from "fs"; import * as timer from "timers/promises"; +import * as colors from "ansi-colors"; import { RF24, CrcLength, DataRate, FifoState } from "@rf24/rf24"; const io = readline.createInterface({ @@ -133,7 +134,18 @@ export class App { // finish printing current cache of signals for (let i = channel; i < CHANNELS; i++) { const total = caches[i]; - process.stdout.write(total > 0 ? total.toString(16) : "-"); + if (total == 0) { + process.stdout.write("-"); + } + else if (total < 5) { + process.stdout.write(colors.green(total.toString(16).toUpperCase())); + } + else if (total < 10) { + process.stdout.write(colors.yellow(total.toString(16).toUpperCase())); + } + else { + process.stdout.write(colors.red(total.toString(16).toUpperCase())); + } } } diff --git a/yarn.lock b/yarn.lock index 37fc14a..ba87490 100644 --- a/yarn.lock +++ b/yarn.lock @@ -298,6 +298,11 @@ ajv@^6.12.4: json-schema-traverse "^0.4.1" uri-js "^4.2.2" +ansi-colors@^4.1.3: + version "4.1.3" + resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.3.tgz#37611340eb2243e70cc604cad35d63270d48781b" + integrity sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw== + ansi-styles@^4.1.0: version "4.3.0" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.3.0.tgz#edd803628ae71c04c85ae7a0906edad34b648937"