Improve command logging and terminal display formatting

- Simplify command logging messages with concise `[CMD]` prefix
- Remove redundant command attempt counter from log messages
- Modify TerminalWidget to handle `[CMD]` tagged messages
- Enhance command display with consistent formatting and separators
This commit is contained in:
2025-02-19 20:56:25 +03:00
parent e6766660c6
commit f45f1bf556

View File

@@ -286,7 +286,7 @@ def execute_commands_from_file(
max_attempts = 3
attempt = 0
while attempt < max_attempts:
msg = f"\nОтправка команды: {cmd} (Попытка {attempt+1} из {max_attempts})\n"
msg = f"[CMD] {cmd}" # Изменено форматирование для команды
if log_callback:
log_callback(msg)
serial_connection.write((cmd + "\n").encode())
@@ -327,7 +327,7 @@ def execute_commands_from_file(
elif copy_mode == "block":
blocks = generate_command_blocks(lines, block_size)
for block in blocks:
msg = f"\nОтправка блока команд:\n{block}\n"
msg = f"[CMD] Отправка блока команд:\n{block}" # Изменено форматирование для блока команд
if log_callback:
log_callback(msg)
serial_connection.write((block + "\n").encode())
@@ -350,7 +350,7 @@ def execute_commands_from_file(
max_attempts = 3
attempt = 0
while attempt < max_attempts:
sub_msg = f"\nОтправка команды: {cmd} (Попытка {attempt+1} из {max_attempts})\n"
sub_msg = f"[CMD] {cmd}" # Изменено форматирование для команды
if log_callback:
log_callback(sub_msg)
serial_connection.write((cmd + "\n").encode())
@@ -705,12 +705,6 @@ class TerminalWidget(CustomText):
Добавление текста с определенным типом сообщения
message_type может быть: 'error', 'warning', 'info', 'command'
"""
# Добавляем разделитель между командами
if message_type == "command":
if self.command_counter > 0:
self.insert(tk.END, "\n" + "" * 80 + "\n", "separator")
self.command_counter += 1
# Добавляем текст
if not text.endswith('\n'):
text += '\n'
@@ -742,7 +736,13 @@ class TerminalWidget(CustomText):
self.append_text(text, "info")
def append_command(self, text):
"""Добавление команды"""
"""Добавление команды с разделителем"""
# Добавляем разделитель между командами
if self.command_counter > 0:
self.insert(tk.END, "\n" + "" * 80 + "\n", "separator")
self.command_counter += 1
# Добавляем команду
self.append_text(text, "command")
def clear(self):
@@ -1042,6 +1042,8 @@ class SerialAppGUI(tk.Tk):
self.file_exec_text.append_warning(text)
elif "[INFO]" in text:
self.file_exec_text.append_info(text)
elif "[CMD]" in text: # Добавляем обработку команд
self.file_exec_text.append_command(text)
else:
self.file_exec_text.append_text(text)