open-policy-agent / opa

Open Policy Agent (OPA) is an open source, general-purpose policy engine.
https://www.openpolicyagent.org
Apache License 2.0
9.69k stars 1.34k forks source link

REPL has issues with `\t` #962

Open aeneasr opened 6 years ago

aeneasr commented 6 years ago

If I copy (cmd+c) the following snippet (with \t)

test = ["b",
    "a"]

and paste it (right-click -> paste), then OPA shows:

> test = ["b",
| data.repl.version"a"]
1 error occurred: 2:18: rego_parse_error: no match found
        data.repl.version"a"]

If I copy the same snippet but replace \t with e.g. 4 spaces

test = ["b",
    "a"]

OPA works fine:

> test = ["b",
|     "a"]
|
>

This is happens for me on the OSX terminal as well as Windows cmd.exe

tsandall commented 6 years ago

The REPL has basic tab completion support. I think the problem is the completion handler running when the user pastes text into the REPL. We should check if the line reader library (peterh/liner) has a way to deal with this. Other REPLs must have dealt with this in the past.

srenatus commented 5 years ago

Looks like the terminal feature to support here is called "bracketed paste", see this blog post: https://cirw.in/blog/bracketed-paste. To actually work, it depends on a cooperative terminal emulator, but nowadays most seem to support it (anecdata: iterm2).

tsandall commented 5 years ago

@srenatus thanks for researching this. From reading the first link you posted, it seems like we'd need to modify the peterh/liner package to properly handle the start/stop escape sequences (it doesn't seem to do this currently.) I'm going to open an issue on peterh/liner to see if they have any ideas.

rvandegrift commented 3 years ago

I've been suffering from this for a while. This would be a lot less painful if opa fmt used spaces for indentation. Would an option to enable this be reasonable, since it looks like the upstream bracketed paste change isn't likely?

tsandall commented 3 years ago

I feel like adding an option to opa fmt is a slippery slope as it's intended to be the "one true format" for rego. If we open the door to customization, we'll certainly end up with other options in future.

I'm tempted to just replace liner with another, more featureful readline implementation. There are a bunch of options that weren't available when we originally picked liner. https://github.com/AlecAivazis/survey looks like it's actively maintained, though it might have more features than we need.

stale[bot] commented 2 years ago

This issue has been automatically marked as inactive because it has not had any activity in the last 30 days.