Add strip_colors as lib/strings API (#2164)

* Add strip_colors as lib/strings API

* Update strings.py

---------

Co-authored-by: Disconnect3d <dominik.b.czarnota@gmail.com>
pull/2172/head
Aaron Adams 2 years ago committed by GitHub
parent 5d083d471c
commit 676ff74484
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -18,6 +18,7 @@ import gdb
import pwndbg
import pwndbg.color.message as M
import pwndbg.commands
import pwndbg.lib.strings
from pwndbg.commands import CommandCategory
from pwndbg.commands import context
from pwndbg.gdblib import config
@ -250,7 +251,7 @@ def build_context_prompt_body():
{source}
```
"""
return strip_colors(prompt)
return pwndbg.lib.strings.strip_colors(prompt)
def build_command_prompt_body(command):
@ -260,12 +261,7 @@ def build_command_prompt_body(command):
output = gdb.execute(command, to_string=True)
print(output)
prompt += f"""\n```\n{output}\n```\n\n"""
return strip_colors(prompt)
def strip_colors(text):
## Now remove all ANSI color codes from the prompt
return re.sub(r"\x1b[^m]*m", "", text)
return pwndbg.lib.strings.strip_colors(prompt)
def query_openai_chat(prompt, model="gpt-3.5-turbo", max_tokens=100, temperature=0.0):

@ -0,0 +1,8 @@
from __future__ import annotations
import re
def strip_colors(text):
"""Remove all ANSI color codes from the text"""
return re.sub(r"\x1b[^m]*m", "", text)
Loading…
Cancel
Save