readline._py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import ctypes
  2. auto_history = True
  3. py = ctypes.CDLL("libpython3.6m.so")
  4. rline_lib = ctypes.CDLL("libtoaru_rline_exp.so")
  5. readline_func = ctypes.c_void_p.in_dll(py,"PyOS_ReadlineFunctionPointer")
  6. t = ctypes.c_char_p.in_dll(rline_lib,"rline_exp_for_python")
  7. readline_func.value = ctypes.addressof(t)
  8. # Change exit string to "exit()"
  9. exit_string_lib = ctypes.c_char_p.in_dll(rline_lib,"rline_exit_string")
  10. exit_string = ctypes.c_char_p(b"")
  11. exit_string_lib.value = exit_string.value
  12. def parse_and_bind(s):
  13. pass
  14. def read_init_file(filename=None):
  15. pass
  16. def get_line_buffer():
  17. return None
  18. def insert_text(string):
  19. return None
  20. def redisplay():
  21. pass
  22. def read_history_file(filename):
  23. pass
  24. def write_history_file(filename):
  25. pass
  26. def append_history_file(nelements,filename=None):
  27. pass
  28. def get_history_length():
  29. return 0
  30. def set_history_length(length):
  31. pass
  32. def clear_history():
  33. pass
  34. def get_current_history_length():
  35. return ctypes.c_int.in_dll(rline_lib,"rline_history_count").value
  36. def get_history_item(index):
  37. if index < 1 or index > get_current_history_length():
  38. raise ValueError("bad history index")
  39. index -= 1
  40. return cast(rline_lib.rline_history_get(index), c_char_p).value.decode('utf-8')
  41. def remove_history_item(pos):
  42. pass
  43. def replace_history_item(pos, item):
  44. pass
  45. def add_history(line):
  46. rline_lib.rline_history_insert(line.encode('utf-8'))
  47. def set_auto_history(enabled):
  48. auto_history = enabled
  49. def set_startup_hook(func=None):
  50. pass
  51. def set_pre_input_hook(func=None):
  52. pass
  53. def set_completer(func=None):
  54. pass
  55. def get_completer():
  56. return None
  57. def get_completion_type():
  58. return None
  59. def get_begidx():
  60. return 0
  61. def get_endidx():
  62. return 0
  63. def set_completer_delims(string):
  64. pass
  65. def get_completer_delims():
  66. return ""
  67. def set_completion_display_matches_hook(func=None):
  68. pass