Skip to content

Commit

Permalink
mavproxy_mode: Allow for mode names to be tab completed
Browse files Browse the repository at this point in the history
Adds tab completion of mode names when changing mode using the command 'mode <MODE>'.
Also prettifies printing of available modes - this previously printed an array of  'dict_keys([..], ...)'
  • Loading branch information
joshanne authored and peterbarker committed Dec 18, 2024
1 parent e45946a commit b39a31c
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions MAVProxy/modules/mavproxy_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
class ModeModule(mp_module.MPModule):
def __init__(self, mpstate):
super(ModeModule, self).__init__(mpstate, "mode", public=True)
self.add_command('mode', self.cmd_mode, "mode change", self.available_modes())
self.add_command('mode', self.cmd_mode, "mode change", [
'(MODE)'
])
self.add_command('guided', self.cmd_guided, "fly to a clicked location on map")
self.add_command('confirm', self.cmd_confirm, "confirm a command")
self.add_completion_function('(MODE)', self.complete_available_modes)

def cmd_mode(self, args):
'''set arbitrary mode'''
Expand All @@ -25,7 +28,7 @@ def cmd_mode(self, args):
print('No mode mapping available')
return
if len(args) != 1:
print('Available modes: ', mode_mapping.keys())
print('Available modes: ', ', '.join(self.available_modes()))
return
if args[0].isdigit():
modenum = int(args[0])
Expand All @@ -50,6 +53,9 @@ def cmd_confirm(self, args):
from MAVProxy.modules.lib import mp_menu
mp_menu.MPMenuConfirmDialog(question, callback=self.mpstate.functions.process_stdin, args=command)

def complete_available_modes(self, text):
return self.available_modes()

def available_modes(self):
if self.master is None:
print('No mode mapping available')
Expand Down

0 comments on commit b39a31c

Please sign in to comment.