Skip to content

Commit 65ce8f9

Browse files
authored
Merge pull request #1354 from cyai/feat/turn_of_active_highlighting
feat: let people turn of active highlighting
2 parents c2141ac + 134d3aa commit 65ce8f9

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

docs/ROADMAP.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
- [ ] 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..?
1010
- [ ] Placeholder text that gives a compelling example OI request. Probably use `textual`
1111
- [ ] Everything else `textual` offers, like could we make it easier to select text? Copy paste in and out? Code editing interface?
12-
- [ ] Let people turn off the active line highlighting
12+
- [x] Let people turn off the active line highlighting
1313
- [ ] Add a --plain flag which doesn't use rich, just prints stuff in plain text
1414
- [ ] 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.)
1515
- [ ] 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)

interpreter/core/core.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def __init__(
9999
self.multi_line = multi_line
100100
self.contribute_conversation = contribute_conversation
101101
self.plain_text_display = plain_text_display
102+
self.highlight_active_line = True # additional setting to toggle active line highlighting. Defaults to True
102103

103104
# Loop messages
104105
self.loop = loop

interpreter/terminal_interface/components/code_block.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ class CodeBlock(BaseBlock):
1212
Code Blocks display code and outputs in different languages. You can also set the active_line!
1313
"""
1414

15-
def __init__(self):
15+
def __init__(self, interpreter=None):
1616
super().__init__()
1717

1818
self.type = "code"
19+
self.highlight_active_line = (
20+
interpreter.highlight_active_line if interpreter else None
21+
)
1922

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

45-
# Add cursor
46-
if cursor:
48+
# Add cursor only if active line highliting is true
49+
if cursor and (
50+
self.highlight_active_line
51+
if self.highlight_active_line is not None
52+
else True
53+
):
4754
code += "●"
4855

4956
# Add each line of code to the table
5057
code_lines = code.strip().split("\n")
5158
for i, line in enumerate(code_lines, start=1):
52-
if i == self.active_line:
59+
if i == self.active_line and (
60+
self.highlight_active_line
61+
if self.highlight_active_line is not None
62+
else True
63+
):
5364
# This is the active line, print it with a white background
5465
syntax = Syntax(
5566
line, self.language, theme="bw", line_numbers=False, word_wrap=True

interpreter/terminal_interface/start_terminal_interface.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ def start_terminal_interface(interpreter):
5050
"type": bool,
5151
"attribute": {"object": interpreter, "attr_name": "auto_run"},
5252
},
53+
{
54+
"name": "no_highlight_active_line",
55+
"nickname": "nhl",
56+
"help_text": "turn off active line highlighting in code blocks",
57+
"type": bool,
58+
"action": "store_true",
59+
"default": False, # Default to False, meaning highlighting is on by default
60+
},
5361
{
5462
"name": "verbose",
5563
"nickname": "v",
@@ -381,6 +389,9 @@ def print_help(self, *args, **kwargs):
381389
print(f"Open Interpreter {version} {update_name}")
382390
return
383391

392+
if args.no_highlight_active_line:
393+
interpreter.highlight_active_line = False
394+
384395
# if safe_mode and auto_run are enabled, safe_mode disables auto_run
385396
if interpreter.auto_run and (
386397
interpreter.safe_mode == "ask" or interpreter.safe_mode == "auto"

interpreter/terminal_interface/terminal_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def terminal_interface(interpreter, message):
221221
if response.strip().lower() == "y":
222222
# Create a new, identical block where the code will actually be run
223223
# Conveniently, the chunk includes everything we need to do this:
224-
active_block = CodeBlock()
224+
active_block = CodeBlock(interpreter)
225225
active_block.margin_top = False # <- Aesthetic choice
226226
active_block.language = language
227227
active_block.code = code

0 commit comments

Comments
 (0)