Last active
February 23, 2020 07:13
-
-
Save MKRhere/b1c6bd1e716e80cc68906396f0e7f83c to your computer and use it in GitHub Desktop.
A commandline widget to run neofetch on watch mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env node | |
const child = require("child_process"); | |
const readline = require("readline"); | |
const { promisify } = require("util"); | |
const getLines = () => | |
String( | |
child.execSync("neofetch --config ~/.mkr/config/neofetch.conf --off"), | |
) | |
.split("\n") | |
.slice(0, -3); | |
const [cursorTo, clearLine] = ["cursorTo", "clearLine"].map(f => (...args) => | |
promisify(readline[f])(process.stdout, ...args), | |
); | |
const cache = []; | |
const writeY = async (chunk, y) => { | |
if (cache[y] === chunk) return; | |
cache[y] = chunk; | |
await cursorTo(0, y); | |
await clearLine(0); | |
process.stdout.write(chunk + "\n"); | |
}; | |
console.clear(); | |
console.log(getLines().join("\n")); | |
setInterval(async () => { | |
const lines = getLines(); | |
let i = 0; | |
for (const line of lines) { | |
if (line) await writeY(line, i); | |
i += 1; | |
} | |
}, process.env.INTERVAL || 1000); | |
process.on("SIGINT", async () => { | |
// cleanup our mess | |
console.clear(); | |
process.exit(); | |
}); | |
process.stdout.on("resize", () => { | |
const lines = getLines(); | |
console.clear(); | |
console.log(lines.join("\n")); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment