![Maven Central Adds Sigstore Signature Validation](https://cdn.sanity.io/images/cgdhsj6q/production/7da3bc8a946cfb5df15d7fcf49767faedc72b483-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
makitso-prompt
Advanced tools
The terminal prompt used by Makitso.
yeh, yeh.. I started with Commander, it calls process.exit()
for various
reasons which made it difficult to use in a REPL. I then converted Makitso use
Inquirer, but it doesn't like promises so much and I needed moar async.
Enquirer was better in this respect, but then I got to implementing autocomplete
and things got tricky again. I had varying success overriding parts of these
modules, but it was harder to bend to them my will than I liked. The inbuilt
Node readline module was much the same, so I started from scratch, pulling in
some of the complex bits from readline and filling in the gaps.
The essential part of a commandline prompt is being able to act on key presses and modify the output in the terminal accordingly. I've attempted to make this as simple as possible with makitso-prompt by allowing pure functions to be used as key-press processors which modify a state object which is then rendered to the terminal. Much of the logic is also broken into easily replaceable functions for customisation.
This will simply echo entered commands
const { Prompt } = require("makitso-prompt");
const prompt = new Prompt();
const command = prompt.start().then(console.log);
const prompt = new Prompt({ prompt: chalk`{blue aPrompt> }` });
const command = prompt.start().then(console.log);
const prompt = new Prompt();
const header = "A line above the prompt";
const footer = "A line below the prompt\nAnother line";
const command = prompt.start({ header, footer }).then(console.log);
const { keyPressHistory } = require("makitso-prompt");
const prompt = new Prompt();
Object.assign(prompt, { keyPressers: [...prompt.keyPressers, keyPressHistory] });
const command = prompt.start().then(console.log);
A keypress handler is an object with a keyPress
method.
Keypress handlers keyPress
methods are called each time a key is pressed.
Keypress handlers are called in the order of the keypressers array.
The keyPress
method is called with the app state
object and a press
object.
Keypress handlers use the press
and/or state
objects to decide what, if
anything, needs to be changed in the state
object. Changes are made using
state methods or using the applyPatch
function from makitso-prompt/immutably
on state.pojo
.
const _filter = require("lodash/filter");
const { applyPatch } = require("makitso-prompt");
// available as `keyPressAutocomplete` but you'll likely want to build your own
function AutoComplete(choices) {
return {
keyPress: async function(state, press) {
if (state.mode === "command") {
let command = state.command;
const matches = _filter(choices, choice => choice.startsWith(command));
if (press.key && press.key.name === "tab" && matches.length === 1) {
state.command = matches[0] + " ";
state.cursorCols = null;
} else {
// state.pojo = applyPatch(state.pojo, { footer: matches.join(" ") });
state.footer = matches.join(" ");
}
}
return state;
}
};
}
const complete = AutoComplete(["abc1", "ab12", "abcdefg", "a123"]);
const prompt = new Prompt();
Object.assign(prompt, { keyPressers: [...prompt.keyPressers, complete] });
const command = prompt.start().then(console.log);
FAQs
a terminal prompt
The npm package makitso-prompt receives a total of 0 weekly downloads. As such, makitso-prompt popularity was classified as not popular.
We found that makitso-prompt 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
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.