Changeset 925dcd


Ignore:
Timestamp:
04/28/2009 01:15:12 AM (16 years ago)
Author:
Andrew Resch <andrewresch@gmail.com>
Branches:
2.0.x, develop, extjs4-port, master
Children:
7b72d7
Parents:
d4cfeb
Message:

Fix up tab-completion to use the commands 'complete' method

Location:
deluge/ui/console
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • deluge/ui/console/commands/config.py

    rd4cfeb r925dcd  
    135135        client.core.set_config({key: val}).addCallback(on_set_config)
    136136
    137 """
    138     def complete(self, text, *args):
    139         keys = []
    140         def _on_get_config(config):
    141             keys.extend(config.keys())
    142         client.get_config(_on_get_config)
    143         client.force_call()
    144         return [ k for k in keys if k.startswith(text) ]
    145 
    146     def split(self, text):
    147         return str.split(text)"""
     137    def complete(self, text):
     138        return [ k for k in component.get("CoreConfig").keys() if k.startswith(text) ]
  • deluge/ui/console/commands/debug.py

    rd4cfeb r925dcd  
    2727import deluge.ui.console.colors as colors
    2828import deluge.log
     29import deluge.component as component
    2930
    3031class Command(BaseCommand):
     
    3738            deluge.log.setLoggerLevel("error")
    3839        else:
    39             console.write("{!error!}%s" % usage)
     40            component.get("ConsoleUI").write("{!error!}%s" % usage)
    4041
    41 #    def complete(self, text, *args):
    42 #        return [ x for x in ['on', 'off'] if x.startswith(text) ]
     42    def complete(self, text):
     43        return [x for x in ['on', 'off'] if x.startswith(text)]
  • deluge/ui/console/commands/help.py

    rd4cfeb r925dcd  
    5555            self.console.write(" ")
    5656            self.console.write('For help on a specific command, use "<command> --help"')
     57
     58    def complete(self, line):
     59        return [x for x in component.get("ConsoleUI")._commands if x.startswith(line)]
  • deluge/ui/console/commands/info.py

    rd4cfeb r925dcd  
    9393             "       You can give the first few characters of a torrent-id to identify the torrent."
    9494
    95 
    9695    def handle(self, *args, **options):
    9796        self.console = component.get("ConsoleUI")
     
    198197
    199198                self.console.write(s[:-1])
     199
     200    def complete(self, line):
     201        # We use the ConsoleUI torrent tab complete method
     202        return component.get("ConsoleUI").tab_complete_torrent(line)
  • deluge/ui/console/commands/pause.py

    rd4cfeb r925dcd  
    4747        if torrent_ids:
    4848            client.core.pause_torrent(torrent_ids)
     49
     50    def complete(self, line):
     51        # We use the ConsoleUI torrent tab complete method
     52        return component.get("ConsoleUI").tab_complete_torrent(line)
  • deluge/ui/console/commands/resume.py

    rd4cfeb r925dcd  
    4747        if torrent_ids:
    4848            client.core.resume_torrent(torrent_ids)
     49
     50    def complete(self, line):
     51        # We use the ConsoleUI torrent tab complete method
     52        return component.get("ConsoleUI").tab_complete_torrent(line)
  • deluge/ui/console/commands/rm.py

    rd4cfeb r925dcd  
    5151
    5252        client.core.remove_torrent(torrent_ids, options['remove_data'])
     53
     54    def complete(self, line):
     55        # We use the ConsoleUI torrent tab complete method
     56        return component.get("ConsoleUI").tab_complete_torrent(line)
  • deluge/ui/console/main.py

    rd4cfeb r925dcd  
    226226        """
    227227        Called when the user hits 'tab' and will autocomplete or show options.
     228        If a command is already supplied in the line, this function will call the
     229        complete method of the command.
    228230
    229231        :param line: str, the current input string
     
    238240        # command that needs to be completed.
    239241        if " " not in line:
    240             if len(line) == 0:
    241                 # We only print these out if it's a second_hit
    242                 if second_hit:
    243                     # There is nothing in line so just print out all possible commands
    244                     # and return.
    245                     self.write(" ")
    246                     for cmd in self._commands:
    247                         self.write(cmd)
    248                 return ("", 0)
     242            possible_matches = []
    249243            # Iterate through the commands looking for ones that startwith the
    250244            # line.
    251             possible_matches = []
    252245            for cmd in self._commands:
    253246                if cmd.startswith(line):
     
    255248
    256249            line_prefix = ""
    257 
    258250        else:
    259             # This isn't a command so treat it as a torrent_id or torrent name
    260             name = line.split(" ")[-1]
    261             if len(name) == 0:
    262                 # There is nothing in the string, so just display all possible options
    263                 if second_hit:
    264                     self.write(" ")
    265                     # Display all torrent_ids and torrent names
    266                     for torrent_id, name in self.torrents:
    267                         self.write(torrent_id)
    268                         self.write(name)
     251            cmd = line.split(" ")[0]
     252            if cmd in self._commands:
     253                # Call the command's complete method to get 'er done
     254                possible_matches = self._commands[cmd].complete(line.split(" ")[-1])
     255                line_prefix = " ".join(line.split(" ")[:-1]) + " "
     256            else:
     257                # This is a bogus command
    269258                return (line, cursor)
    270 
    271             # Find all possible matches
    272             possible_matches = []
    273             for torrent_id, torrent_name in self.torrents:
    274                 if torrent_id.startswith(name):
    275                     possible_matches.append(torrent_id)
    276                 elif torrent_name.startswith(name):
    277                     possible_matches.append(torrent_name)
    278 
    279             # Set the line prefix that should be prepended to any input line match
    280             line_prefix = " ".join(line.split(" ")[:-1]) + " "
    281259
    282260        # No matches, so just return what we got passed
     
    293271                # Only print these out if it's a second_hit
    294272                self.write(" ")
    295                 for cmd in possible_matches:
    296                     self.write(cmd)
     273                for match in possible_matches:
     274                    self.write(match)
    297275            return (line, cursor)
     276
     277    def tab_complete_torrent(self, line):
     278        """
     279        Completes torrent_ids or names.
     280
     281        :param line: str, the string to complete
     282
     283        :returns: list of matches
     284
     285        """
     286
     287        possible_matches = []
     288
     289        # Find all possible matches
     290        for torrent_id, torrent_name in self.torrents:
     291            if torrent_id.startswith(line):
     292                possible_matches.append(torrent_id)
     293            if torrent_name.startswith(line):
     294                possible_matches.append(torrent_name)
     295
     296        return possible_matches
    298297
    299298    def get_torrent_name(self, torrent_id):
Note: See TracChangeset for help on using the changeset viewer.