Skip to content

OneMadGypsy/simple-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

91 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simple-cli

This is a very simple command line interface written in micropython. It's main purpose is to serve as a terminal interface to perform filesystem and diagnostic operations on a mounted drive that is connected to your microcontroller. The formatting this app uses is only properly supported by a linux terminal. Windows will understand the formatting, but interpret it differently. If you would like to retheme the interface it can be done easily by modifying lines 29 through 34. There are also some alternate theme ideas at the bottom of this repo.

If you are using a mounted drive with a Raspberry Pi Pico maybe you would be interested in my pico-sd-card module. This cli app was 100% written because of my SD card module, and my desire to be able to interact with the card, directly from the Pico, in a more graphical way. Using the loading external scripts example under Usage as a base, you could actually put this cli app on the SD card and run it from there.


CLI Example Image

Community:

To officially file a bug report or feature request you can use these templates: bug report | feature request

To discus features, bugs or share your own project that utilize code in this repo: join the discussion




Ports:

cli.py

This can be uploaded directly to the board, but is intended to be used as a frozen module. For information regarding how to setup the sdk and freeze a module you can refer to this post on the Raspberry Pi forum.

cli.mpy

This is a cross-compiled version of cli.py. It is intended to be uploaded to your board as you would any normal .py script.




Docs:


CLI(clear, user)

Arg Type Description Default
clear bool clears the terminal on startup True
user str personalize user@sysname:~/ 'user'



Commands:


Whereas the Same As section of the below table is accurate, very few commands are identical to their equivalent. This is because returned information has formatting, sorting and/or pruning applied, and may trigger another command as a convenience.


Cmd Description Examples Equivalent
exit exit the CLI no equivalent
help prints this help info no equivalent
clr clear the terminal print('\n'*100)
now prints system timestamp utime.localtime(utime.time())
sysinfo prints system info no equivalent
collect run garbage collection gc.collect()
list lists the current directory list [path] uos.listdir() (sorted)
cd change directory cd path uos.chdir()
print print requested file print fileName [r, rb] no equivalent
mkdir creates a new directory mkdir dirName uos.mkdir()
del delete a file or folder del fileOrDirName no equivalent
rename rename a file rename oldname newname uos.rename()
find find all with term from cwd find term no equivalent
syspath print or [modify] syspath syspath [add, del] sys.path [.append(), .remove()]
copy copy a file copy source dest [w, wb] no equivalent



Info


  1. cd, mkdir, del and rename will automatically list the targeted directory when their operation completes
  2. sypath will automatically list all paths when an add or del operation completes
  3. copy will automatically list the parent directory of the destination file when the operation completes
  4. /absolute/path, relative/path, and ../relative path are all supported
  5. wrap paths that contain spaces in quotes 'path/with space/file name.ext'
  6. most operations can be performed from anywhere as long as the path argument(s) are correct
  7. del is nuclear! It is the equivalent of sudo rm -r mydir. You will not be asked if you are sure.



Usage:


simple

from cli import CLI

CLI(user='yourName') #auto-clears
from cli import CLI

CLI(False, 'yourName') #wont auto-clear

on button release

from cli import CLI
from machine import Pin

cli = Pin(3, Pin.IN, Pin.PULL_DOWN)
cli.irq(lambda p:CLI(user="yourName"), Pin.IRQ_FALLING) #on release



Theme Ideas:

Here are a few alternate themes that can be copy/pasted over lines 29 through 34. I don't take the below themes very seriously, They are provided more so you can understand how each property affects the appearance, and easily make a theme that you like. Themes, in general, were never intended to be a feature. The way I programmed this made it very simple to change the appearance. Due to it's simplicity I decided to share the method. If you create an interesting theme share it here so others can enjoy it.


These images are from an older version and do not reflect the current feature-set that is available. The main image for this repository is always current. Formatting has not changed, and all of these themes are still relevant.

Happy Jack

_MAIN       = _FG_BLACK 
_BRIGHT_FG  = _FG_YELLOW
_FG         = _FG_BLACK 
_BG         = _BG_RED
_ALT_FG     = _FG_RED   
_ALT_BG     = _BG_BLACK

Happy Jack Example


Mardi Gras

_MAIN       = _FG_MAGENTA
_BRIGHT_FG  = _FG_YELLOW 
_FG         = _FG_BLACK  
_BG         = _BG_GREEN
_ALT_FG     = _FG_GREEN  
_ALT_BG     = _BG_BLACK

Mardi Gras Example


Snow Capped

_MAIN       = _FG_WHITE
_BRIGHT_FG  = _FG_BLUE 
_FG         = _FG_WHITE
_BG         = _BG_BLUE
_ALT_FG     = _FG_WHITE
_ALT_BG     = _BG_BLACK

Surf Example


Minimalist

_MAIN       = _FG_WHITE
_BRIGHT_FG  = _FG_WHITE
_FG         = _FG_WHITE
_BG         = _BG_BLACK
_ALT_FG     = _FG_WHITE
_ALT_BG     = _BG_BLACK

Minimalist Example


Snowballs

_MAIN       = _FG_CYAN
_BRIGHT_FG  = _FG_YELLOW
_FG         = _FG_BLACK
_BG         = _BG_MAGENTA
_ALT_FG     = _FG_GREEN
_ALT_BG     = _BG_BLACK

Snowballs Example

About

A simple command line interface in micropython

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages