From 4ec66f63520ca01e898a685285133684c5d8b28f Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Thu, 25 May 2023 11:07:22 -0400 Subject: [PATCH] Improved detection of and errors relating to clipboard support in raw ttys Former-commit-id: 7b13af57872ff2bd2bf8285608b5d9a206c84fe8 Former-commit-id: 4406cd49234ff58cf568a55d07757f373830fe91 --- lib/sshyp.py | 7 +++++-- lib/stweak.py | 5 +++-- port-jobs/CLIPTOOL.py | 5 +++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/sshyp.py b/lib/sshyp.py index 000923b..7877118 100755 --- a/lib/sshyp.py +++ b/lib/sshyp.py @@ -669,10 +669,13 @@ def copy_data(): run(('termux-clipboard-set', _copy_line[_index])) Popen("sleep 30; termux-clipboard-set ''", shell=True) # X11 clipboard detection - else: + elif 'DISPLAY' in environ: run(('xclip', '-sel', 'c'), stdin=Popen(('printf', _copy_line[_index].replace('\\', '\\\\') .replace('%', '%%')), stdout=PIPE).stdout) Popen("sleep 30; printf '' | xclip -sel c", shell=True) + else: + print('\n\u001b[38;5;9merror: clipboard tool could not be determined\n\nnote that the clipboard does not ' + 'function in a raw tty\u001b[0m\n') # PORT END CLIPBOARD rmtree(f"{tmp_dir}{_shm_folder}") @@ -779,7 +782,7 @@ if __name__ == "__main__": success_flag = 1 copy_data() except IndexError: - print(f"\n\u001b[38;5;9merror: field does not exist in entry\u001b[0m\n") + print('\n\u001b[38;5;9merror: field does not exist in entry\u001b[0m\n') s_exit(2) elif arguments[1] == 'add': if arguments[2] in ('note', '-n', 'password', '-p'): diff --git a/lib/stweak.py b/lib/stweak.py index de69753..b5c0a6d 100644 --- a/lib/stweak.py +++ b/lib/stweak.py @@ -345,11 +345,12 @@ def initial_setup(): # PORT START CLIPTOOL # check for clipboard tool and display warning if missing if uname()[0] in ('Linux', 'FreeBSD'): + _display_server = None if 'WAYLAND_DISPLAY' in environ: _display_server, _clipboard_tool, _clipboard_package = 'Wayland', 'wl-copy', 'wl-clipboard' - else: + elif 'DISPLAY' in environ: _display_server, _clipboard_tool, _clipboard_package = 'X11', 'xclip', 'xclip' - if which(_clipboard_tool) is None: + if _display_server is not None and which(_clipboard_tool) is None: print(f'\n\u001b[38;5;9mwarning: you are using {_display_server} and "{_clipboard_tool}" is not ' f'present - \ncopying entry fields will not function until ' f'"{_clipboard_package}" is installed\u001b[0m') diff --git a/port-jobs/CLIPTOOL.py b/port-jobs/CLIPTOOL.py index 1fea306..303156d 100755 --- a/port-jobs/CLIPTOOL.py +++ b/port-jobs/CLIPTOOL.py @@ -13,11 +13,12 @@ string2 = '# PORT END CLIPTOOL' if len(arguments) > 0: regex = re.compile(f"{string1}.*?{string2}", re.DOTALL) replacement = """# check for clipboard tool and display warning if missing + _display_server = None if 'WAYLAND_DISPLAY' in environ: _display_server, _clipboard_tool, _clipboard_package = 'Wayland', 'wl-copy', 'wl-clipboard' - else: + elif 'DISPLAY' in environ: _display_server, _clipboard_tool, _clipboard_package = 'X11', 'xclip', 'xclip' - if which(_clipboard_tool) is None: + if _display_server is not None and which(_clipboard_tool) is None: print(f'''\n\u001b[38;5;9mwarning: you are using {_display_server} and "{_clipboard_tool}" is not present - copying entry fields will not function until "{_clipboard_package}" is installed\u001b[0m ''')"""