A Node.js/TypeScript package for advanced console UI control with logging, colored output, input handling, key events, and progress bars.
A brief description of what this project does and who it's for
A npm package for console control.
Install interflow with npm
npm install interflow
import {Interflow} from 'interflow'
import {stdin, stdout} from 'node:process'
async function main() {
const interflow = new Interflow(stdin, stdout)
interflow.log("Hello World")
}
main()
Output
Hello World
const interflow = new Interflow(stdin, stdout)
await interflow.input("Whats your name? ", (input) => {
interflow.log("Hello", input)
})
Output
What is your name? (Interflow)
Hello (Interflow)
import {Interflow, InterflowColor} from 'interflow'
const interflow = new Interflow(stdin, stdout)
interflow.log(
InterflowColor.red("Something in red!")
)
Output
Something in red! (it's red trust me)
const interflow = new Interflow(stdin, stdout)
interflow.on("key", (key) => {
interflow.log(key.bytes, key.code(), key.value())
})
Output
(key press "a")
97 a a
(key press "arrow up")
27,91,65 up (value is empty since its not a visible char)
const interflow = new Interflow(stdin, stdout, {
timestamps: false,
debugConfig: {
showLineNumbers: false,
showLineNumbersFromAbsolute: false,
}
})
// normal log
interflow.log("hello world")
// with multiple objects
interflow.log("hello", "world")
// info
interflow.info("some info")
// warning
interflow.warning("some warning")
// error
interflow.error("some error")
// debug
interflow.debug("some debug")
// success
interflow.success("some success")
String
await interflow.input("Whats your name?", (input) => {
interflow.log("Hello", input)
})
Whats your name? (Interflow)
Hello (Interflow)
Bool
await interflow.boolInput("Would you like to continue?", (input) => {
interflow.log("You chose", input)
})
Would you like to continue? (Y/n)
You chose (true)
Multiple options
let options = ["option 2", "option 2", "option 3"]
await interflow.chooseInput("Choose an option?", options, (input) => {
interflow.log("You chose", input)
})
Choose an option? [option 1] [option 2] [option 3]
You chose (option 2)
Key
interflow.on("key", (key) => {
interflow.log(key.bytes, key.code(), key.value())
})
interflow.goto(x, y, from_absolute)
// absolute is from very top
// relative is from first log
interflow.up(n_lines)
interflow.down(n_lines)
interflow.clear() // Clear whole console
interflow.clearLine(line, from_absolute)
// absolute is from very top
// relative is from first log
interflow.log(
InterflowColor.green("You made it until here!")
)
Foreground
Background
Fonts
const interflow = new Interflow(stdin, stdout);
const bar = new InterflowProgressBar(interflow)
.setLabel('Loading')
.setUseBlocks(true)
.setBarLength(50)
.setMax(1000);
for (let i = 0; i < 1000; i++) {
bar.tick();
await interflow.sleep(100);
if (i % 20 === 0) {
interflow.log("Index", i)
}
}
Loading [█████████████ ] (27%)
Index 0
Index 20