4

I would like to write a small application/directory/file launcher in python. To make it fast i would like to autocomplete/autosuggest entries. But i want to display these suggestions as the user types. From what i have read about the readline module completion is only possible using a "Completion hotkey" e.g. Tab.

Any suggestions ?

Using curses with filter as suggested below does not seem to work. This minimal example clears my screen despite the call to filter():

import curses

curses.filter()
win = curses.initscr()

curses.noecho()
curses.cbreak()


while 1:
  key = win.getkey()
  win.echochar(key)
  if key == "Q":
    break

curses.endwin()
joekr
  • 1,543
  • 1
  • 16
  • 22

1 Answers1

1

I would try with "curses" library:

http://docs.python.org/2/library/curses.html

You have a related topic at:

How to make python autocompletion display matches?

Community
  • 1
  • 1
  • Curses would work i guess, however it seems to clear the screen which would cause bad integration with the shell – joekr Aug 19 '13 at 11:01
  • @joekr You are right, at http://stackoverflow.com/questions/4772061/curses-library-c-getch-without-clearing-screen someone asked for a solution for the same problem (screen clearing) and got a solution for curses using C language just calling newterm instead initscr. Nevertheless, I think that solution doesn't apply here because python curses library doesn't offer "newterm" method. – Pablo Francisco Pérez Hidalgo Aug 19 '13 at 11:15
  • @joekr I have just found that you can override the initial screen clearing using the "filter" method: http://docs.python.org/2/library/curses.html#curses.filter – Pablo Francisco Pérez Hidalgo Aug 19 '13 at 11:18