mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-27 02:31:45 +02:00
Allow controlling how multiple selections are handled in the hints kitten
Fixes #1665
This commit is contained in:
@@ -4,6 +4,15 @@ Changelog
|
|||||||
|kitty| is a feature full, cross-platform, *fast*, GPU based terminal emulator.
|
|kitty| is a feature full, cross-platform, *fast*, GPU based terminal emulator.
|
||||||
To update |kitty|, :doc:`follow the instructions <binary>`.
|
To update |kitty|, :doc:`follow the instructions <binary>`.
|
||||||
|
|
||||||
|
0.14.2 [future]
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
- hints kitten: Add a :option:`kitty +kitten hints --multiple-joiner` option to
|
||||||
|
control how multiple selections are serialized when copying to clipboard
|
||||||
|
or inserting into the terminal. You can have them one separate lines,
|
||||||
|
separated by arbitrary characters, or even serialized as JSON (:iss:`1665`)
|
||||||
|
|
||||||
|
|
||||||
0.14.1 [2019-05-29]
|
0.14.1 [2019-05-29]
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
|
|||||||
@@ -246,7 +246,9 @@ def run_loop(args, text, all_marks, index_map):
|
|||||||
handler = Hints(text, all_marks, index_map, args)
|
handler = Hints(text, all_marks, index_map, args)
|
||||||
loop.loop(handler)
|
loop.loop(handler)
|
||||||
if handler.chosen and loop.return_code == 0:
|
if handler.chosen and loop.return_code == 0:
|
||||||
return {'match': handler.chosen, 'program': args.program}
|
return {'match': handler.chosen, 'program': args.program,
|
||||||
|
'multiple_joiner': args.multiple_joiner,
|
||||||
|
'type': args.type}
|
||||||
raise SystemExit(loop.return_code)
|
raise SystemExit(loop.return_code)
|
||||||
|
|
||||||
|
|
||||||
@@ -374,6 +376,17 @@ Select multiple matches and perform the action on all of them together at the en
|
|||||||
In this mode, press :kbd:`Esc` to finish selecting.
|
In this mode, press :kbd:`Esc` to finish selecting.
|
||||||
|
|
||||||
|
|
||||||
|
--multiple-joiner
|
||||||
|
default=auto
|
||||||
|
String to use to join multiple selections when copying to the clipboard or
|
||||||
|
inserting into the terminal. The special strings: "space", "newline", "empty",
|
||||||
|
"json" and "auto" are interpreted as a space character, a newline an empty
|
||||||
|
joiner, a JSON serialized list and an automatic choice, based on the type of
|
||||||
|
text being selected. In addition, integers are interpreted as zero-based
|
||||||
|
indices into the list of selections. You can use 0 for the first selection and
|
||||||
|
-1 for the last.
|
||||||
|
|
||||||
|
|
||||||
--add-trailing-space
|
--add-trailing-space
|
||||||
default=auto
|
default=auto
|
||||||
choices=auto,always,never
|
choices=auto,always,never
|
||||||
@@ -422,13 +435,34 @@ def main(args):
|
|||||||
def handle_result(args, data, target_window_id, boss):
|
def handle_result(args, data, target_window_id, boss):
|
||||||
program = data['program']
|
program = data['program']
|
||||||
matches = tuple(filter(None, data['match']))
|
matches = tuple(filter(None, data['match']))
|
||||||
|
joiner = data['multiple_joiner']
|
||||||
|
try:
|
||||||
|
is_int = int(joiner)
|
||||||
|
except Exception:
|
||||||
|
is_int = None
|
||||||
|
text_type = data['type']
|
||||||
|
|
||||||
|
def joined_text():
|
||||||
|
if is_int is not None:
|
||||||
|
try:
|
||||||
|
return matches[is_int]
|
||||||
|
except IndexError:
|
||||||
|
return matches[-1]
|
||||||
|
if joiner == 'json':
|
||||||
|
import json
|
||||||
|
return json.dumps(matches, ensure_ascii=False, indent='\t')
|
||||||
|
if joiner == 'auto':
|
||||||
|
q = '\n\r' if text_type in ('line', 'url') else ' '
|
||||||
|
else:
|
||||||
|
q = {'newline': '\n\r', 'space': ' '}.get(joiner, '')
|
||||||
|
return q.join(matches)
|
||||||
|
|
||||||
if program == '-':
|
if program == '-':
|
||||||
w = boss.window_id_map.get(target_window_id)
|
w = boss.window_id_map.get(target_window_id)
|
||||||
if w is not None:
|
if w is not None:
|
||||||
for m in matches:
|
w.paste(joined_text())
|
||||||
w.paste(m)
|
|
||||||
elif program == '@':
|
elif program == '@':
|
||||||
set_clipboard_string(matches[-1])
|
set_clipboard_string(joined_text())
|
||||||
else:
|
else:
|
||||||
cwd = None
|
cwd = None
|
||||||
w = boss.window_id_map.get(target_window_id)
|
w = boss.window_id_map.get(target_window_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user