import { input } from "https://deno.land/x/denops_std@v6.5.0/helper/mod.ts";
Open a prompt to get user input.
It is a wrapper function of Vim/Neovim's native input()
function.
This version has the following advantages
- Developers can use TypeScript custom completion function
- It returns
null
instead when user cancelled by or - It automatically guard input when
inputsave
option is specified
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts";
import { input } from "https://deno.land/x/denops_std@v6.5.0/helper/input.ts";
export const main: Entrypoint = async (denops) => {
console.log(
await input(denops, {
prompt: "> ",
text: "This is default value",
}),
);
}
Not like native input()
function, it returns null
instead of an empty string
when user press <Esc>
or <C-c>
so that developers can distinguish if user
cancelled or input an empty string.
It accepts a TypeScript callback as a completion function addition to built-in completions and Vim script custom completion like:
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts";
import { input } from "https://deno.land/x/denops_std@v6.5.0/helper/input.ts";
export const main: Entrypoint = async (denops) => {
// Built-in completions
console.log(
await input(denops, {
prompt: "> ",
text: "This is default value",
completion: "command",
}),
);
// Vim script custom completion (assume 'MyVimScriptCompletion' is defined in Vim script)
console.log(
await input(denops, {
prompt: "> ",
text: "This is default value",
completion: "custom,MyVimScriptCompletion",
}),
);
// TypeScript custom completion
console.log(
await input(denops, {
prompt: "> ",
text: "This is default value",
completion: (
arglead: string,
cmdline: string,
cursorpos: number,
): Promise<string[]> => {
return Promise.resolve(["Hello", "World"]);
},
}),
);
}
If you'd like to guard input by inputsave()
and inputrestore()
, use
inputsave
option like:
import type { Entrypoint } from "https://deno.land/x/denops_std@v6.5.0/mod.ts";
import { input } from "https://deno.land/x/denops_std@v6.5.0/helper/input.ts";
export const main: Entrypoint = async (denops) => {
denops.dispatcher = {
say: async () => {
return await input(denops, {
prompt: "> ",
inputsave: true,
});
},
};
}
Parameters
denops: Denops
optional
options: InputOptions = [UNSUPPORTED]