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

Attempt to perform arithmetic on a nil value (field 'y') #2

Open
daelvn opened this issue Dec 12, 2019 · 9 comments
Open

Attempt to perform arithmetic on a nil value (field 'y') #2

daelvn opened this issue Dec 12, 2019 · 9 comments

Comments

@daelvn
Copy link

daelvn commented Dec 12, 2019

For some reason, Sirocco has stopped working for me in a script that used to work. Might be due the fact that I'm running it on Alpine on WSL, and I used to run it on Arch, but I don't see the reason why it would affect it.

This is the stacktrace I'm getting:

/home/daelvn/.luaver/lua/5.1.5/bin/lua: .../luarocks/3.2.0_5.1/share/lua/5.1/sirocco/prompt.lua:355: attempt to perform arithmetic on field 'y' (a nil value)
stack traceback:
        [C]: ?
        .../luarocks/3.2.0_5.1/share/lua/5.1/sirocco/prompt.lua:355: in function 'update'
        .../luarocks/3.2.0_5.1/share/lua/5.1/sirocco/prompt.lua:429: in function <.../luarocks/3.2.0_5.1/share/lua/5.1/sirocco/prompt.lua:425>
        (...2 tail call(s)...)
        ...luarocks/rocks-5.1/rockwriter/1.0.2-1/bin/rockwriter:179: in main chunk
        [C]: ?

To reproduce it, I just did

$ luarocks install rockwriter
$ rockwriter example-1.0-1.rockspec

And it should break, although it works fine on my other machine.

It's not urgent, but help would be appreciated. Thanks!

@giann
Copy link
Owner

giann commented Dec 13, 2019

What terminal emulator are you running?

@daelvn
Copy link
Author

daelvn commented Dec 13, 2019

It happens on both Windows Terminal (microsoft/terminal) and the VS Code embedded terminal.

@giann
Copy link
Owner

giann commented Dec 13, 2019

What does echo $TERM give you?

@daelvn
Copy link
Author

daelvn commented Dec 13, 2019

xterm-256color

@giann
Copy link
Owner

giann commented Dec 16, 2019

My guess is that your terminal emulator doesn't support the escape code that returns the cursor position. Can you do echo -e "\033[6n" | cat and tell me if you get anything in return. You should get something like ^[[38;1R

@daelvn
Copy link
Author

daelvn commented Dec 16, 2019

I get ^[[4:1R, yeah.

@giann
Copy link
Owner

giann commented Dec 17, 2019

Can I see your script then? this seems to require some debugging.

@daelvn
Copy link
Author

daelvn commented Dec 18, 2019

Of course.
MoonScript source: https://github.com/daelvn/rockwriter/blob/master/rockwriter.moon
Lua compiled source (may be not readable): https://github.com/daelvn/rockwriter/blob/master/rockwriter.lua

It did use to work with that source, which is what makes it weird. I went to my old laptop running Arch, checked that it still runs, latest version. $TERM is xterm-termite and instead of getting a cursor position like last time, I got 1R in front of the prompt. Like this:

→ ~ 1R

I could try other terminal emulators for Alpine WSL, but I don't know how much success I'd have with them.

@Lessica
Copy link

Lessica commented Jul 6, 2022

See giann/croissant#9, many terminals won't respond to Prompt.escapeCodes.user7 control question until multiple lines of codes been completely entered, or other user interactions been completely processed.

sirocco/sirocco/prompt.lua

Lines 407 to 411 in b2af2d3

-- Get current position
self.output:write(Prompt.escapeCodes.user7)
self.startingPosition.x,
self.startingPosition.y = self:getCursor()

So, it's not the right time to fetch the cursor position right after that.

sirocco/sirocco/prompt.lua

Lines 392 to 395 in b2af2d3

function Prompt:getCursor()
local y, x = tui.getnext():match("([0-9]*);([0-9]*)")
return tonumber(x), tonumber(y)
end

We should check the result of the tui.getnext() call if we got a control response or not. If we got a control response, do the right thing to the terminal layout. Otherwise, just treat these input characters as user's input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants