A simple shell for pyboard

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Turbinenreiter
Posts: 288
Joined: Sun May 04, 2014 8:54 am

Re: A simple shell for pyboard

Post by Turbinenreiter » Wed Aug 13, 2014 6:52 am

On the REPL you can use arrow-up to get the last lines you entered. It's limited to a couple of lines tough.

fma
Posts: 160
Joined: Wed Jan 01, 2014 5:38 pm
Location: France

Re: A simple shell for pyboard

Post by fma » Wed Aug 13, 2014 6:53 am

I agree, but recording the history will do a lot of write cycles on the flash. It is maybe not an issue when using a sd card, as you can change it, but what about the internal flash? How many write cycle can it handle?

This feature should be an option the user has to specifically turn on, knowing the risks.

For other features, like code completion, I guess this would use a lot of memory...
Frédéric

User avatar
dhylands
Posts: 3211
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: A simple shell for pyboard

Post by dhylands » Wed Aug 13, 2014 7:08 am

There is already 8 lines of history that you can retrieve using the up-arrow (at least under linux).

If your terminal is sending the ANSI escape sequence for the up arrow (which is ESC [ A) then you should be getting history displayed.

torwag
Posts: 208
Joined: Fri Dec 13, 2013 9:25 am

Re: A simple shell for pyboard

Post by torwag » Wed Aug 13, 2014 10:27 am

Ohh,
did not know about that. Or my terminal (screen under Linux) is not sending the right ANSI escapes.

Need to test.

History could be cached in (user adjustable) RAM. Only if you want to make it persistent, a write down could be issued for every n new commands. That should lower the write cycles quite a bit.

Yep, completion would be quite resource hungry. And since you normally do not deal with very large and complex modules like pylab on the pyboard, completion might not really be so helpful.

Another idea would be to hack ipython on the PC side to work with the pyboard. Instead of sending the commands to an local python-interpreter it would send them over serial to the pyboard. Does ipython have the ability to e.g. execute the commands on another machine?
There was something like clustering with the ipython webinterface. Would be fun to use the ipython notebook webinterface to test and debug the pyboard.

User avatar
dhylands
Posts: 3211
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: A simple shell for pyboard

Post by dhylands » Wed Aug 13, 2014 3:11 pm

Here's a little code snippet you can run on your pyboard to see what keys are sent:

Code: Select all

from pyb import USB_VCP

u = USB_VCP()

while True:
    data = u.recv(1)
    ch = data[0]
    if ch < ord(' ') or ch > ord('~'):
        ch = '.'
    print("Rcvd: 0x%x '%c'" % (data[0], ch))
and this is what I see when I press the up arrow:

Code: Select all

>>> import keys
Rcvd: 0x1b '.'
Rcvd: 0x5b '['
Rcvd: 0x41 'A'

Turbinenreiter
Posts: 288
Joined: Sun May 04, 2014 8:54 am

Re: A simple shell for pyboard

Post by Turbinenreiter » Thu Aug 14, 2014 8:44 am

I now have working:

Code: Select all

cat file1 > file2
echo print('test') > test.py
micropython test.py
ls        (without invisible files)
ls -a    (with invisible files)
Also:
cd without args crashed, I made it cd to /

The '>' is implemented within do_cat and do_echo - I guess this should be done in a more generic way by building it into Shell.line_to_arg(line).
'micropython' is implemented using exec() - and seems to be working fine.

I'll send you a pull request once I think it's sane. [edit: done]

User avatar
dhylands
Posts: 3211
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: A simple shell for pyboard

Post by dhylands » Thu Aug 14, 2014 4:29 pm

Yeah - we should have the various commands send their output to self.stdout and get their input from self.stdin

Then we can put the > and < processing in the line_to_arg and have it set self.stdin and self.stdout and then we just need to reset those after (or just before) each command runs.

cmd calls a function postcmd which is called after the command runs, and we can provide that function in Shell and have it restore self.stdin and self.stdout

keithostertag
Posts: 9
Joined: Sun Dec 17, 2017 3:46 pm

Re: A simple shell for pyboard

Post by keithostertag » Mon Feb 19, 2018 6:45 pm

Hi Dave-

Thanks for making this shell for micropython available! Fun, convenient, and useful!

This is an old thread, so I wonder if your shell.py and/or cmd.py has been updated since?

I'm wondering if there is a cp command, or maybe there's a different method you use the shell with to copy files?

Thanks,
Keith Ostertag

User avatar
Roberthh
Posts: 1563
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: A simple shell for pyboard

Post by Roberthh » Mon Feb 19, 2018 8:54 pm

in microypthon-lib there is a module called upysh with a small set of *ix like commands
https://github.com/micropython/micropyt ... ster/upysh
Installable by direct copy or upip.
It has no cp, but that could easily be added.

User avatar
dhylands
Posts: 3211
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: A simple shell for pyboard

Post by dhylands » Tue Feb 20, 2018 12:15 am

The shell I wrote doesn't have a cp command, but it does have a a cat command and supports redirection so you can use:

Code: Select all

 cat filename1 > filename2
to do a copy. Adding a cp command would be pretty straight forward. You can use the help command to see what commands exist.

PRs welcome

Post Reply