From 2b91c72850273bb991729c44aae83303b8478949 Mon Sep 17 00:00:00 2001 From: Caleb Voorhees Date: Wed, 13 Mar 2024 11:26:47 -0400 Subject: [PATCH] Add feature to copy answer text to clipboard (#297) - Add x as a menu option which uses `pyperclip` library to copy the stack overflow answer currently being displayed to the users clipboard. --- socli/tui.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/socli/tui.py b/socli/tui.py index 04206fc..d3df7a9 100644 --- a/socli/tui.py +++ b/socli/tui.py @@ -111,7 +111,7 @@ def make_frame(self): footer=urwid.Pile([ QuestionURL(self.url), UnicodeText( - u'\u2191: previous answer, \u2193: next answer, c:comments, o: open in browser, \u2190: back, ' + u'\u2191: previous answer, \u2193: next answer, x: copy answer, c:comments, o: open in browser, \u2190: back, ' u'd: visit duplicated question, q: quit') ]) ) @@ -128,7 +128,7 @@ def make_frame(self): footer=urwid.Pile([ QuestionURL(self.url), UnicodeText( - u'\u2191: previous answer, \u2193: next answer, c:comments, o: open in browser, \u2190: back, ' + u'\u2191: previous answer, \u2193: next answer, x: copy answer, c:comments, o: open in browser, \u2190: back, ' u'd: back to original question, q: quit') ]) ) @@ -145,7 +145,7 @@ def make_frame(self): footer=urwid.Pile([ QuestionURL(self.url), UnicodeText( - u'\u2191: previous answer, \u2193: next answer, c: comments, o: open in browser, ' + u'\u2191: previous answer, \u2193: next answer, x: copy answer, c: comments, o: open in browser, ' u'\u2190: back, q: quit') ]) ) @@ -203,6 +203,10 @@ def keypress(self, size, key): import webbrowser display_header.event('browser', "Opening in your browser...") webbrowser.open(self.url) + elif key in {'x', 'X'}: + import pyperclip + current_answer = self.answer_text.index + pyperclip.copy(self.answer_text.answers[current_answer]) elif key == 'left': global question_post global question_page