mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-12 20:44:50 +00:00
Fix up tab-completion to use the commands 'complete' method
This commit is contained in:
parent
d4cfebadbc
commit
925dcd43b8
@ -134,14 +134,5 @@ class Command(BaseCommand):
|
|||||||
self.console.write("{!success!}Configuration value successfully updated.")
|
self.console.write("{!success!}Configuration value successfully updated.")
|
||||||
client.core.set_config({key: val}).addCallback(on_set_config)
|
client.core.set_config({key: val}).addCallback(on_set_config)
|
||||||
|
|
||||||
"""
|
def complete(self, text):
|
||||||
def complete(self, text, *args):
|
return [ k for k in component.get("CoreConfig").keys() if k.startswith(text) ]
|
||||||
keys = []
|
|
||||||
def _on_get_config(config):
|
|
||||||
keys.extend(config.keys())
|
|
||||||
client.get_config(_on_get_config)
|
|
||||||
client.force_call()
|
|
||||||
return [ k for k in keys if k.startswith(text) ]
|
|
||||||
|
|
||||||
def split(self, text):
|
|
||||||
return str.split(text)"""
|
|
||||||
|
@ -26,6 +26,7 @@ from deluge.ui.console.main import BaseCommand
|
|||||||
from deluge.ui.client import client
|
from deluge.ui.client import client
|
||||||
import deluge.ui.console.colors as colors
|
import deluge.ui.console.colors as colors
|
||||||
import deluge.log
|
import deluge.log
|
||||||
|
import deluge.component as component
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
"""Enable and disable debugging"""
|
"""Enable and disable debugging"""
|
||||||
@ -36,7 +37,7 @@ class Command(BaseCommand):
|
|||||||
elif state == 'off':
|
elif state == 'off':
|
||||||
deluge.log.setLoggerLevel("error")
|
deluge.log.setLoggerLevel("error")
|
||||||
else:
|
else:
|
||||||
console.write("{!error!}%s" % usage)
|
component.get("ConsoleUI").write("{!error!}%s" % usage)
|
||||||
|
|
||||||
# def complete(self, text, *args):
|
def complete(self, text):
|
||||||
# return [ x for x in ['on', 'off'] if x.startswith(text) ]
|
return [x for x in ['on', 'off'] if x.startswith(text)]
|
||||||
|
@ -54,3 +54,6 @@ class Command(BaseCommand):
|
|||||||
self.console.write("{!info!}" + cmd + "{!input!} - " + self._commands[cmd].__doc__ or '')
|
self.console.write("{!info!}" + cmd + "{!input!} - " + self._commands[cmd].__doc__ or '')
|
||||||
self.console.write(" ")
|
self.console.write(" ")
|
||||||
self.console.write('For help on a specific command, use "<command> --help"')
|
self.console.write('For help on a specific command, use "<command> --help"')
|
||||||
|
|
||||||
|
def complete(self, line):
|
||||||
|
return [x for x in component.get("ConsoleUI")._commands if x.startswith(line)]
|
||||||
|
@ -92,7 +92,6 @@ class Command(BaseCommand):
|
|||||||
usage = "Usage: info [<torrent-id> [<torrent-id> ...]]\n"\
|
usage = "Usage: info [<torrent-id> [<torrent-id> ...]]\n"\
|
||||||
" You can give the first few characters of a torrent-id to identify the torrent."
|
" You can give the first few characters of a torrent-id to identify the torrent."
|
||||||
|
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
self.console = component.get("ConsoleUI")
|
self.console = component.get("ConsoleUI")
|
||||||
# Compile a list of torrent_ids to request the status of
|
# Compile a list of torrent_ids to request the status of
|
||||||
@ -197,3 +196,7 @@ class Command(BaseCommand):
|
|||||||
s += "\n"
|
s += "\n"
|
||||||
|
|
||||||
self.console.write(s[:-1])
|
self.console.write(s[:-1])
|
||||||
|
|
||||||
|
def complete(self, line):
|
||||||
|
# We use the ConsoleUI torrent tab complete method
|
||||||
|
return component.get("ConsoleUI").tab_complete_torrent(line)
|
||||||
|
@ -46,3 +46,7 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
if torrent_ids:
|
if torrent_ids:
|
||||||
client.core.pause_torrent(torrent_ids)
|
client.core.pause_torrent(torrent_ids)
|
||||||
|
|
||||||
|
def complete(self, line):
|
||||||
|
# We use the ConsoleUI torrent tab complete method
|
||||||
|
return component.get("ConsoleUI").tab_complete_torrent(line)
|
||||||
|
@ -46,3 +46,7 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
if torrent_ids:
|
if torrent_ids:
|
||||||
client.core.resume_torrent(torrent_ids)
|
client.core.resume_torrent(torrent_ids)
|
||||||
|
|
||||||
|
def complete(self, line):
|
||||||
|
# We use the ConsoleUI torrent tab complete method
|
||||||
|
return component.get("ConsoleUI").tab_complete_torrent(line)
|
||||||
|
@ -50,3 +50,7 @@ class Command(BaseCommand):
|
|||||||
torrent_ids.extend(self.console.match_torrent(arg))
|
torrent_ids.extend(self.console.match_torrent(arg))
|
||||||
|
|
||||||
client.core.remove_torrent(torrent_ids, options['remove_data'])
|
client.core.remove_torrent(torrent_ids, options['remove_data'])
|
||||||
|
|
||||||
|
def complete(self, line):
|
||||||
|
# We use the ConsoleUI torrent tab complete method
|
||||||
|
return component.get("ConsoleUI").tab_complete_torrent(line)
|
||||||
|
@ -225,6 +225,8 @@ class ConsoleUI(component.Component):
|
|||||||
def tab_completer(self, line, cursor, second_hit):
|
def tab_completer(self, line, cursor, second_hit):
|
||||||
"""
|
"""
|
||||||
Called when the user hits 'tab' and will autocomplete or show options.
|
Called when the user hits 'tab' and will autocomplete or show options.
|
||||||
|
If a command is already supplied in the line, this function will call the
|
||||||
|
complete method of the command.
|
||||||
|
|
||||||
:param line: str, the current input string
|
:param line: str, the current input string
|
||||||
:param cursor: int, the cursor position in the line
|
:param cursor: int, the cursor position in the line
|
||||||
@ -237,48 +239,24 @@ class ConsoleUI(component.Component):
|
|||||||
# First check to see if there is no space, this will mean that it's a
|
# First check to see if there is no space, this will mean that it's a
|
||||||
# command that needs to be completed.
|
# command that needs to be completed.
|
||||||
if " " not in line:
|
if " " not in line:
|
||||||
if len(line) == 0:
|
possible_matches = []
|
||||||
# We only print these out if it's a second_hit
|
|
||||||
if second_hit:
|
|
||||||
# There is nothing in line so just print out all possible commands
|
|
||||||
# and return.
|
|
||||||
self.write(" ")
|
|
||||||
for cmd in self._commands:
|
|
||||||
self.write(cmd)
|
|
||||||
return ("", 0)
|
|
||||||
# Iterate through the commands looking for ones that startwith the
|
# Iterate through the commands looking for ones that startwith the
|
||||||
# line.
|
# line.
|
||||||
possible_matches = []
|
|
||||||
for cmd in self._commands:
|
for cmd in self._commands:
|
||||||
if cmd.startswith(line):
|
if cmd.startswith(line):
|
||||||
possible_matches.append(cmd)
|
possible_matches.append(cmd)
|
||||||
|
|
||||||
line_prefix = ""
|
line_prefix = ""
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# This isn't a command so treat it as a torrent_id or torrent name
|
cmd = line.split(" ")[0]
|
||||||
name = line.split(" ")[-1]
|
if cmd in self._commands:
|
||||||
if len(name) == 0:
|
# Call the command's complete method to get 'er done
|
||||||
# There is nothing in the string, so just display all possible options
|
possible_matches = self._commands[cmd].complete(line.split(" ")[-1])
|
||||||
if second_hit:
|
line_prefix = " ".join(line.split(" ")[:-1]) + " "
|
||||||
self.write(" ")
|
else:
|
||||||
# Display all torrent_ids and torrent names
|
# This is a bogus command
|
||||||
for torrent_id, name in self.torrents:
|
|
||||||
self.write(torrent_id)
|
|
||||||
self.write(name)
|
|
||||||
return (line, cursor)
|
return (line, cursor)
|
||||||
|
|
||||||
# Find all possible matches
|
|
||||||
possible_matches = []
|
|
||||||
for torrent_id, torrent_name in self.torrents:
|
|
||||||
if torrent_id.startswith(name):
|
|
||||||
possible_matches.append(torrent_id)
|
|
||||||
elif torrent_name.startswith(name):
|
|
||||||
possible_matches.append(torrent_name)
|
|
||||||
|
|
||||||
# Set the line prefix that should be prepended to any input line match
|
|
||||||
line_prefix = " ".join(line.split(" ")[:-1]) + " "
|
|
||||||
|
|
||||||
# No matches, so just return what we got passed
|
# No matches, so just return what we got passed
|
||||||
if len(possible_matches) == 0:
|
if len(possible_matches) == 0:
|
||||||
return (line, cursor)
|
return (line, cursor)
|
||||||
@ -292,10 +270,31 @@ class ConsoleUI(component.Component):
|
|||||||
if second_hit:
|
if second_hit:
|
||||||
# Only print these out if it's a second_hit
|
# Only print these out if it's a second_hit
|
||||||
self.write(" ")
|
self.write(" ")
|
||||||
for cmd in possible_matches:
|
for match in possible_matches:
|
||||||
self.write(cmd)
|
self.write(match)
|
||||||
return (line, cursor)
|
return (line, cursor)
|
||||||
|
|
||||||
|
def tab_complete_torrent(self, line):
|
||||||
|
"""
|
||||||
|
Completes torrent_ids or names.
|
||||||
|
|
||||||
|
:param line: str, the string to complete
|
||||||
|
|
||||||
|
:returns: list of matches
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
possible_matches = []
|
||||||
|
|
||||||
|
# Find all possible matches
|
||||||
|
for torrent_id, torrent_name in self.torrents:
|
||||||
|
if torrent_id.startswith(line):
|
||||||
|
possible_matches.append(torrent_id)
|
||||||
|
if torrent_name.startswith(line):
|
||||||
|
possible_matches.append(torrent_name)
|
||||||
|
|
||||||
|
return possible_matches
|
||||||
|
|
||||||
def get_torrent_name(self, torrent_id):
|
def get_torrent_name(self, torrent_id):
|
||||||
"""
|
"""
|
||||||
Gets a torrent name from the torrents list.
|
Gets a torrent name from the torrents list.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user