All pastes #411088 Raw Edit

Unnamed

public text v1 · immutable
#411088 ·published 2007-03-26 20:58 UTC
rendered paste body
#!/usr/bin/python

import readline

primary = ["bob", "bill", "foo", "bar"]
secondary = ["--bar", "--foo"]

values = []

#def pre_input_hook():
#	readline.insert_text("strongmail# ")
#	readline.redisplay()
#readline.set_pre_input_hook(pre_input_hook)

def complete(text, state):
	if (state == 0):
		incmd = False
		line = readline.get_line_buffer()
		for cmd in primary:
			if line.startswith(cmd +" "):
				incmd = True
		if (incmd):
			values[:] = [s for s in secondary if s.startswith(text)]
		else:
			values[:] = [s for s in primary if s.startswith(text)]

	return values[state]

readline.set_completer(complete)
readline.parse_and_bind("tab: complete")

while (True):
	inp = raw_input("input# ")