admin管理员组文章数量:1391960
I'm trying to change the prompt for Node's REPL with text given inside the REPL.
My original attempt was something like this.
import repl from 'repl'
let PROMPT = 'original > '
repl.start({
ignoreUndefined: true,
prompt: PROMPT,
eval: (text, context, filename, callback) => {
PROMPT = `${text} >`
return callback()
}
})
I realized this isn't gonna work because the prompt for the repl is set when the process starts.
I came up with something like this, which starts a new repl with a new prompt after ever entered mand.
import repl from 'repl'
let PROMPT = 'original > '
let REPL = createRepl(PROMPT)
function createRepl (prompt) {
return repl.start({
ignoreUndefined: true,
prompt: PROMPT,
eval: (text, context, filename, callback) => {
PROMPT = `${text.replace(/\n/, '')} >`
REPL.close()
REPL = createRepl(PROMPT)
}
})
}
This solution is almost there the issue is that the process is exiting when I close the original REPL.
I'm simply trying to change the REPL prompt from inside the script after the process starts. I'm open to any means to do this. Ideally the prompt
prop took a function with the prompt
argument and allowed you to set it from within the function, then I could use an event or something else.
I'm trying to change the prompt for Node's REPL with text given inside the REPL.
My original attempt was something like this.
import repl from 'repl'
let PROMPT = 'original > '
repl.start({
ignoreUndefined: true,
prompt: PROMPT,
eval: (text, context, filename, callback) => {
PROMPT = `${text} >`
return callback()
}
})
I realized this isn't gonna work because the prompt for the repl is set when the process starts.
I came up with something like this, which starts a new repl with a new prompt after ever entered mand.
import repl from 'repl'
let PROMPT = 'original > '
let REPL = createRepl(PROMPT)
function createRepl (prompt) {
return repl.start({
ignoreUndefined: true,
prompt: PROMPT,
eval: (text, context, filename, callback) => {
PROMPT = `${text.replace(/\n/, '')} >`
REPL.close()
REPL = createRepl(PROMPT)
}
})
}
This solution is almost there the issue is that the process is exiting when I close the original REPL.
I'm simply trying to change the REPL prompt from inside the script after the process starts. I'm open to any means to do this. Ideally the prompt
prop took a function with the prompt
argument and allowed you to set it from within the function, then I could use an event or something else.
1 Answer
Reset to default 12You should be able to call repl.setPrompt('foo> ');
to change the prompt.
本文标签: javascriptChange REPL prompt from within the REPLStack Overflow
版权声明:本文标题:javascript - Change REPL prompt from within the REPL - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744743985a2622779.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论