Add /back command to return from messaging to node selection
This commit is contained in:
+30
-18
@@ -23,6 +23,7 @@ class MeshtasticCLI:
|
|||||||
self.exit_flag = False
|
self.exit_flag = False
|
||||||
self.selected_node = None
|
self.selected_node = None
|
||||||
self.debug_mode = debug_mode
|
self.debug_mode = debug_mode
|
||||||
|
self.current_mode = "node_selection" # Can be "node_selection" or "messaging"
|
||||||
|
|
||||||
def setup_exit_handler(self):
|
def setup_exit_handler(self):
|
||||||
"""Setup exit handler"""
|
"""Setup exit handler"""
|
||||||
@@ -212,9 +213,10 @@ class MeshtasticCLI:
|
|||||||
}
|
}
|
||||||
self.messages.append(msg)
|
self.messages.append(msg)
|
||||||
# Print new messages in real-time
|
# Print new messages in real-time
|
||||||
time_str = msg['time'].strftime('%Y-%m-%d %H:%M:%S')
|
if self.current_mode == "messaging":
|
||||||
print(f"\n[{time_str}] {msg['from']} ({msg['from_short']}) -> {msg['to']} ({msg['to_short']}): {msg['text']}")
|
time_str = msg['time'].strftime('%Y-%m-%d %H:%M:%S')
|
||||||
print("> ", end='', flush=True)
|
print(f"\n[{time_str}] {msg['from']} ({msg['from_short']}) -> {msg['to']} ({msg['to_short']}): {msg['text']}")
|
||||||
|
print("> ", end='', flush=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if self.debug_mode:
|
if self.debug_mode:
|
||||||
print(f"[DEBUG] Error processing packet: {e}")
|
print(f"[DEBUG] Error processing packet: {e}")
|
||||||
@@ -230,7 +232,7 @@ class MeshtasticCLI:
|
|||||||
print("Waiting for node activity...")
|
print("Waiting for node activity...")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
print(f"\nNodes active in the last hour ({len(recent_nodes)}):")
|
print(f"\nActive Nodes (Seen in the last hour) ({len(recent_nodes)}):")
|
||||||
node_list = list(recent_nodes.values())
|
node_list = list(recent_nodes.values())
|
||||||
for i, node in enumerate(node_list, 1):
|
for i, node in enumerate(node_list, 1):
|
||||||
time_ago = (datetime.now() - node['last_seen']).seconds // 60
|
time_ago = (datetime.now() - node['last_seen']).seconds // 60
|
||||||
@@ -295,16 +297,21 @@ class MeshtasticCLI:
|
|||||||
"""Main messaging loop"""
|
"""Main messaging loop"""
|
||||||
print("\n=== Messaging Interface ===")
|
print("\n=== Messaging Interface ===")
|
||||||
print("Type your message and press ENTER to send")
|
print("Type your message and press ENTER to send")
|
||||||
|
print("Type /back to return to node selection")
|
||||||
print("Type /quit to exit\n")
|
print("Type /quit to exit\n")
|
||||||
|
|
||||||
while not self.exit_flag:
|
while not self.exit_flag:
|
||||||
try:
|
try:
|
||||||
msg = input("> ").strip()
|
msg = input("> ").strip()
|
||||||
|
|
||||||
# Check for quit command
|
# Check for special commands
|
||||||
if msg.lower() == '/quit':
|
if msg.lower() == '/quit':
|
||||||
self.exit_program()
|
self.exit_program()
|
||||||
break
|
break
|
||||||
|
elif msg.lower() == '/back':
|
||||||
|
print("\nReturning to node selection...\n")
|
||||||
|
self.current_mode = "node_selection"
|
||||||
|
return False # Signal to go back
|
||||||
|
|
||||||
if self.exit_flag:
|
if self.exit_flag:
|
||||||
break
|
break
|
||||||
@@ -325,6 +332,7 @@ class MeshtasticCLI:
|
|||||||
self.interface.close()
|
self.interface.close()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
return True # Signal to exit
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Main program flow"""
|
"""Main program flow"""
|
||||||
@@ -387,21 +395,25 @@ class MeshtasticCLI:
|
|||||||
|
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
# Step 4: Select contact
|
# Main loop that allows switching between modes
|
||||||
while not self.exit_flag:
|
while not self.exit_flag:
|
||||||
node_list = self.list_recent_nodes()
|
if self.current_mode == "node_selection":
|
||||||
if node_list is None:
|
node_list = self.list_recent_nodes()
|
||||||
time.sleep(5)
|
if node_list is None:
|
||||||
continue
|
time.sleep(5)
|
||||||
|
continue
|
||||||
|
|
||||||
|
if self.select_contact(node_list):
|
||||||
|
self.current_mode = "messaging"
|
||||||
|
self.display_messages()
|
||||||
|
else:
|
||||||
|
continue # Refresh node list
|
||||||
|
|
||||||
if self.select_contact(node_list):
|
elif self.current_mode == "messaging":
|
||||||
break
|
should_exit = self.message_loop()
|
||||||
|
if should_exit:
|
||||||
# Step 5: Display message history
|
break # Exit program
|
||||||
self.display_messages()
|
# If we get here, user typed /back, so we'll loop again in node_selection mode
|
||||||
|
|
||||||
# Step 6: Enter messaging loop
|
|
||||||
self.message_loop()
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Parse command line arguments
|
# Parse command line arguments
|
||||||
|
|||||||
Reference in New Issue
Block a user