hints kitten: Detect paths and hashes that appear over multiple lines
Fixes #3845
This commit is contained in:
parent
af956f4d84
commit
c566ed4643
@ -43,6 +43,12 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
|
|||||||
most other programs and allows long chains of them to look better
|
most other programs and allows long chains of them to look better
|
||||||
(:iss:`3844`)
|
(:iss:`3844`)
|
||||||
|
|
||||||
|
- hints kitten: Detect paths and hashes that appear over multiple lines.
|
||||||
|
Note that this means that all line breaks in the text are no longer \n
|
||||||
|
soft breaks are instead \r. If you use a custom regular expression that
|
||||||
|
is meant to match over line breaks, you will need to match over both.
|
||||||
|
(:iss:`3845`)
|
||||||
|
|
||||||
|
|
||||||
0.21.2 [2021-06-28]
|
0.21.2 [2021-06-28]
|
||||||
----------------------
|
----------------------
|
||||||
|
|||||||
@ -94,6 +94,11 @@ def highlight_mark(m: Mark, text: str, current_input: str, alphabet: str, colors
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def debug(*a: Any, **kw: Any) -> None:
|
||||||
|
from ..tui.loop import debug as d
|
||||||
|
d(*a, **kw)
|
||||||
|
|
||||||
|
|
||||||
def render(text: str, current_input: str, all_marks: Sequence[Mark], ignore_mark_indices: Set[int], alphabet: str, colors: Dict[str, str]) -> str:
|
def render(text: str, current_input: str, all_marks: Sequence[Mark], ignore_mark_indices: Set[int], alphabet: str, colors: Dict[str, str]) -> str:
|
||||||
for mark in reversed(all_marks):
|
for mark in reversed(all_marks):
|
||||||
if mark.index in ignore_mark_indices:
|
if mark.index in ignore_mark_indices:
|
||||||
@ -102,8 +107,7 @@ def render(text: str, current_input: str, all_marks: Sequence[Mark], ignore_mark
|
|||||||
text = text[:mark.start] + mtext + text[mark.end:]
|
text = text[:mark.start] + mtext + text[mark.end:]
|
||||||
|
|
||||||
text = text.replace('\0', '')
|
text = text.replace('\0', '')
|
||||||
|
return re.sub('[\r\n]', '\r\n', text).rstrip()
|
||||||
return text.replace('\n', '\r\n').rstrip()
|
|
||||||
|
|
||||||
|
|
||||||
class Hints(Handler):
|
class Hints(Handler):
|
||||||
@ -342,12 +346,12 @@ def functions_for(args: HintsCLIOptions) -> Tuple[str, List[PostprocessorFunc]]:
|
|||||||
)
|
)
|
||||||
post_processors.append(url)
|
post_processors.append(url)
|
||||||
elif args.type == 'path':
|
elif args.type == 'path':
|
||||||
pattern = r'(?:\S*/\S+)|(?:\S+[.][a-zA-Z0-9]{2,7})'
|
pattern = r'(?:\S*?/[\r\S]+)|(?:\S[\r\S]*\.[a-zA-Z0-9\r]{2,7})'
|
||||||
post_processors.extend((brackets, quotes))
|
post_processors.extend((brackets, quotes))
|
||||||
elif args.type == 'line':
|
elif args.type == 'line':
|
||||||
pattern = '(?m)^\\s*(.+)[\\s\0]*$'
|
pattern = '(?m)^\\s*(.+)[\\s\0]*$'
|
||||||
elif args.type == 'hash':
|
elif args.type == 'hash':
|
||||||
pattern = '[0-9a-f]{7,128}'
|
pattern = '[0-9a-f][0-9a-f\r]{6,127}'
|
||||||
elif args.type == 'ip':
|
elif args.type == 'ip':
|
||||||
pattern = (
|
pattern = (
|
||||||
# # IPv4 with no validation
|
# # IPv4 with no validation
|
||||||
@ -370,16 +374,22 @@ def functions_for(args: HintsCLIOptions) -> Tuple[str, List[PostprocessorFunc]]:
|
|||||||
|
|
||||||
def convert_text(text: str, cols: int) -> str:
|
def convert_text(text: str, cols: int) -> str:
|
||||||
lines: List[str] = []
|
lines: List[str] = []
|
||||||
empty_line = '\0' * cols
|
empty_line = '\0' * cols + '\n'
|
||||||
for full_line in text.split('\n'):
|
for full_line in text.split('\n'):
|
||||||
if full_line:
|
if full_line:
|
||||||
if not full_line.rstrip('\r'): # empty lines
|
if not full_line.rstrip('\r'): # empty lines
|
||||||
lines.extend(repeat(empty_line, len(full_line)))
|
lines.extend(repeat(empty_line, len(full_line)))
|
||||||
continue
|
continue
|
||||||
|
appended = False
|
||||||
for line in full_line.split('\r'):
|
for line in full_line.split('\r'):
|
||||||
if line:
|
if line:
|
||||||
lines.append(line.ljust(cols, '\0'))
|
lines.append(line.ljust(cols, '\0'))
|
||||||
return '\n'.join(lines)
|
lines.append('\r')
|
||||||
|
appended = True
|
||||||
|
if appended:
|
||||||
|
lines[-1] = '\n'
|
||||||
|
rstripped = re.sub('[\r\n]+$', '', ''.join(lines))
|
||||||
|
return rstripped
|
||||||
|
|
||||||
|
|
||||||
def parse_input(text: str) -> str:
|
def parse_input(text: str) -> str:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user