readline.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # -*- coding: UTF-8 -*-
  2. # this file is needed in site-packages to emulate readline
  3. # necessary for rlcompleter since it relies on the existence
  4. # of a readline module
  5. from pyreadline3.rlmain import Readline
  6. __all__ = [
  7. "parse_and_bind",
  8. "get_line_buffer",
  9. "insert_text",
  10. "clear_history",
  11. "read_init_file",
  12. "read_history_file",
  13. "write_history_file",
  14. "get_current_history_length",
  15. "get_history_length",
  16. "get_history_item",
  17. "set_history_length",
  18. "set_startup_hook",
  19. "set_pre_input_hook",
  20. "set_completer",
  21. "get_completer",
  22. "get_begidx",
  23. "get_endidx",
  24. "set_completer_delims",
  25. "get_completer_delims",
  26. "add_history",
  27. "callback_handler_install",
  28. "callback_handler_remove",
  29. "callback_read_char",
  30. "redisplay",
  31. ] # Some other objects are added below
  32. # create a Readline object to contain the state
  33. rl = Readline()
  34. if rl.disable_readline:
  35. def dummy(completer=""):
  36. pass
  37. for funk in __all__:
  38. globals()[funk] = dummy
  39. else:
  40. def GetOutputFile():
  41. """Return the console object used by readline so that it can be
  42. used for printing in color."""
  43. return rl.console
  44. __all__.append("GetOutputFile")
  45. import pyreadline3.console as console
  46. # make these available so this looks like the python readline module
  47. read_init_file = rl.read_init_file
  48. parse_and_bind = rl.parse_and_bind
  49. clear_history = rl.clear_history
  50. add_history = rl.add_history
  51. insert_text = rl.insert_text
  52. write_history_file = rl.write_history_file
  53. read_history_file = rl.read_history_file
  54. get_completer_delims = rl.get_completer_delims
  55. get_current_history_length = rl.get_current_history_length
  56. get_history_length = rl.get_history_length
  57. get_history_item = rl.get_history_item
  58. get_line_buffer = rl.get_line_buffer
  59. set_completer = rl.set_completer
  60. get_completer = rl.get_completer
  61. get_begidx = rl.get_begidx
  62. get_endidx = rl.get_endidx
  63. set_completer_delims = rl.set_completer_delims
  64. set_history_length = rl.set_history_length
  65. set_pre_input_hook = rl.set_pre_input_hook
  66. set_startup_hook = rl.set_startup_hook
  67. callback_handler_install = rl.callback_handler_install
  68. callback_handler_remove = rl.callback_handler_remove
  69. callback_read_char = rl.callback_read_char
  70. redisplay = rl.redisplay
  71. console.install_readline(rl.readline)
  72. __all__.append("rl")
  73. __doc__ = "Importing this module enables command line editing using pyreadline3 for Widnows systems"
  74. # type: ignore