Skip to content

Commit

Permalink
add colors to node scanner example
Browse files Browse the repository at this point in the history
  • Loading branch information
2bndy5 committed Nov 10, 2024
1 parent b285a70 commit e4de8af
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions examples/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
14 changes: 13 additions & 1 deletion examples/node/ts/scanner.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down Expand Up @@ -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()));
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit e4de8af

Please sign in to comment.