Installed rlfe
rlfe - "cook" input lines for other programs using readline
Worked for me on Pop!_OS / Ubuntu using bash
.
sudo apt-get install rlfe
And the problem was just fixed, don't know how, but it works.
EDIT: Apparently rlfe
can cause some minor bugs and you also have to run rlfe
command every time you open the terminal, which is obviously not really convenient. So my solution was to just append rlfe
to ~/.bashrc
. When you open a new terminal - nothing happens, you just have to ^C and it'll be fine. Even though it is an easy solution to the problem, I don't think it's good. What if you writing a program for someone? Do they really have to do that rlfe
fix? Solution is not user-friendly, and you probably don't wanna put rlfe
at ~/.bashrc
for the end user, because the command always has to be at the end, otherwise bash
will just ignore everything that goes after -> you will break end user's .bashrc
. So you should probably go with rlwrap
or fix the problem programmatically using libraries (which is probably the best solution if you plan to share your program).
rlwrap
solution:
sudo apt-get install rlwrap
rlwrap <command>
EDIT: I was writing a console application in Node.js. To handle user input I'm using basic process.stdin.on("data", ...)
. The only solution I found is to use built-in readline
module. So I wrote a function, which works basically the same as the method I was using before:
const rl = require("readline").createInterface(process.stdin, process.stdout)
function recursiveReadline(prompt, handler) {
rl.question(prompt, output => {
if (handler(output.trim()) == 0) return rl.close()
recursiveReadline(prompt, handler)
})
}
//
recursiveReadline("> ", (data) => {
if (data == "exit") return 0 // closes readline
console.log(data)
})