From 9620bb2b25d27dc201011fb47062d6c783778cb5 Mon Sep 17 00:00:00 2001 From: Siarhei Siniak Date: Fri, 15 Nov 2024 20:57:06 +0300 Subject: [PATCH] [~] Refactort --- dotfiles/.local/bin/commands | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/dotfiles/.local/bin/commands b/dotfiles/.local/bin/commands index fc11701..36301ef 100755 --- a/dotfiles/.local/bin/commands +++ b/dotfiles/.local/bin/commands @@ -132,8 +132,8 @@ def intercept_output( not (isinstance(last_data, bytes) and len(last_data) == 0): t3 = current_subprocess.stdout.peek() - t4 = current_subprocess.stdout.read(len(t3)) - assert isinstance(t4, int) + t4: bytes = current_subprocess.stdout.read(len(t3)) + assert isinstance(t4, bytes) last_data = t3 output.append(t3) @@ -1551,18 +1551,21 @@ def pass_ssh_osx(argv): password = last_line2.decode('utf-8').rstrip('\r\n') assert not password is None - clipboard_set(password) - get_time = lambda : datetime.datetime.now().timestamp() - start = get_time() - while True: - cur = get_time() - remains = 10 - (cur - start) - if remains <= 1e-8: - break - else: - print('\r%5.2fs remains' % remains, end='') - time.sleep(0.1) + try: + clipboard_set(password) + get_time = lambda : datetime.datetime.now().timestamp() + start = get_time() + while True: + cur = get_time() + remains = 10 - (cur - start) + if remains <= 1e-8: + break + else: + print('\r%5.2fs remains' % remains, end='') + time.sleep(0.1) + except KeyboardInterrupt: + pass clipboard_set('') print('\rcleared cliboard\n', end='')