Skip to content

Commit b9c766d

Browse files
ccalmelsClement Calmels
authored andcommitted
Add a way to provide a complete method to a gdb.Command
Currently only a gdb.COMPLETE_xxx constant can be used to specify the complete policy of a Dashboad.Module commands. This patch allows to pass a callable that will provide a complete method to the gdb.Command. An example: class Example(Dashboard.Module): """ Example """ def __init__(self): super().__init__() def lines(self, term_width, term_height, style_changed): return [] def do(self, arg): pass def do_complete(self, text, word): values = ['abc', 'aab', 'aaa'] return [x for x in values if x.startswith(word)] def commands(self): return { 'do': { 'action': self.do, 'doc': 'do something', 'complete': self.do_complete, } }
1 parent 80835e2 commit b9c766d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

.gdbinit

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -674,8 +674,14 @@ class Dashboard(gdb.Command):
674674

675675
@staticmethod
676676
def create_command(name, invoke, doc, is_prefix, complete=None):
677-
Class = type('', (gdb.Command,), {'invoke': invoke, '__doc__': doc})
678-
Class(name, gdb.COMMAND_USER, complete or gdb.COMPLETE_NONE, is_prefix)
677+
if callable(complete):
678+
Class = type('', (gdb.Command,), {'invoke': invoke,
679+
'complete': complete,
680+
'__doc__': doc})
681+
Class(name, gdb.COMMAND_USER, prefix=is_prefix)
682+
else:
683+
Class = type('', (gdb.Command,), {'invoke': invoke, '__doc__': doc})
684+
Class(name, gdb.COMMAND_USER, complete or gdb.COMPLETE_NONE, is_prefix)
679685

680686
@staticmethod
681687
def err(string):

0 commit comments

Comments
 (0)