~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shell.py

  • Committer: Aaron Bentley
  • Date: 2005-11-15 18:14:05 UTC
  • mto: (283.2.1 bzrtools2)
  • mto: This revision was merged to the branch mainline in revision 285.
  • Revision ID: abentley@panoramicfeedback.com-20051115181405-62626c6d828b32cc
Got completions working properly

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
        self.arg_pos = None
41
41
 
42
42
    def get_completions(self):
43
 
        if not command:
44
 
            iter = (c for c in iter_command_names() if
 
43
        try:
 
44
            return self.get_completions_or_raise()
 
45
        except Exception, e:
 
46
            print e, type(e)
 
47
            return []
 
48
 
 
49
    def get_option_completions(self):
 
50
        try:
 
51
            command_obj = get_cmd_object(self.command)
 
52
        except BzrError:
 
53
            return []
 
54
        opts = [o+" " for o in iter_opt_completions(command_obj)]
 
55
        return list(filter_completions(opts, self.text))
 
56
 
 
57
    def get_completions_or_raise(self):
 
58
        if self.command is None:
 
59
            iter = (c+" " for c in iter_command_names() if
45
60
                    c not in COMPLETION_BLACKLIST)
46
 
            try:
47
 
                iter = list(filter_completions(iter, text))
48
 
            except Exception, e:
49
 
                print e, type(e)
50
 
 
 
61
            return list(filter_completions(iter, self.text))
 
62
        if self.prev_opt is None:
 
63
            completions = self.get_option_completions()
 
64
            if self.command == "cd":
 
65
                iter = iter_dir_completions(self.text)
 
66
                completions.extend(list(filter_completions(iter, self.text)))
 
67
            else:
 
68
                iter = iter_file_completions(self.text)
 
69
                completions.extend([f+" " for f in 
 
70
                                    filter_completions(iter, self.text)])
 
71
            return completions 
51
72
 
52
73
 
53
74
class PromptCmd(cmd.Cmd):
161
182
 
162
183
 
163
184
    def completenames(self, text, line, begidx, endidx):
164
 
        from bzrlib.trace import mutter
165
 
        completions = []
166
 
        iter = (c for c in iter_command_names() if
167
 
                c not in COMPLETION_BLACKLIST)
168
 
        try:
169
 
            if len(line) > 0:
170
 
                arg = line.split()[-1]
171
 
            else:
172
 
                arg = ""
173
 
            iter = filter_completions(iter, arg)
174
 
        except Exception, e:
175
 
            print e, type(e)
176
 
        return list(iter)
 
185
        return CompletionContext(text).get_completions()
177
186
 
178
187
    def completedefault(self, text, line, begidx, endidx):
179
188
        """Perform completion for native commands.
189
198
        """
190
199
        (cmd, args, foo) = self.parseline(line)
191
200
        if cmd == "bzr":
192
 
            try:
193
 
                return self.completenames(text, line, begidx, endidx)
194
 
            except Exception, e:
195
 
                print e
196
 
        try:
197
 
            command_obj = get_cmd_object(cmd)
198
 
        except BzrError:
199
 
            command_obj = None
200
 
        try:
201
 
            if command_obj is not None:
202
 
                opts = list(iter_opt_completions(command_obj))
203
 
                files = list(iter_file_completions(text))
204
 
                return list(filter_completions(opts+files, text))
205
 
            elif cmd == "cd":
206
 
                if len(args) > 0:
207
 
                    arg = args.split()[-1]
208
 
                else:
209
 
                    arg = ""
210
 
                iter = iter_dir_completions(text)
211
 
                iter = filter_completions(iter, text)
212
 
                return list(iter)
213
 
            elif len(args)>0:
214
 
                arg = args.split()[-1]
215
 
                iter = iter_file_completions(arg)
216
 
                return list(iter_munged_completions(iter, arg, text))
217
 
            else:
218
 
                return self.completenames(text, line, begidx, endidx)
219
 
        except Exception, e:
220
 
            print e
 
201
            cmd = None
 
202
        return CompletionContext(text, command=cmd).get_completions()
221
203
 
222
204
def run_shell():
223
205
    try: