Skip to content

Commit

Permalink
Add feature to copy answer text to clipboard (#297)
Browse files Browse the repository at this point in the history
- Add x as a menu option which uses `pyperclip` library to copy the stack overflow answer currently being displayed to the users clipboard.
  • Loading branch information
cvoorhees15 authored Mar 13, 2024
1 parent a611f8f commit 2b91c72
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions socli/tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
])
)
Expand All @@ -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')
])
)
Expand All @@ -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')
])
)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2b91c72

Please sign in to comment.