Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: let people turn of active highlighting #1354

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- [ ] Figure out how to get OI to answer to user input requests like python's `input()`. Do we somehow detect a delay in the output..? Is there some universal flag that TUIs emit when they expect user input? Should we do this semantically with embeddings, then ask OI to review it and respond..?
- [ ] Placeholder text that gives a compelling example OI request. Probably use `textual`
- [ ] Everything else `textual` offers, like could we make it easier to select text? Copy paste in and out? Code editing interface?
- [ ] Let people turn off the active line highlighting
- [x] Let people turn off the active line highlighting
- [ ] Add a --plain flag which doesn't use rich, just prints stuff in plain text
- [ ] Use iPython stuff to track the active line, instead of inserting print statements, which makes debugging weird (From ChatGPT: For deeper insights into what's happening behind the scenes, including which line of code is being executed, you can increase the logging level of the IPython kernel. You can configure the kernel's logger to a more verbose setting, which logs each execution request. However, this requires modifying the kernel's startup settings, which might involve changing logging configurations in the IPython kernel source or when launching the kernel.)
- [ ] Let people edit the code OI writes. Could just open it in the user's preferred editor. Simple. [Full description of how to implement this here.](https://github.com/KillianLucas/open-interpreter/pull/830#issuecomment-1854989795)
Expand Down
1 change: 1 addition & 0 deletions interpreter/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def __init__(
self.multi_line = multi_line
self.contribute_conversation = contribute_conversation
self.plain_text_display = plain_text_display
self.highlight_active_line = True # additional setting to toggle active line highlighting. Defaults to True

# Loop messages
self.loop = loop
Expand Down
19 changes: 15 additions & 4 deletions interpreter/terminal_interface/components/code_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ class CodeBlock(BaseBlock):
Code Blocks display code and outputs in different languages. You can also set the active_line!
"""

def __init__(self):
def __init__(self, interpreter=None):
super().__init__()

self.type = "code"
self.highlight_active_line = (
interpreter.highlight_active_line if interpreter else None
)

# Define these for IDE auto-completion
self.language = ""
Expand All @@ -42,14 +45,22 @@ def refresh(self, cursor=True):
)
code_table.add_column()

# Add cursor
if cursor:
# Add cursor only if active line highliting is true
if cursor and (
self.highlight_active_line
if self.highlight_active_line is not None
else True
):
code += "●"

# Add each line of code to the table
code_lines = code.strip().split("\n")
for i, line in enumerate(code_lines, start=1):
if i == self.active_line:
if i == self.active_line and (
self.highlight_active_line
if self.highlight_active_line is not None
else True
):
# This is the active line, print it with a white background
syntax = Syntax(
line, self.language, theme="bw", line_numbers=False, word_wrap=True
Expand Down
11 changes: 11 additions & 0 deletions interpreter/terminal_interface/start_terminal_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ def start_terminal_interface(interpreter):
"type": bool,
"attribute": {"object": interpreter, "attr_name": "auto_run"},
},
{
"name": "no_highlight_active_line",
"nickname": "nhl",
"help_text": "turn off active line highlighting in code blocks",
"type": bool,
"action": "store_true",
"default": False, # Default to False, meaning highlighting is on by default
},
{
"name": "verbose",
"nickname": "v",
Expand Down Expand Up @@ -381,6 +389,9 @@ def print_help(self, *args, **kwargs):
print(f"Open Interpreter {version} {update_name}")
return

if args.no_highlight_active_line:
interpreter.highlight_active_line = False

# if safe_mode and auto_run are enabled, safe_mode disables auto_run
if interpreter.auto_run and (
interpreter.safe_mode == "ask" or interpreter.safe_mode == "auto"
Expand Down
2 changes: 1 addition & 1 deletion interpreter/terminal_interface/terminal_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def terminal_interface(interpreter, message):
if response.strip().lower() == "y":
# Create a new, identical block where the code will actually be run
# Conveniently, the chunk includes everything we need to do this:
active_block = CodeBlock()
active_block = CodeBlock(interpreter)
active_block.margin_top = False # <- Aesthetic choice
active_block.language = language
active_block.code = code
Expand Down
Loading