How to use the readline-sync.prompt function in readline-sync

To help you get started, we’ve selected a few readline-sync examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fengari-lua / fengari / tests / manual-tests / lua-cli.js View on Github external
{
            let buffer = lua.to_luastring("return " + input);
            status = lauxlib.luaL_loadbuffer(L, buffer, buffer.length, stdin);
        }
        if (status !== lua.LUA_OK) {
            lua.lua_pop(L, 1);
            let buffer = lua.to_luastring(input);
            if (lauxlib.luaL_loadbuffer(L, buffer, buffer.length, stdin) === lua.LUA_OK) {
                status = lua.LUA_OK;
            }
        }
        while (status === lua.LUA_ERRSYNTAX && lua.lua_tojsstring(L, -1).endsWith("")) {
            /* continuation */
            lua.lua_pop(L, 1);
            lua.lua_getglobal(L, _PROMPT2);
            input += "\n" + readlineSync.prompt({
                prompt: lua.lua_tojsstring(L, -1) || '>> '
            });
            lua.lua_pop(L, 1);
            let buffer = lua.to_luastring(input);
            status = lauxlib.luaL_loadbuffer(L, buffer, buffer.length, stdin);
        }
        if (status === lua.LUA_OK) {
            status = docall(L, 0, lua.LUA_MULTRET);
        }
        if (status === lua.LUA_OK) {
            let n = lua.lua_gettop(L);
            if (n > 0) {  /* any result to be printed? */
                lua.lua_getglobal(L, lua.to_luastring("print"));
                lua.lua_insert(L, 1);
                if (lua.lua_pcall(L, n, 0, 0) != lua.LUA_OK) {
                    lauxlib.lua_writestringerror(`error calling 'print' (${lua.lua_tojsstring(L, -1)})\n`);
github fengari-lua / fengari / tests / manual-tests / lua-cli.js View on Github external
const doREPL = function(L) {
    for (;;) {
        lua.lua_getglobal(L, _PROMPT);
        let input = readlineSync.prompt({
            prompt: lua.lua_tojsstring(L, -1) || '> '
        });
        lua.lua_pop(L, 1);

        if (input.length === 0)
            continue;

        let status;
        {
            let buffer = lua.to_luastring("return " + input);
            status = lauxlib.luaL_loadbuffer(L, buffer, buffer.length, stdin);
        }
        if (status !== lua.LUA_OK) {
            lua.lua_pop(L, 1);
            let buffer = lua.to_luastring(input);
            if (lauxlib.luaL_loadbuffer(L, buffer, buffer.length, stdin) === lua.LUA_OK) {
github dataform-co / dataform / cli / console.ts View on Github external
function prompt(questionText: string, options?: readlineSync.BasicOptions) {
  writeStdOut(questionText);
  return readlineSync.prompt({
    ...options,
    prompt: (options && options.prompt && options.prompt + DEFAULT_PROMPT) || DEFAULT_PROMPT
  });
}