--- /usr/bin/emerge 2004-08-26 23:07:15.000000000 -0700 +++ /root/emerge 2004-08-26 23:02:10.801371432 -0700 @@ -21,6 +21,47 @@ else: return os.path.normpath(mystr) +def getch(): + """Gets a single character from standard input. Does not echo to the + screen.""" + try: + import msvcrt + char = msvcrt.getch() + except ImportError: + import sys, tty, termios + fd = sys.stdin.fileno() + old_settings = termios.tcgetattr(fd) + try: + tty.setraw(sys.stdin.fileno()) + char = sys.stdin.read(1) + finally: + termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) + return char + + +def userchoice(choices): + """Displays a prompt and a set of responses, then waits for a response + which is checked against the responses and the first to match is + returned. + + choice: a List of Strings. + choice_color: a Function taking and returning a String + + Returns the number of the response.""" + for i in range(1, len(choices) + 1) : + print green("\t[" + `i` + "] ") + red(choices[i - 1]) + + while 1: + choice = getch() + try: + choice = int(choice) + except ValueError: + continue + if choice > len(choices) : + continue + + return choice - 1 + def userquery(prompt, responses=None, colours=None): """Displays a prompt and a set of responses, then waits for a response which is checked against the responses and the first to match is @@ -873,12 +914,17 @@ try: mykey=portage.dep_expand(x,portage.portdb) except ValueError, errpkgs: - print "\n\n!!! The short ebuild name \"" + x + "\" is ambiguous. Please specify" - print "!!! one of the following fully-qualified ebuild names instead:\n" - for i in errpkgs[0]: - print " " + green(i) - print - sys.exit(1) + print "\n!!! The short ebuild name \"" + x + "\" is ambiguous. Please specify" + print "!!! one of the following fully-qualified ebuild names instead:\n" + if "--ask" in myopts: + choice = userchoice(errpkgs[0]) + mykey = errpkgs[0][choice] + print + else : + for i in errpkgs[0]: + print " " + green(i) + print + sys.exit(1) # select needs to return 0 on dep_check failure