
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
simple-terminal-menu
Advanced tools
terminal-menu does a good job for starting a menu but it is a bit tedious to set-up reliably for process.stdin / process.stdout and also for the use with double width characters.
For simply taking charge of the power this terminal menu offers a few things:
You don't have to do that, it will just work :)
.add
gets an new signature
.add(<label>[, <marker>][, <cb>])
With this you can add entries that have a right-aligned marker text shown.
You can also use .addItem
to use objects to add menu items.
.addItem({
label: "<label>",
marker: "<marker>",
handler: "<cb>"
})
Just use .writeSeparator()
to create a separator line.
If an entry exceeds the width of the menu it will be truncated with opts.truncator
or ...
Similar like .add
it supports .writeLine
that allows you to write a text that is both left & right aligned.
.writeLine(<left>[, <right>])
If the terminal doesn't support TTY the will just return null
!
To write a nice title and subtitle the comfort functions .writeTitle
and .writeSubtitle
exist.
If you have several menus that need to look alike, you can use the factory. It is available via require(simple-terminal-menu/factory)
.
Install it using npm
npm install simple-terminal-menu --save
And then create a menu it in your code using
var createMenu = require('../simple-terminal-menu')
function showSelection(label, marker) {
console.log("label: " + label + "; marker: " + marker + ";")
}
function mainMenu() {
var menu = createMenu({ // settings passed through to terminal-menu
x: 3,
y: 2
})
menu.writeLine("My Menu", "(tm)")
menu.writeSeparator()
menu.add("A", "[selected]", showSelection)
menu.add("B", showSelection)
menu.writeSeparator()
menu.add("open submenu", subMenu)
menu.add("exit", menu.close)
}
function subMenu() {
var menu = createMenu()
menu.writeLine("SubMenu")
menu.writeSeparator()
menu.add("C", "[selected]", showSelection)
menu.add("D", showSelection)
menu.writeSeparator()
menu.add("cancel", mainMenu)
menu.add("niceTitle", nicelyTitledMenu)
menu.add("exit", menu.close)
}
function nicelyTitledMenu() {
var menu = createMenu();
menu.writeTitle("Awesome window")
menu.writeSubtitle("A little more colorful")
menu.writeSeperator()
menu.add("cancel", subMenu)
menu.add("factoryA", factoryMenuA)
menu.add("exit", menu.close)
}
// Options for the menu when created through the factory
var factoryMenuOptions = {} // Can be empty! the factory uses some sensible defaults!
// Defaults for creating menu with the factory
var defaultFactoryOptions = {
title: "Factory Title",
// you could also specify `subtitle:`, menu & extras are not available.
}
var factory = require('simple-terminal-menu/factory')(factoryMenuOptions, defaultFactoryOptions);
function factoryMenuA() {
factory.create({
subtitle: "factory-a",
menu: [{
label: "E",
handler: showSelection
}, {
label: "F",
handler: showSelection
}],
extras: [{
label: "factoryB",
handler: factoryMenuB
},{
label: "cancel",
handler: nicelyTitledMenu
}]
})
}
function factoryMenuB() {
factory.create({
subtitle: "factory-b",
menu: [{
label: "G",
handler: showSelection
}],
extras: [{
label: "factoryA",
handler: factoryMenuA
},{
label: "cancel",
handler: nicelyTitledMenu
}]
}
mainMenu()
FAQs
A menu that is easier to use on the terminal than terminal-menu
The npm package simple-terminal-menu receives a total of 228 weekly downloads. As such, simple-terminal-menu popularity was classified as not popular.
We found that simple-terminal-menu demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.