Skip to content

Commit

Permalink
feat: added terminal bell to alert the user they have been returned c…
Browse files Browse the repository at this point in the history
…ontrol
  • Loading branch information
ErikBjare committed Sep 7, 2024
1 parent 740f132 commit 1da7d04
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion gptme/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from .prompts import get_prompt
from .tools import execute_msg, has_tool
from .tools.browser import read_url
from .util import epoch_to_age, generate_name
from .util import epoch_to_age, generate_name, print_bell

logger = logging.getLogger(__name__)
print_builtin = __builtins__["print"] # type: ignore
Expand Down Expand Up @@ -437,6 +437,7 @@ def get_logfile(name: str | Literal["random", "resume"], interactive=True) -> Pa


def prompt_user(value=None) -> str: # pragma: no cover
print_bell()
response = prompt_input(PROMPT_USER, value)
if response:
readline.add_history(response)
Expand Down
8 changes: 8 additions & 0 deletions gptme/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import random
import re
import sys
import textwrap
from datetime import datetime, timedelta

Expand Down Expand Up @@ -133,6 +134,7 @@ def ask_execute(question="Execute code?", default=True) -> bool: # pragma: no c
choicestr = f"({'Y' if default else 'y'}/{'n' if default else 'N'})"
# answer = None
# while not answer or answer.lower() not in ["y", "yes", "n", "no", ""]:
print_bell() # Ring the bell just before asking for input
answer = console.input(
f"[bold yellow on dark_red] {EMOJI_WARN} {question} {choicestr} [/] ",
)
Expand Down Expand Up @@ -194,3 +196,9 @@ def extract_codeblocks(markdown: str) -> list[tuple[str, str]]:
current_block.append(line)

return codeblocks


def print_bell():
"""Ring the terminal bell."""
sys.stdout.write("\a")
sys.stdout.flush()

0 comments on commit 1da7d04

Please sign in to comment.