|
21 | 21 | from openad.gui.ws_server import ws_server # Web socket server for gui - experimental |
22 | 22 | from openad.helpers.output import output_table |
23 | 23 | from openad.helpers.plugins import display_plugin_overview |
| 24 | +from openad.helpers.history import init_history, update_history_file, add_history_entry |
24 | 25 |
|
25 | 26 | # Core |
26 | 27 | import openad.core.help as openad_help |
@@ -508,27 +509,11 @@ def do_help(self, inp, display_info=True, starts_with_only=False, disable_catego |
508 | 509 |
|
509 | 510 | def preloop(self): |
510 | 511 | """CMD class called function: Preloop is called by cmd to get an update the history file each History File""" |
511 | | - if readline and os.path.exists(self.histfile): |
512 | | - # note history files can get corrupted so using try to compensate |
513 | | - try: |
514 | | - readline.read_history_file(self.histfile) |
515 | | - except Exception: # pylint: disable=broad-exception-caught # do not need to know exception |
516 | | - # Create history file in case it doesn't exist yet. |
517 | | - # - - - |
518 | | - # To trigger: |
519 | | - # >> create new workspace foobar |
520 | | - # >> ctrl+c |
521 | | - # (Reboot) |
522 | | - readline.write_history_file(self.histfile) |
| 512 | + init_history(self) |
523 | 513 |
|
524 | 514 | def postloop(self): |
525 | 515 | """CMD class called function: Post loop is called by cmd to get an update the history file""" |
526 | | - readline.set_history_length(self.histfile_size) |
527 | | - readline.write_history_file(self.histfile) |
528 | | - |
529 | | - def add_history(self, inp): |
530 | | - """CMD class called function: adds history file""" |
531 | | - readline.add_history(inp) |
| 516 | + update_history_file(self) |
532 | 517 |
|
533 | 518 | def complete(self, text, state): |
534 | 519 | """CMD class called function: |
@@ -748,10 +733,6 @@ def emptyline(self): |
748 | 733 | def default(self, line): |
749 | 734 | """Default method call on hitting of the return Key, it tries to parse and execute the statements.""" |
750 | 735 |
|
751 | | - # Prevent the history from growing too large |
752 | | - if readline.get_current_history_length() > self.histfile_size: |
753 | | - readline.remove_history_item(0) |
754 | | - |
755 | 736 | inp = line # assigning line to input value |
756 | 737 |
|
757 | 738 | x = None |
@@ -1031,7 +1012,6 @@ def api_remote( |
1031 | 1012 | """ |
1032 | 1013 |
|
1033 | 1014 | global MAGIC_PROMPT |
1034 | | - # GLOBAL_SETTINGS["display"] = "notebook" |
1035 | 1015 |
|
1036 | 1016 | initialise() |
1037 | 1017 |
|
@@ -1066,14 +1046,7 @@ def api_remote( |
1066 | 1046 | set_context(magic_prompt, x) |
1067 | 1047 |
|
1068 | 1048 | magic_prompt.api_variables = api_var_list |
1069 | | - # We now manage history. The history sometimes gets corrupted through no fault of ours. |
1070 | | - # If so, we just reset it. |
1071 | | - try: |
1072 | | - readline.read_history_file(magic_prompt.histfile) |
1073 | | - except Exception: # pylint: disable=broad-exception-caught # could be a number of errors |
1074 | | - readline.add_history("") |
1075 | | - readline.write_history_file(magic_prompt.histfile) |
1076 | | - readline.read_history_file(magic_prompt.histfile) |
| 1049 | + |
1077 | 1050 | for i in arguments: |
1078 | 1051 | inp = inp + a_space + i |
1079 | 1052 | a_space = " " |
@@ -1105,9 +1078,8 @@ def api_remote( |
1105 | 1078 | # Note, may be possible add code completion here #revisit |
1106 | 1079 | else: |
1107 | 1080 | magic_prompt.preloop() |
1108 | | - magic_prompt.add_history(inp) |
| 1081 | + add_history_entry(magic_prompt, inp) |
1109 | 1082 | magic_prompt.postloop() |
1110 | | - readline.write_history_file(magic_prompt.histfile) |
1111 | 1083 |
|
1112 | 1084 | result = magic_prompt.default(inp) |
1113 | 1085 |
|
@@ -1171,15 +1143,15 @@ def cmd_line(): |
1171 | 1143 | and command_line.settings["context"] == words[2 + word_increment].upper() |
1172 | 1144 | ): |
1173 | 1145 | command_line.preloop() |
1174 | | - command_line.add_history(str(" ".join(words[3 + word_increment :])).strip()) |
| 1146 | + add_history_entry(command_line, str(" ".join(words[3 + word_increment :])).strip()) |
1175 | 1147 | command_line.postloop() |
1176 | 1148 | result = command_line.default(str(" ".join(words[3 + word_increment :])).strip()) |
1177 | 1149 | else: |
1178 | 1150 | # If there is an argument and it is not help, attempt to run the command |
1179 | 1151 | # Note, may be possible add code completion here #revisit |
1180 | 1152 |
|
1181 | 1153 | command_line.preloop() |
1182 | | - command_line.add_history(inp[+increment:].strip()) |
| 1154 | + add_history_entry(command_line, inp[+increment:].strip()) |
1183 | 1155 | command_line.postloop() |
1184 | 1156 | result = command_line.default(inp[+increment:].strip()) |
1185 | 1157 | command_line.do_exit("dummy do not remove") |
|
0 commit comments