Skip to content

Commit

Permalink
morefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed May 3, 2024
1 parent 34740b2 commit 339eeea
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
50 changes: 33 additions & 17 deletions r2ai/bubble.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Bubble chat helper functions to make clippy-ai look nice."""

import os

clippy_begin="""
CLIPPY_BEGIN = """
.--.
_|_ |
O O |
Expand All @@ -10,29 +12,43 @@
/ | `---'
.---------------------------------------------------------------' '----"""

clippy_end="""`-----------------------------------------------------------------------"""
CLIPPY_END = """`-----------------------------------------------------------------------"""

user_begin=""" |\\
USER_BEGIN = """ |\\
| \\
.--' '--"""

user_end='`---'
USER_END = '`---'

def query(text):
l = len(text) + 10
print("\033[F\033[J")
print(user_begin + ("-"*(l-5)) + ".")
pad = " " * (l - len(text))
print(f"| {text} {pad} |")
print(user_end+ ("-"*l) + "'")
"""Display the user text using an ascii-art bubble chat
Parameters:
text (string): Message to display
"""
l = len(text) + 10
print("\033[F\033[J")
print(USER_BEGIN + ("-" * (l - 5)) + ".")
pad = " " * (l - len(text))
print(f"| {text} {pad} |")
print(USER_END + ("-"*l) + "'")

def getpad():
tw = os.get_terminal_size().columns - 75
pad = "-"
if tw > 0:
pad = "-" * tw
return pad
"""Generate padding with dashes
"""
tw = os.get_terminal_size().columns - 75
pad = "-"
if tw > 0:
pad = "-" * tw
return pad

def response_begin():
print(clippy_begin + getpad() + ".")
"""Print the beginning of the clippy response
"""
print(CLIPPY_BEGIN + getpad() + ".")

def response_end():
print(clippy_end + getpad() + "'")
"""Print the end of the clippy response
"""
print(CLIPPY_END + getpad() + "'")
11 changes: 7 additions & 4 deletions r2ai/tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def display_matches(self, substitution, matches, longest_match_length):

def tab_hist(text):
if not have_readline:
print("Cannot find readline")
print("Cannot find readline", file=sys.stderr)
return False

def tab_evals(x):
Expand All @@ -107,16 +107,19 @@ def tab_evals(x):

def tab_write():
if not have_readline:
print("Cannot find readline")
print("Cannot find readline", file=sys.stderr)
return False
readline.write_history_file(R2AI_HISTFILE)

def tab_init():
if not have_readline:
print("Cannot find readline")
print("Cannot find readline", file=sys.stderr)
return False
completer = MyCompleter(list(set(commands)))
readline.read_history_file(R2AI_HISTFILE)
try:
readline.read_history_file(R2AI_HISTFILE)
except FileNotFoundError:
pass
readline.set_completer(completer.complete)
readline.set_completer_delims('\t\n;')
readline.set_completion_display_matches_hook(completer.display_matches)
Expand Down

0 comments on commit 339eeea

Please sign in to comment.