dhylands / rshell

Remote Shell for MicroPython
MIT License
945 stars 133 forks source link

Not Windows Compatible #17

Open ghost opened 7 years ago

ghost commented 7 years ago

This cannot be used out-of-the-box on Windows because the readline module is needed, which is not available for a Windows shell. Maybe you could detect OS and load a similar module for Windows users?

Thanks

dhylands commented 7 years ago

It does work on windows under cygwin.

Are you aware of a similar module for windows?

I've managed to find pyreadline: https://pypi.python.org/pypi/pyreadline and I found this blog post on using it with rlcompleter: http://www.farmckon.net/2009/08/rlcompleter-how-do-i-get-it-to-work/

Would you be able to test this?

Arrowana commented 7 years ago

I tried to had some minor tweaks to make the rshell work on windows. It does, I can use rshell. Absolute windows path don't seem to work though, but relative ones work fine However pyreadline breaks the CPython REPL.

With pyreadline installed if I press TAB in the CPython REPL it will throw >>> def test(): ... Readline internal error Traceback (most recent call last): File "C:\Users\Arowana\AppData\Local\Programs\Python\Python35\lib\site-packages\pyreadline\console\console.py", line 768, in hook_wrapper_23 res = ensure_str(readline_hook(prompt)) File "C:\Users\Arowana\AppData\Local\Programs\Python\Python35\lib\site-packages\pyreadline\rlmain.py", line 571, in readline self._readline_from_keyboard() File "C:\Users\Arowana\AppData\Local\Programs\Python\Python35\lib\site-packages\pyreadline\rlmain.py", line 536, in _readline_from_keyboard if self._readline_from_keyboard_poll(): File "C:\Users\Arowana\AppData\Local\Programs\Python\Python35\lib\site-packages\pyreadline\rlmain.py", line 556, in _readline_from_keyboard_poll result = self.mode.process_keyevent(event.keyinfo) File "C:\Users\Arowana\AppData\Local\Programs\Python\Python35\lib\site-packages\pyreadline\modes\emacs.py", line 243, in process_keyevent r = self.process_keyevent_queue[-1](keyinfo) File "C:\Users\Arowana\AppData\Local\Programs\Python\Python35\lib\site-packages\pyreadline\modes\emacs.py", line 286, in _process_keyevent r = dispatch_func(keyinfo) File "C:\Users\Arowana\AppData\Local\Programs\Python\Python35\lib\site-packages\pyreadline\modes\basemode.py", line 257, in complete completions = self._get_completions() File "C:\Users\Arowana\AppData\Local\Programs\Python\Python35\lib\site-packages\pyreadline\modes\basemode.py", line 200, in _get_completions r = self.completer(ensure_unicode(text), i) File "C:\Users\Arowana\AppData\Local\Programs\Python\Python35\lib\rlcompleter.py", line 80, in complete readline.redisplay() AttributeError: module 'readline' has no attribute 'redisplay' File "<stdin>", line 2

Obviously a pyreadline bug

ccooper21 commented 6 years ago

I just learned about rshell on the uPy forums and thought I'd give it a try (on Windows). Pretty cool! As expected, I had to install the pyreadline library to get it working. Other than that, the only change I had to make is to replace the 'libedit' in readline.__doc__ reference in main.py with readline.__doc__ and 'libedit' in readline.__doc__. I did not observe the error that @Arrowana reported.

Jim43 commented 6 years ago

@ccooper21 it works,thanks

jumblies commented 6 years ago

Working through another issue, I reinstalled and it occurred to me a minor change could prevent manual editing. I'm a gitidiot so here is what did starting at line 67

if os.name == "nt":
    if readline.__doc__ and 'libedit' in readline.__doc__:
        readline.parse_and_bind ("bind ^I rl_complete")
        BROKEN_READLINE = True
    else:
        readline.parse_and_bind("tab: complete")

I guess all that's needed is an else to use the standard line in *nix systems.

RSabet commented 6 years ago

see #62

clifforddw commented 6 years ago

Hi All, I managed to get rshell working on windows through the Linux Subsystem for windows. install rshell as per the documentation and then enable the requires serial port with this command :

stty -F /dev/ttyS2 -a

Good article here with the background https://blogs.msdn.microsoft.com/wsl/2017/04/14/serial-support-on-the-windows-subsystem-for-linux/

karelv commented 5 years ago

@dhylands ,

I've managed to find pyreadline: https://pypi.python.org/pypi/pyreadline and I found this blog post on using it with rlcompleter: http://www.farmckon.net/2009/08/rlcompleter-how-do-i-get-it-to-work/

I did this: pip install rshell (rshell-0.0.16) I run rshell, I got:

.... ModuleNotFoundError: No module named 'readline'

Then I've installed pyreadline: pip install pyreadline (pyreadline-2.1)

$ rshell
Welcome to rshell. Use the exit command to exit rshell.

No MicroPython boards connected - use the connect command to add one

C:\Users\karelv\micropython

Note: I used git-sh as shell and python from anaconda on my win7 pc. Note2: the prompt is in green, so I guess the colors are working Note3: I entered repl, but no clue how to exit it... exit() is not working... I found it; ctrl-X, thanks, now I can start my blinking app :-)

dhylands commented 5 years ago

You should be able to exit the REPL by using Control-X. I didn't want to use Control-D since Control-D does a soft reset under MicroPython. It should print a line mentioning Control-X when you enter the REPL.

dhylands commented 5 years ago

To exit from rshell (rather then the micropython repl within rshell) I normally use Control-D, but that didn't seem to work under Windows, so I added an exit command (no parenthesis).

karelv commented 5 years ago

Hello @dhylands, ctrl-X indeed exits the repl, while ctrl-D exits the rshell (when in git-sh). Thanks a lot. Now I have another question, off-topic. I'm new to micropython and ESP32. I just now have a ESP32 module. I want to create an application with CAN bus 2.0, but I have misread the micropython doc, CAN is only implemented for pyboard. What would you suggest me to do? Go arduino, or go ESP-IDF as development platform? Is it possible to 'port' arduino to micropython? Or I go better with ESP-IDF?

karelv commented 5 years ago

Again ontopic... I tried rshell also on cmd.exe (win7).

dhylands commented 5 years ago

I have'n't really used ESP-IDF directly, and I rarely use arduino, so I'm not really sure which would be more appropriate.

As for help and exit being built-in commands to cmd.exe, I don't understand the issue. Those commands will only be interpreted by cmd.exe if you're at the cmd prompt. If you're at the rshell prompt, then the commands will be interpreted by rshell.

So yeah, if you type the command twice, the first one will be interpreted by rshell and when it exits, the second buffered command will be executed by cmd.exe.

ghost commented 5 years ago

I personally use ESP-IDF, simply because it is developed by Espressif, so there is never going to be any versioning issues with different ESP modules. While I do love Arduino, it is so much more open to issues because of it's community focus.

The ESP-IDF site has great documentation, and if you're looking for a community to help you, check out esp32.com

On Fri, Dec 21, 2018 at 11:50 AM karelv notifications@github.com wrote:

Hello @dhylands https://github.com/dhylands, ctrl-X indeed exits the repl, while ctrl-D exits the rshell (when in git-sh). Thanks a lot. Now I have another question, off-topic. I'm new to micropython and ESP32. I just now have a ESP32 module. I want to create an application with CAN bus 2.0, but I have misread the micropython doc, CAN is only implemented for pyboard. What would you suggest me to do? Go arduino, or go ESP-IDF as development platform? Is it possible to 'port' arduino to micropython? Or I go better with ESP-IDF?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dhylands/rshell/issues/17#issuecomment-449482783, or mute the thread https://github.com/notifications/unsubscribe-auth/AArMRMDAbJ-OKa6CG8KQ4-mrtB4BJsjSks5u7TuUgaJpZM4K7I6m .

-- Paul Christian Allsopp

Please recycle - it ain't easy being green