Exemplo n.º 1
0
def run(args, source_file=None):
    if source_file is None:
        text = sys.stdin.buffer.read().decode('utf-8')
        sys.stdin = open('/dev/tty')
    else:
        with open(source_file, 'r') as f:
            text = f.read()
    if args.regex is None:
        from .url_regex import url_delimiters
        url_pat = '(?:{})://[^{}]{{3,}}'.format(
            '|'.join(args.url_prefixes.split(',')), url_delimiters
        )
        finditer = partial(find_urls, re.compile(url_pat))
    else:
        finditer = partial(regex_finditer, re.compile(args.regex))
    lines = []
    index_map = {}
    for line in text.splitlines():
        marked = mark(finditer, line, index_map)
        lines.append(marked)
    if not index_map:
        input(_('No URLs found, press Enter to abort.'))
        return

    loop = Loop()
    handler = URLHints(lines, index_map)
    loop.loop(handler)
    if handler.chosen and loop.return_code == 0:
        cmd = command_for_open(args.program)
        ret = subprocess.Popen(cmd + [handler.chosen]).wait()
        if ret != 0:
            print('URL handler "{}" failed with return code: {}'.format(' '.join(cmd), ret), file=sys.stderr)
            input('Press Enter to quit')
            loop.return_code = ret
    raise SystemExit(loop.return_code)
Exemplo n.º 2
0
def run_loop(args, lines, index_map):
    loop = Loop()
    handler = URLHints(lines, index_map)
    loop.loop(handler)
    if handler.chosen and loop.return_code == 0:
        cmd = command_for_open(args.program)
        ret = subprocess.Popen(cmd + [handler.chosen]).wait()
        if ret != 0:
            print('URL handler "{}" failed with return code: {}'.format(
                ' '.join(cmd), ret),
                  file=sys.stderr)
            input('Press Enter to quit')
            loop.return_code = ret
    raise SystemExit(loop.return_code)
Exemplo n.º 3
0
def run_loop(args, lines, index_map):
    loop = Loop()
    handler = URLHints(lines, index_map)
    loop.loop(handler)
    if handler.chosen and loop.return_code == 0:
        if args.in_kitty:
            import json
            print('OK:', json.dumps({'url': handler.chosen, 'program': args.program, 'action': 'open_with'}))
        else:
            cmd = command_for_open(args.program)
            ret = subprocess.Popen(cmd + [handler.chosen]).wait()
            if ret != 0:
                print('URL handler "{}" failed with return code: {}'.format(' '.join(cmd), ret), file=sys.stderr)
                input('Press Enter to quit')
                loop.return_code = ret
    raise SystemExit(loop.return_code)
Exemplo n.º 4
0
def handle_result(args: List[str], data: Result, target_window_id: int,
                  boss: BossType) -> None:
    if data:
        from kitty.fast_data_types import get_options
        cmd = command_for_open(get_options().open_url_with)
        open_cmd(cmd, data)
Exemplo n.º 5
0
def handle_result(args: List[str], data: Result, target_window_id: int,
                  boss: BossType) -> None:
    if data:
        cmd = command_for_open(boss.opts.open_url_with)
        open_cmd(cmd, data)