def run(args: HintsCLIOptions, text: str, extra_cli_args: Sequence[str] = ()) -> Optional[Dict[str, Any]]: try: text = parse_input(text) pattern, post_processors = functions_for(args) if args.type == 'linenum': args.customize_processing = '::linenum::' if args.customize_processing: m = load_custom_processor(args.customize_processing) if 'mark' in m: all_marks = tuple(m['mark'](text, args, Mark, extra_cli_args)) else: all_marks = tuple(mark(pattern, post_processors, text, args)) else: all_marks = tuple(mark(pattern, post_processors, text, args)) if not all_marks: input(_('No {} found, press Enter to quit.').format( 'URLs' if args.type == 'url' else 'matches' )) return None largest_index = all_marks[-1].index offset = max(0, args.hints_offset) for m in all_marks: if args.ascending: m.index += offset else: m.index = largest_index - m.index + offset index_map = {m.index: m for m in all_marks} except Exception: import traceback traceback.print_exc() input('Press Enter to quit.') raise SystemExit(1) return run_loop(args, text, all_marks, index_map, extra_cli_args)
def run(args: HintsCLIOptions, text: str, extra_cli_args: Sequence[str] = ()) -> Optional[Dict[str, Any]]: try: text = parse_input(text) text, hyperlinks = process_escape_codes(text) pattern, post_processors = functions_for(args) if args.type == 'linenum': args.customize_processing = '::linenum::' if args.type == 'hyperlink': all_marks = hyperlinks elif args.customize_processing: m = load_custom_processor(args.customize_processing) if 'mark' in m: all_marks = tuple(m['mark'](text, args, Mark, extra_cli_args)) else: all_marks = tuple(mark(pattern, post_processors, text, args)) else: all_marks = tuple(mark(pattern, post_processors, text, args)) if not all_marks: none_of = {'url': 'URLs', 'hyperlink': 'hyperlinks'}.get(args.type, 'matches') report_error(_('No {} found.').format(none_of)) return None largest_index = all_marks[-1].index offset = max(0, args.hints_offset) for m in all_marks: if args.ascending: m.index += offset else: m.index = largest_index - m.index + offset index_map = {m.index: m for m in all_marks} except Exception: report_unhandled_error() return run_loop(args, text, all_marks, index_map, extra_cli_args)