A simple python editline-library for different
kinds of line-editing. I wrote this, because I needed line-editing in
environments which didn't have the gnu readline installed.
I also added a simple check-capability for checking the validity of the
given input.
The checks-parameter is a list of classes that are used to check if the input
is acceptable. The class has to have attribute "errortext" to describe the
failure of a test and "check"-method that gets the input as a parameter and
must return true if the value is accepted.
For example:
class pathexists(resultcheck):
errortext = "path does not exist"
def check(self, result):
return os.path.exists(result)
editline.getinput(prompt = "", default = "", checks = [])
Prints the prompt and the default-value and let's the user edit the input-line.
Line-editing capabilities (emacs-style):
- CTRL-A - beginning of line
- CTRL-E - end of line
- CTRL-K - kill to end of line
editline.getnumber(prompt = "", default = "", checks = [])
As getinput but accepts only numbers.
editline.getpasswd(prompt = "", default = "", checks = [], mask = "*")
As getinput but prints all characters as mask-char.
editline.getpath(prompt = "", default = "", checks = [])
As getinput but with path-expansion capabilities (tcsh-style).
- TAB - expand path
- CTRL-D - show possible expansions
editline.getexistingpath(prompt = "", default = "", checks = [])
Like getpath but requires an existing path
editline.getdirpath(prompt = "", default = "", checks = [])
Like getpath but requires an existing directory
If you find something useful here I'd be happy to
hear about it