Hi. Over the weekend I was playing around with trying to create a Jupyter kernel wrapper using the CommandBox REPL. It works for the most part but I am seeing strange behavior with the input being echoed. I am pretty sure it is an issue with the Python library I am using (pexpect) but wanted to rule out something with CommandBox. Can you think of anything in the CommandBox REPL that would cause this?
I should also mention that I am currently running it inside a Docker container. Using the base image jupyter/base-notebook then installing CommandBox in the Dockerfile.
This is cool. I did some work with Jupyter a while back trying to use an existing JSR-223 wrapper to run Lucee CFML directly, but the lack of support in Lucee for the full JSR-223 API made it impossible
Wow, it’s been 5 years ago and my bug still sits
Anyway, on to your question-- I assume you’re talking about how the output is duplicated on the same line? My guess is this is related to the ANSI escape sequences that are part of the output. Can you check if the Python library is compatible with ANSI escape codes or not. If not, there are ways to start CommandBox up and force JLine to use a dumb terminal so there’s no ANSI formatting.
Also, I’ll note you can’t reliably do any string math like checking the length of a string or creating substrings on the colored output unless you also take account of the non-printable ANSI escape chars in the string.
Actually, the issue may be related to formatting, but not necessarily on output. The REPL formats your code as you type it, so that means that it will move the cursor back to the start of the line (or perhaps somewhere in the middle of the line) while you’re typing to “re-draw” the text with new color formatting. Your Python library may not be handling those ANSI commands to move the cursor back and redraw. And now that I look closer at it, that seems even more likely.
CommandBox would have
- redrawn the
lento change its color once it matched a known CF member function
- redrawn the parenthesis as they were typed to highlight the start/end parens
I think the Python library is not obeying the ANSI codes to move the cursor backwards. You should play the snake game and see what it does
Either way, forcing dumb terminal is the quick test for this.
Had to look this up. It actually seems broken on Windows so I have no idea if it will work for you or not in your Docker container. But create a
commandbox.properties file in the same directory as the
box binary with this in it to test:
That is supposed to be a default terminal with no special features, but it totally doesn’t even accept keyboard input when I use it in Windows, so YMMV.
And if the
commandbox.properties file is a pain, on Linux you can also set the following env var in the shell before running Box
Thanks Brad. Setting that flag seems to have fixed the strange duplication.
I am looking to see if there is a similar flag to disable echo. If not, it would not be hard to remove it from the output.
Good news. To be clear, I think the Python lib probably supports SOME ANSI formatting such as color coding (because I see color formatting in your output above). Just not the escapes that move the cursor around. I’d log this as a bug in the corresponding Python lib.
If you go entirely to a dumb terminal, you’ll loose the nice color coding of the JSON formatted output.
This is a work in progress / proof of concept but if anyone is interested in it, I created a github repo. It does not currently work on Windows. There are other issues with continuation,interrupts, etc. that still need to be worked out.
I will plan on writing up more details in a blog post or something.
I changed the Python library I was using to control CommandBox so it now works on Windows as well as Linux. It also fixed a few of the bugs I was seeing. Still very much a work in progress however so please let me know if you notice any issues.
I also updated the readme file with more information about setting it up. If you just want to try it out the mybinder.org option is the easiest.