Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LIPS command line (read-line (current-input-port)) erases prompt #253

Closed
dragoncoder047 opened this issue Nov 21, 2023 · 7 comments
Closed
Labels
bug Something isn't working resolved

Comments

@dragoncoder047
Copy link
Contributor

dragoncoder047 commented Nov 21, 2023

(read-line (current-input-port)) is the way I've seen to get a line of input form the user in Scheme. Unfortunately, on LIPS, this doesn't work quite-right, it just erases the prompt. (I'm looking for something equivalent to Python's input() function.)

dc047:/home/dc047> npm list -g | grep lips
├── @jcubic/[email protected]
dc047:/home/dc047> lips --version
(command "lips")
(website "https://lips.js.org")
(languages scheme r5rs r7rs)
(encodings utf-8)
(scheme.srfi 0 1 2 4 6 8 10 22 23 26 46 69 98 111 156 176)
(release "{{VER}}")
(os.uname "linux" "6.2.0-1016-azure")
(os.env.LANG "C.UTF-8")
(os.env.TERM "xterm-256color")
(build.date "{{DATE}}")
dc047:/home/dc047> cat test.scm
(display "Enter a string: ")
; (wait 1000)
(display (concat "You entered: " (read-line (current-input-port))))
dc047:/home/dc047> lips test.scm
hello
You entered: hello                                                                                                                        

It's supposed to wind up with "Enter a string: hello" on the first line after running test.scm. If you uncomment the (wait) call, you can see that the prompt is actually printed, but when it gets to the (read-line), the line is cleared.

If there is a better way of getting input, please let me know.

@jcubic
Copy link
Owner

jcubic commented Nov 22, 2023

Thanks for the report, will try to check it out when I will have time.

@jcubic
Copy link
Owner

jcubic commented Nov 22, 2023

So the problem is because of the way stdin/stdout are created in REPL:

var interp = Interpreter('repl', {
    stdin: InputPort(function() {
        return new Promise(function(resolve) {
            rl = readline.createInterface({
                input: process.stdin,
                output: process.stdout
            });
            rl.question('', function(data) {
                resolve(data);
                rl.close();
            });
        });
    }),
    // -------------------------------------------------------------------------
    stdout: OutputPort(function(x) {
        if (typeof x !== 'string') {
            x = this.get('repr')(x);
        }
        newline = !x.match(/\n$/);
        process.stdout.write(x);
    }),

NodeJS readline.createInterface clears everything that was printed in same line. I think that the quick fix would be to keep text before newline in variable and use it in rl.question instead of empty string.

jcubic added a commit that referenced this issue Nov 22, 2023
@jcubic
Copy link
Owner

jcubic commented Nov 22, 2023

the fix seems to work fine. It's available on devel branch.

@dragoncoder047
Copy link
Contributor Author

how do I npm install -g the devel branch? Do I just point to a specific commit?

@dragoncoder047
Copy link
Contributor Author

nevermind, I figured it out.

@jcubic
Copy link
Owner

jcubic commented Nov 22, 2023

Best way is to use:

git clone https://github.com/jcubic/lips.git
cd lips
git checkout devel
npm install -g .

There is pending new release beta.17 on devel, I probably should release soon, but if you find some issues let me know, I will be able to fix them before the next release.

@jcubic jcubic added bug Something isn't working resolved labels Dec 23, 2023
@jcubic jcubic closed this as completed Dec 23, 2023
@jcubic
Copy link
Owner

jcubic commented Dec 23, 2023

Just released version 1.0.0-beta.17 with a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working resolved
Projects
None yet
Development

No branches or pull requests

2 participants