Command history now also is implemented
This commit is contained in:
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
1
bin/data/command_history.csv
Normal file
1
bin/data/command_history.csv
Normal file
@@ -0,0 +1 @@
|
||||
test,,test1,start,stop,stop,start
|
||||
|
@@ -24,4 +24,7 @@ Command:
|
||||
Button:
|
||||
text: "back"
|
||||
size_hint: 0.1, 0.1
|
||||
pos_hint: {"x": 0.02, "y": 0.02}
|
||||
pos_hint: {"x": 0.02, "y": 0.02}
|
||||
on_release:
|
||||
app.root.current = "HomeScreen"
|
||||
root.manager.transition.direction = "right"
|
||||
24
bin/others/history_manager.py
Normal file
24
bin/others/history_manager.py
Normal file
@@ -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)
|
||||
28
main.py
28
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)
|
||||
|
||||
Reference in New Issue
Block a user