Skip to content

Commit

Permalink
refactor: revert to "[c] to copy"
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbrayo committed Nov 1, 2024
1 parent 1a55e10 commit e71aaa8
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions gptme/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import random
import re
import sys
import tty
import termios
import textwrap
from datetime import datetime, timedelta
Expand Down Expand Up @@ -169,17 +168,15 @@ def ask_execute(question="Execute code?", default=True) -> bool: # pragma: no c
termios.tcflush(sys.stdin, termios.TCIFLUSH) # flush stdin

choicestr = f"[{'Y' if default else 'y'}/{'n' if default else 'N'}]"
copystr = "[Ctrl+c] to copy"
console.print(
f"[bold bright_yellow on red] {question} {choicestr} {copystr if copiable else ''} [/] ",
end="",
copystr = r"\[c] to copy" if copiable else ""
answer = console.input(
f"[bold bright_yellow on red] {question} {choicestr}{copystr} [/] ",
)
print()
answer = listen_for_character()
if copiable and answer == "\x03":
if copiable and "c" in answer.lower():
if copy():
print("Copied to clipboard.")
return False
if len(answer) > 1:
answer = answer.lower().strip("c")

global override_auto
if answer.lower() in [
Expand Down Expand Up @@ -339,20 +336,3 @@ def path_with_tilde(path: Path) -> str:
if path_str.startswith(home):
return path_str.replace(home, "~", 1)
return path_str


def listen_for_character():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
if ch in ("\n", "\r"):
# handle enter key
ch = ""
except KeyboardInterrupt:
ch = "\x03" # ASCII code for Ctrl+C
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
clear_copiable()
return ch

0 comments on commit e71aaa8

Please sign in to comment.