diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/bin/data/command_history.csv b/bin/data/command_history.csv new file mode 100644 index 0000000..dc62b25 --- /dev/null +++ b/bin/data/command_history.csv @@ -0,0 +1 @@ +test,,test1,start,stop,stop,start diff --git a/bin/gui/command_screen.kv b/bin/gui/command_screen.kv index 94de211..1ce9950 100644 --- a/bin/gui/command_screen.kv +++ b/bin/gui/command_screen.kv @@ -24,4 +24,7 @@ Command: Button: text: "back" size_hint: 0.1, 0.1 - pos_hint: {"x": 0.02, "y": 0.02} \ No newline at end of file + pos_hint: {"x": 0.02, "y": 0.02} + on_release: + app.root.current = "HomeScreen" + root.manager.transition.direction = "right" \ No newline at end of file diff --git a/bin/others/history_manager.py b/bin/others/history_manager.py new file mode 100644 index 0000000..090383b --- /dev/null +++ b/bin/others/history_manager.py @@ -0,0 +1,24 @@ +import bin.com.csv_parsers + +cvr = bin.com.csv_parsers.CsvRead() +cvw = bin.com.csv_parsers.CsvWrite() + + +class HistroyManager: + def __init__(self): + self.__history = [] + self.__history_mod = [] + + def append_history(self, command, path): + try: + self.__history_mod = cvr.importing(path).pop(0) + except IndexError: + pass + if command != "": + self.__history_mod.insert(0, command) + cvw.write_str(path, self.__history_mod) + else: + pass + + def get_history(self, path): + return cvr.importing(path) diff --git a/main.py b/main.py index 086e679..22f60a4 100644 --- a/main.py +++ b/main.py @@ -21,6 +21,7 @@ from kivy.clock import Clock from kivy.core.window import Window import bin.others.autocomplete import bin.others.run_command +import bin.others.history_manager ################################ @@ -31,6 +32,7 @@ config.read('./config/settings.ini') version_app = f"{config['Info']['version']}{config['Info']['subVersion']}" ac = bin.others.autocomplete.AutoComplete() rc = bin.others.run_command.RunCommand() +hm = bin.others.history_manager.HistroyManager() ################################ @@ -103,6 +105,31 @@ class Main(MDScreen): ################ class Command(MDScreen): + def __init__(self, **kwargs): + super().__init__(**kwargs) + self.keyboard = Window.request_keyboard(None, self) + self.keyboard.bind(on_key_down=self.key_pressed) + self.__pos = -1 + + def key_pressed(self, keyboard, keycode, text, modifiers): + self.key = keycode[1] + if self.key == "up": + self.__pos += 1 + self.__last_cmds = hm.get_history("./bin/data/command_history.csv").pop(0) + try: + self.ids.tin.text = self.__last_cmds.pop(self.__pos) + except IndexError: + self.__pos -= 1 + elif self.key == "down": + self.__pos -= 1 + self.__last_cmds = hm.get_history("./bin/data/command_history.csv").pop(0) + try: + self.ids.tin.text = self.__last_cmds.pop(self.__pos) + except IndexError: + self.__pos += 1 + else: + pass + def autocomplete(self): self.text = self.ids.tin.text self.input = self.text[len(self.text) - 1:] @@ -121,6 +148,7 @@ class Command(MDScreen): logger.debug(f"The following command has been run successfully: {self.ids.tin.text}") else: logger.debug(f"The following command has failed to run: {self.ids.tin.text}") + hm.append_history(self.ids.tin.text, "./bin/data/command_history.csv") self.ids.tin.text = "" self.__history = self.ids.cmd_out.text self.__output_text = self.__history + "\n\n" + str(self.__info)