示例#1
0
 def format_usage(self, usage):
     from calibre.utils.terminal import colored
     parts = usage.split(' ')
     if parts:
         parts[0] = colored(parts[0], fg='yellow', bold=True)
     usage = ' '.join(parts)
     return colored(_('Usage'), fg='blue', bold=True) + ': ' + usage
示例#2
0
    def format_option(self, option):
        import textwrap
        from calibre.utils.terminal import colored

        result = []
        opts = self.option_strings[option]
        opt_width = self.help_position - self.current_indent - 2
        if len(opts) > opt_width:
            opts = "%*s%s\n" % (self.current_indent, "",
                                    colored(opts, fg='green'))
            indent_first = self.help_position
        else:                       # start help on same line as opts
            opts = "%*s%-*s  " % (self.current_indent, "", opt_width +
                    len(colored('', fg='green')), colored(opts, fg='green'))
            indent_first = 0
        result.append(opts)
        if option.help:
            help_text = self.expand_default(option).split('\n')
            help_lines = []

            for line in help_text:
                help_lines.extend(textwrap.wrap(line, self.help_width))
            result.append("%*s%s\n" % (indent_first, "", help_lines[0]))
            result.extend(["%*s%s\n" % (self.help_position, "", line)
                           for line in help_lines[1:]])
        elif opts[-1] != "\n":
            result.append("\n")
        return "".join(result)+'\n'
示例#3
0
文件: config.py 项目: zyhong/calibre
    def format_option(self, option):
        import textwrap
        from calibre.utils.terminal import colored

        result = []
        opts = self.option_strings[option]
        opt_width = self.help_position - self.current_indent - 2
        if len(opts) > opt_width:
            opts = "%*s%s\n" % (self.current_indent, "",
                                colored(opts, fg='green'))
            indent_first = self.help_position
        else:  # start help on same line as opts
            opts = "%*s%-*s  " % (self.current_indent, "", opt_width + len(
                colored('', fg='green')), colored(opts, fg='green'))
            indent_first = 0
        result.append(opts)
        if option.help:
            help_text = self.expand_default(option).split('\n')
            help_lines = []

            for line in help_text:
                help_lines.extend(textwrap.wrap(line, self.help_width))
            result.append("%*s%s\n" % (indent_first, "", help_lines[0]))
            result.extend([
                "%*s%s\n" % (self.help_position, "", line)
                for line in help_lines[1:]
            ])
        elif opts[-1] != "\n":
            result.append("\n")
        return "".join(result) + '\n'
示例#4
0
文件: config.py 项目: zyhong/calibre
 def format_usage(self, usage):
     from calibre.utils.terminal import colored
     parts = usage.split(' ')
     if parts:
         parts[0] = colored(parts[0], fg='yellow', bold=True)
     usage = ' '.join(parts)
     return colored(_('Usage'), fg='blue', bold=True) + ': ' + usage
示例#5
0
    def __init__(self,
                 usage='%prog [options] filename',
                 version=None,
                 epilog=None,
                 gui_mode=False,
                 conflict_handler='resolve',
                 **kwds):
        import textwrap
        from calibre.utils.terminal import colored

        usage = textwrap.dedent(usage)
        if epilog is None:
            epilog = _('Created by ')+colored(__author__, fg='cyan')
        usage += '\n\n'+_('''Whenever you pass arguments to %prog that have spaces in them, '''
                          '''enclose the arguments in quotation marks. For example: "{}"''').format(
                               "C:\\some path with spaces" if iswindows else '/some path/with spaces') +'\n'
        if version is None:
            version = '%%prog (%s %s)'%(__appname__, get_version())
        optparse.OptionParser.__init__(self, usage=usage, version=version, epilog=epilog,
                               formatter=CustomHelpFormatter(),
                               conflict_handler=conflict_handler, **kwds)
        self.gui_mode = gui_mode
        if False:
            # Translatable string from optparse
            _("Options")
            _("show this help message and exit")
            _("show program's version number and exit")
示例#6
0
文件: config.py 项目: zyhong/calibre
    def __init__(self,
                 usage='%prog [options] filename',
                 version=None,
                 epilog=None,
                 gui_mode=False,
                 conflict_handler='resolve',
                 **kwds):
        import textwrap
        from calibre.utils.terminal import colored

        usage = textwrap.dedent(usage)
        if epilog is None:
            epilog = _('Created by ') + colored(__author__, fg='cyan')
        usage += '\n\n' + _(
            '''Whenever you pass arguments to %prog that have spaces in them, '''
            '''enclose the arguments in quotation marks. For example: "{}"'''
        ).format("C:\\some path with spaces"
                 if iswindows else '/some path/with spaces') + '\n'
        if version is None:
            version = '%%prog (%s %s)' % (__appname__, get_version())
        optparse.OptionParser.__init__(self,
                                       usage=usage,
                                       version=version,
                                       epilog=epilog,
                                       formatter=CustomHelpFormatter(),
                                       conflict_handler=conflict_handler,
                                       **kwds)
        self.gui_mode = gui_mode
        if False:
            # Translatable string from optparse
            _("Options")
            _("show this help message and exit")
            _("show program's version number and exit")
示例#7
0
 def format_heading(self, heading):
     from calibre.utils.terminal import colored
     return "%*s%s:\n" % (self.current_indent, '',
                              colored(heading, fg='blue', bold=True))
示例#8
0
文件: config.py 项目: zyhong/calibre
 def format_heading(self, heading):
     from calibre.utils.terminal import colored
     return "%*s%s:\n" % (self.current_indent, '',
                          colored(heading, fg='blue', bold=True))