Esempio n. 1
0
def find_completions(words: Sequence[str], new_word: bool, entry_points: Iterable[str], namespaced_entry_points: Iterable[str]) -> Completions:
    ans = Completions()
    if not words or words[0] != 'kitty':
        return ans
    words = words[1:]
    if not words or (len(words) == 1 and not new_word):
        if words and words[0].startswith('--') and '=' in words[0]:
            complete_cli(ans, words, new_word, options_for_completion(), complete_kitty_cli_arg)
            return ans
        prefix = words[0] if words else ''
        completions_for_first_word(ans, prefix, entry_points, namespaced_entry_points)
        kitty_cli_opts(ans, prefix)
        return ans
    if words[0] == '@':
        if len(words) == 1 or (len(words) == 2 and not new_word):
            prefix = words[1] if len(words) > 1 else ''
            ans.add_match_group('Remote control commands', {c: '' for c in remote_control_command_names() if c.startswith(prefix)})
        else:
            complete_remote_command(ans, words[1], words[2:], new_word)
        return ans
    if words[0].startswith('@'):
        if len(words) == 1 and not new_word:
            prefix = words[0]
            ans.add_match_group('Remote control commands', {f'@{c}': '' for c in remote_control_command_names() if c.startswith(prefix)})
        else:
            complete_remote_command(ans, words[0][1:], words[1:], new_word)
    if words[0] == '+':
        if len(words) == 1 or (len(words) == 2 and not new_word):
            prefix = words[1] if len(words) > 1 else ''
            ans.add_match_group('Entry points', {c: '' for c in namespaced_entry_points if c.startswith(prefix)})
        else:
            if words[1] == 'kitten':
                if len(words) == 2 or (len(words) == 3 and not new_word):
                    ans.add_match_group('Kittens', (k for k in all_kitten_names() if k.startswith('' if len(words) == 2 else words[2])))
                else:
                    complete_kitten(ans, words[2], words[3:], new_word)
        return ans
    if words[0].startswith('+'):
        if len(words) == 1:
            if new_word:
                if words[0] == '+kitten':
                    ans.add_match_group('Kittens', all_kitten_names())
            else:
                prefix = words[0]
                ans.add_match_group('Entry points', (c for c in namespaced_entry_points if c.startswith(prefix)))
        else:
            if len(words) == 2 and not new_word:
                ans.add_match_group('Kittens', (k for k in all_kitten_names() if k.startswith(words[1])))
            else:
                if words[0] == '+kitten':
                    complete_kitten(ans, words[1], words[2:], new_word)
    else:
        complete_cli(ans, words, new_word, options_for_completion(), complete_kitty_cli_arg)

    return ans
Esempio n. 2
0
def write_cli_docs():
    from kitty.cli import option_spec_as_rst
    with open('generated/cli-kitty.rst', 'w') as f:
        f.write(
            option_spec_as_rst(appname='kitty').replace(
                'kitty --to', 'kitty @ --to'))
    as_rst = partial(option_spec_as_rst, heading_char='_')
    from kitty.remote_control import global_options_spec, cli_msg, cmap, all_commands
    with open('generated/cli-kitty-at.rst', 'w') as f:
        p = partial(print, file=f)
        p('kitty @\n' + '-' * 80)
        p('.. program::', 'kitty @')
        p('\n\n' + as_rst(global_options_spec,
                          message=cli_msg,
                          usage='command ...',
                          appname='kitty @'))
        from kitty.cmds import cli_params_for
        for cmd_name in all_commands:
            func = cmap[cmd_name]
            p('kitty @', func.name + '\n' + '-' * 120)
            p('.. program::', 'kitty @', func.name)
            p('\n\n' + as_rst(*cli_params_for(func)))
    from kittens.runner import all_kitten_names, get_kitten_cli_docs
    for kitten in all_kitten_names():
        data = get_kitten_cli_docs(kitten)
        if data:
            with open(f'generated/cli-kitten-{kitten}.rst', 'w') as f:
                p = partial(print, file=f)
                p('.. program::', f'kitty +kitten {kitten}')
                p('\n\n' +
                  option_spec_as_rst(data['options'],
                                     message=data['help_text'],
                                     usage=data['usage'],
                                     appname=f'kitty +kitten {kitten}',
                                     heading_char='^'))
Esempio n. 3
0
def setup(app):
    os.makedirs('generated/conf', exist_ok=True)
    from kittens.runner import all_kitten_names
    all_kitten_names = all_kitten_names()
    write_cli_docs(all_kitten_names)
    write_conf_docs(app, all_kitten_names)
    app.add_lexer('session', SessionLexer())
    app.add_role('link', link_role)
    app.add_role('iss', partial(num_role, 'issues'))
    app.add_role('pull', partial(num_role, 'pull'))
    app.add_role('commit', commit_role)
    app.connect('html-page-context', add_html_context)
Esempio n. 4
0
def setup(app: Any) -> None:
    os.makedirs('generated/conf', exist_ok=True)
    from kittens.runner import all_kitten_names
    kn = all_kitten_names()
    write_cli_docs(kn)
    write_remote_control_protocol_docs()
    write_conf_docs(app, kn)
    app.add_lexer('session', SessionLexer() if version_info[0] < 3 else SessionLexer)
    app.add_role('link', link_role)
    app.add_role('iss', partial(num_role, 'issues'))
    app.add_role('pull', partial(num_role, 'pull'))
    app.add_role('commit', commit_role)
    app.connect('html-page-context', add_html_context)
Esempio n. 5
0
def setup(app):
    try:
        os.mkdir('generated')
    except FileExistsError:
        pass
    from kittens.runner import all_kitten_names
    all_kitten_names = all_kitten_names()
    write_cli_docs(all_kitten_names)
    write_conf_docs(app, all_kitten_names)
    app.add_lexer('session', SessionLexer())
    app.add_role('link', link_role)
    app.add_role('iss', partial(num_role, 'issues'))
    app.add_role('pull', partial(num_role, 'pull'))
    app.add_role('commit', commit_role)
    app.connect('html-page-context', add_html_context)
Esempio n. 6
0
def setup(app: Any) -> None:
    os.makedirs('generated/conf', exist_ok=True)
    from kittens.runner import all_kitten_names
    kn = all_kitten_names()
    write_cli_docs(kn)
    write_remote_control_protocol_docs()
    write_conf_docs(app, kn)
    app.add_config_value('analytics_id', '', 'env')
    app.connect('html-page-context', add_html_context)
    app.add_lexer('session', SessionLexer() if version_info[0] < 3 else SessionLexer)
    app.add_role('link', link_role)
    app.add_role('commit', commit_role)
    # monkey patch sphinx_inline_tabs to avoid a warning about parallel reads
    # see https://github.com/pradyunsg/sphinx-inline-tabs/issues/26
    inline_tabs = app.extensions['sphinx_inline_tabs']
    inline_tabs.parallel_read_safe = inline_tabs.parallel_write_safe = True
Esempio n. 7
0
def find_completions(words, new_word, entry_points, namespaced_entry_points):
    ans = Completions()
    if not words or words[0] != 'kitty':
        return ans
    words = words[1:]
    if not words or (len(words) == 1 and not new_word):
        prefix = words[0] if words else ''
        completions_for_first_word(ans, prefix, entry_points,
                                   namespaced_entry_points)
        kitty_cli_opts(ans, prefix)
        return ans
    if words[0] == '@':
        if len(words) == 1 or (len(words) == 2 and not new_word):
            prefix = words[1] if len(words) > 1 else ''
            ans.match_groups['Remote control commands'] = {
                c: None
                for c in cmap if c.startswith(prefix)
            }
        else:
            complete_remote_command(ans, words[1], words[2:], new_word)
        return ans
    if words[0].startswith('@'):
        if len(words) == 1 and not new_word:
            prefix = words[0]
            ans.match_groups['Remote control commands'] = {
                '@' + c: None
                for c in cmap if c.startswith(prefix)
            }
        else:
            complete_remote_command(ans, words[0][1:], words[1:], new_word)
    if words[0] == '+':
        if len(words) == 1 or (len(words) == 2 and not new_word):
            prefix = words[1] if len(words) > 1 else ''
            ans.match_groups['Entry points'] = {
                c: None
                for c in namespaced_entry_points if c.startswith(prefix)
            }
        else:
            if words[1] == 'kitten':
                if len(words) == 2 or (len(words) == 3 and not new_word):
                    ans.match_groups['Kittens'] = dict.fromkeys(
                        k for k in all_kitten_names()
                        if k.startswith('' if len(words) == 2 else words[2]))
                else:
                    complete_kitten(ans, words[2], words[3:], new_word)
        return ans
    if words[0].startswith('+'):
        if len(words) == 1:
            if new_word:
                if words[0] == '+kitten':
                    ans.match_groups['Kittens'] = dict.fromkeys(
                        all_kitten_names())
            else:
                prefix = words[0]
                ans.match_groups['Entry points'] = {
                    c: None
                    for c in namespaced_entry_points if c.startswith(prefix)
                }
        else:
            if len(words) == 2 and not new_word:
                ans.match_groups['Kittens'] = dict.fromkeys(
                    k for k in all_kitten_names() if k.startswith(words[1]))
            else:
                if words[0] == '+kitten':
                    complete_kitten(ans, words[1], words[2:], new_word)
    else:
        complete_cli(ans, words, new_word, options_for_completion(),
                     complete_kitty_cli_arg)

    return ans
Esempio n. 8
0
 def test_all_kitten_names(self) -> None:
     from kittens.runner import all_kitten_names
     names = all_kitten_names()
     self.assertIn('diff', names)
     self.assertIn('hints', names)
     self.assertGreater(len(names), 8)
Esempio n. 9
0
def prewarm() -> None:
    from kittens.runner import all_kitten_names
    for kitten in all_kitten_names():
        with suppress(Exception):
            import_module(f'kittens.{kitten}.main')
    import_module('kitty.complete')