def _make_list(self, showlist): """ Helper function for printing a formatted show list """ # Fixed column widths col_id_length = 7 col_index_length = 6 col_title_length = 5 col_episodes_length = 9 col_score_length = 6 # Calculate maximum width for the title column # based on the width of the terminal (height, width) = utils.get_terminal_size() max_title_length = width - col_id_length - col_episodes_length - col_score_length - col_index_length - 5 # Find the widest title so we can adjust the title column for show in showlist: if len(show['title']) > col_title_length: if len(show['title']) > max_title_length: # Stop if we exceeded the maximum column width col_title_length = max_title_length break else: col_title_length = len(show['title']) # Print header print "| {0:{1}} {2:{3}} {4:{5}} {6:{7}} |".format( 'Index', col_index_length, 'Title', col_title_length, 'Progress', col_episodes_length, 'Score', col_score_length) # List shows for index, show in enumerate(showlist, 1): if self.engine.mediainfo['has_progress']: episodes_str = "{0:3} / {1}".format(show['my_progress'], show['total']) else: episodes_str = "-" # Truncate title if needed title_str = show['title'].encode('utf-8') title_str = title_str[:max_title_length] if len(title_str) > max_title_length else title_str # Color title according to status if show['status'] == utils.STATUS_AIRING: colored_title = _COLOR_AIRING + title_str + _COLOR_RESET else: colored_title = title_str print "| {0:^{1}} {2}{3} {4:{5}} {6:^{7}} |".format( index, col_index_length, colored_title, '.' * (col_title_length-len(show['title'])), episodes_str, col_episodes_length, show['my_score'], col_score_length) # Print result count print '%d results' % len(showlist) print
def _make_list(self, showlist): """ Helper function for printing a formatted show list """ # Fixed column widths col_id_length = 7 col_index_length = 6 col_title_length = 5 col_episodes_length = 9 col_score_length = 6 # Calculate maximum width for the title column # based on the width of the terminal (height, width) = utils.get_terminal_size() max_title_length = width - col_id_length - col_episodes_length - col_score_length - col_index_length - 5 # Find the widest title so we can adjust the title column for show in showlist: if len(show['title']) > col_title_length: if len(show['title']) > max_title_length: # Stop if we exceeded the maximum column width col_title_length = max_title_length break else: col_title_length = len(show['title']) # Print header print "| {0:{1}} {2:{3}} {4:{5}} {6:{7}} |".format( 'Index', col_index_length, 'Title', col_title_length, 'Progress', col_episodes_length, 'Score', col_score_length) # List shows for index, show in enumerate(showlist, 1): if self.engine.mediainfo['has_progress']: episodes_str = "{0:3} / {1}".format(show['my_progress'], show['total']) else: episodes_str = "-" # Truncate title if needed title_str = show['title'].encode('utf-8') title_str = title_str[:max_title_length] if len( title_str) > max_title_length else title_str # Color title according to status if show['status'] == utils.STATUS_AIRING: colored_title = _COLOR_AIRING + title_str + _COLOR_RESET else: colored_title = title_str print "| {0:^{1}} {2}{3} {4:{5}} {6:^{7}} |".format( index, col_index_length, colored_title, '.' * (col_title_length - len(show['title'])), episodes_str, col_episodes_length, show['my_score'], col_score_length) # Print result count print '%d results' % len(showlist) print
def do_help(self, arg): if arg: try: doc = getattr(self, 'do_' + arg).__doc__ if doc: (name, args, expl, usage) = self._parse_doc(arg, doc) print() print(name) for line in expl: print(" {}".format(line)) if args: print("\n Arguments:") for arg in args: if arg[2]: print(" {}: {}".format(arg[0], arg[1])) else: print(" {} (optional): {}".format(arg[0], arg[1])) if usage: print("\n Usage: " + usage) print() return except AttributeError: pass print("No help available.") return else: CMD_LENGTH = 11 ARG_LENGTH = 13 (height, width) = utils.get_terminal_size() prev_width = CMD_LENGTH + ARG_LENGTH + 3 tw = textwrap.TextWrapper() tw.width = width - 2 tw.subsequent_indent = ' ' * prev_width print() print(" {0:>{1}} {2:{3}} {4}".format( 'command', CMD_LENGTH, 'args', ARG_LENGTH, 'description')) print(" " + "-"*(min(prev_width+81, width-3))) names = self.get_names() names.sort() cmds = [] for name in names: if name[:3] == 'do_': doc = getattr(self, name).__doc__ if not doc: continue cmd = name[3:] (name, args, expl, usage) = self._parse_doc(cmd, doc) line = " {0:>{1}} {2:{3}} {4}".format( name, CMD_LENGTH, '<' + ','.join( a[0] for a in args) + '>', ARG_LENGTH, expl[0]) print(tw.fill(line)) print() print("Use `help <command>` for detailed information.") print()
def do_help(self, arg): if arg: try: doc = getattr(self, 'do_' + arg).__doc__ if doc: (name, args, expl, usage, examples) = self._parse_doc(arg, doc) print() print(name) for line in expl: print(" {}".format(line)) if args: print("\n Arguments:") for arg in args: if arg[2]: print(" {}: {}".format(arg[0], arg[1])) else: print(" {} (optional): {}".format(arg[0], arg[1])) if usage: print("\n Usage: " + usage) for example in examples: print(" Example: " + example) print() return except AttributeError: pass print("No help available.") return else: CMD_LENGTH = 11 ARG_LENGTH = 13 (height, width) = utils.get_terminal_size() prev_width = CMD_LENGTH + ARG_LENGTH + 3 tw = textwrap.TextWrapper() tw.width = width - 2 tw.subsequent_indent = ' ' * prev_width print() print(" {0:>{1}} {2:{3}} {4}".format( 'command', CMD_LENGTH, 'args', ARG_LENGTH, 'description')) print(" " + "-"*(min(prev_width+81, width-3))) names = self.get_names() names.sort() for name in names: if name[:3] == 'do_': doc = getattr(self, name).__doc__ if not doc: continue cmd = name[3:] (name, args, expl, usage, examples) = self._parse_doc(cmd, doc) line = " {0:>{1}} {2:{3}} {4}".format( name, CMD_LENGTH, '<' + ','.join( a[0] for a in args) + '>', ARG_LENGTH, expl[0]) print(tw.fill(line)) print() print("Use `help <command>` for detailed information.") print()
def _make_list(self, showlist): """ Helper function for printing a formatted show list """ # Fixed column widths col_id_length = 7 col_index_length = 6 col_title_length = 5 col_episodes_length = 9 col_score_length = 6 altnames = self.engine.altnames() # Calculate maximum width for the title column # based on the width of the terminal (height, width) = utils.get_terminal_size() max_title_length = width - col_id_length - col_episodes_length - col_score_length - col_index_length - 5 # Find the widest title so we can adjust the title column for index, show in showlist: if len(show["title"]) > col_title_length: if len(show["title"]) > max_title_length: # Stop if we exceeded the maximum column width col_title_length = max_title_length break else: col_title_length = len(show["title"]) # Print header print( "| {0:{1}} {2:{3}} {4:{5}} {6:{7}} |".format( "Index", col_index_length, "Title", max_title_length, "Progress", col_episodes_length, "Score", col_score_length, ) ) # List shows for index, show in showlist: if self.engine.mediainfo["has_progress"]: episodes_str = "{0:3} / {1}".format(show["my_progress"], show["total"]) else: episodes_str = "-" # Get title (and alt. title) and if need be, truncate it title_str = show["title"] if altnames.get(show["id"]): title_str += "[{}]".format(altnames.get(show["id"])) title_str = title_str[:max_title_length] if len(title_str) > max_title_length else title_str # Color title according to status if show["status"] == utils.STATUS_AIRING: colored_title = _COLOR_AIRING + title_str + _COLOR_RESET else: colored_title = title_str print( "| {0:^{1}} {2}{3} {4:{5}} {6:^{7}} |".format( index, col_index_length, colored_title, "." * (max_title_length - len(title_str)), episodes_str, col_episodes_length, show["my_score"], col_score_length, ) ) # Print result count print("%d results" % len(showlist)) print()