Improve 'info' command draw speed

This commit is contained in:
Andrew Resch 2009-10-31 18:52:52 +00:00
parent 3b07cc40bd
commit 2a4cf7cb56
3 changed files with 26 additions and 4 deletions

View File

@ -136,6 +136,8 @@ class Command(BaseCommand):
:param verbose: bool, if true, we print out more information about the :param verbose: bool, if true, we print out more information about the
the torrent the torrent
""" """
self.console.set_batch_write(True)
self.console.write(" ") self.console.write(" ")
self.console.write("{!info!}Name: {!input!}%s" % (status["name"])) self.console.write("{!info!}Name: {!input!}%s" % (status["name"]))
self.console.write("{!info!}ID: {!input!}%s" % (torrent_id)) self.console.write("{!info!}ID: {!input!}%s" % (torrent_id))
@ -223,6 +225,8 @@ class Command(BaseCommand):
self.console.write(s[:-1]) self.console.write(s[:-1])
self.console.set_batch_write(False)
def complete(self, line): def complete(self, line):
# We use the ConsoleUI torrent tab complete method # We use the ConsoleUI torrent tab complete method
return component.get("ConsoleUI").tab_complete_torrent(line) return component.get("ConsoleUI").tab_complete_torrent(line)

View File

@ -237,6 +237,19 @@ class ConsoleUI(component.Component):
def update(self): def update(self):
pass pass
def set_batch_write(self, batch):
"""
When this is set the screen is not refreshed after a `:meth:write` until
this is set to False.
:param batch: set True to prevent screen refreshes after a `:meth:write`
:type batch: bool
"""
self.batch_write = batch
if not batch:
self.screen.refresh()
def write(self, line): def write(self, line):
""" """
Writes a line out depending on if we're in interactive mode or not. Writes a line out depending on if we're in interactive mode or not.
@ -245,7 +258,7 @@ class ConsoleUI(component.Component):
""" """
if self.interactive: if self.interactive:
self.screen.add_line(line) self.screen.add_line(line, not self.batch_write)
else: else:
print(colors.strip_colors(line)) print(colors.strip_colors(line))

View File

@ -129,7 +129,7 @@ class Screen(CursesStdIO):
def connectionLost(self, reason): def connectionLost(self, reason):
self.close() self.close()
def add_line(self, text): def add_line(self, text, refresh=True):
""" """
Add a line to the screen. This will be showed between the two bars. Add a line to the screen. This will be showed between the two bars.
The text can be formatted with color using the following format: The text can be formatted with color using the following format:
@ -149,7 +149,11 @@ class Screen(CursesStdIO):
"{!info!}I am some info text!" "{!info!}I am some info text!"
"{!error!}Uh oh!" "{!error!}Uh oh!"
:param text: str, the text to show :param text: the text to show
:type text: string
:param refresh: if True, the screen will refresh after the line is added
:type refresh: bool
""" """
def get_line_chunks(line): def get_line_chunks(line):
@ -219,7 +223,8 @@ class Screen(CursesStdIO):
# Remove the oldest line if the max buffer size has been reached # Remove the oldest line if the max buffer size has been reached
del self.lines[0] del self.lines[0]
self.refresh() if refresh:
self.refresh()
def add_string(self, row, string): def add_string(self, row, string):
""" """