From 22b8d29baaa719cd870cac0e90ba65ebe0ebf7a1 Mon Sep 17 00:00:00 2001 From: perrette Date: Tue, 27 Jun 2023 13:08:13 +0200 Subject: [PATCH] fix broken test in test_list.py (strip ansi links) --- papers/__main__.py | 15 +-------------- papers/utils.py | 28 ++++++++++++++++++++++++++++ tests/test_list.py | 10 +++++----- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/papers/__main__.py b/papers/__main__.py index 3653e51..a1b71c7 100644 --- a/papers/__main__.py +++ b/papers/__main__.py @@ -18,7 +18,7 @@ from papers.config import bcolors, Config, search_config, CONFIG_FILE, CONFIG_FILE_LOCAL, DATA_DIR, CONFIG_FILE_LEGACY, BACKUP_DIR from papers.duplicate import list_duplicates, list_uniques, edit_entries from papers.bib import Biblio, FUZZY_RATIO, DEFAULT_SIMILARITY, entry_filecheck, backupfile as backupfile_func, isvalidkey -from papers.utils import move, checksum +from papers.utils import move, checksum, ansi_link as link from papers import __version__ @@ -806,19 +806,6 @@ def parse_keywords(e): print(format_entries(entries)) -def link(uri, label=None): - """https://stackoverflow.com/a/71309268/2192272 - """ - if label is None: - label = uri - parameters = '' - - # OSC 8 ; params ; URI ST OSC 8 ;; ST - escape_mask = '\033]8;{};{}\033\\{}\033]8;;\033\\' - - return escape_mask.format(parameters, uri, label) - - def statuscmd(parser, o, config): print(config.status(check_files=not o.no_check_files, verbose=o.verbose)) diff --git a/papers/utils.py b/papers/utils.py index de6fc27..6c5a389 100644 --- a/papers/utils.py +++ b/papers/utils.py @@ -1,4 +1,5 @@ import os +import re import shutil import hashlib @@ -27,6 +28,33 @@ def strip_colors(s): return s +def ansi_link(uri, label=None): + """https://stackoverflow.com/a/71309268/2192272 + """ + if label is None: + label = uri + parameters = '' + + # OSC 8 ; params ; URI ST OSC 8 ;; ST + escape_mask = '\033]8;{};{}\033\\{}\033]8;;\033\\' + + return escape_mask.format(parameters, uri, label) + + +ANSI_LINK_RE = re.compile(r'(?P\033]8;(?P.*?);(?P.*?)\033\\(?P