Are you writing a workhorse shell script in python? Why not curses?
This class, using curses, lets a user select from a simple list of options. The return is a simple list of selected options, or False (for cancel). And, for the OCD in all of us, it preserves terminal window contents after exiting.
First, get picker.py from github: https://github.com/pp19dd/picker
Usage example:
from picker import * opts = Picker( title = 'Select files to delete', options = [ ".autofsck", ".autorelabel", "bin/", "boot/", "cgroup/", "dev/", "etc/", "home/", "installimage.conf", "installimage.debug", "lib/", "lib64/", "lost+found/", "media/", "mnt/", "opt/", "proc/", "root/", "sbin/", "selinux/", "srv/", "sys/", "tmp/", "usr/", "var/" ] ).getSelected() if opts == False: print "Aborted!" else: print opts
If the user hits cancel, the routine returns a False – otherwise, you get a simple list:
['.autofsck', '.autorelabel', 'bin/', 'boot/', 'cgroup/']
The return, being a simple list, allows for a fairly readable logic:
if "cgroup/" in opts: print "cgroup is done for!"
Now, mind the possible False return, and put it to good use!
The post Simple python list picker using curses appeared first on Dino's Anabasis.