@@ -28,18 +28,31 @@ def flush(self):
28
28
class CodeRenderer (ContentRenderer ):
29
29
def __init__ (self , style ):
30
30
super ().__init__ (style )
31
- SchemaRenderer .print_separator ("┼" )
32
31
self .line_number = 1
33
32
self .code_lang = None
34
33
self .buffer = ""
35
34
self .rendered_content = ""
36
35
self .spinner = SimpleSpinner ("" )
37
36
self .is_spinning = False
38
37
self .terminal_width = os .get_terminal_size ().columns
39
- self .prefix_width = 6 # "123 │ " = 6 characters
40
38
self .safety_padding = 4 # Extra padding to prevent edge cases
41
39
self .json_obj = None
42
40
41
+ # Set prefix width based on INTERPRETER_LINE_NUMBERS
42
+ self .show_line_numbers = (
43
+ os .environ .get ("INTERPRETER_LINE_NUMBERS" , "true" ).lower () == "true"
44
+ )
45
+ self .prefix_width = (
46
+ 6 if self .show_line_numbers else 0
47
+ ) # "123 │ " = 6 characters
48
+
49
+ # Print appropriate separator
50
+ if self .show_line_numbers :
51
+ SchemaRenderer .print_separator ("┼" )
52
+ else :
53
+ SchemaRenderer .print_separator ("┴" )
54
+ print ()
55
+
43
56
def feed (self , json_obj ):
44
57
self .json_obj = json_obj
45
58
@@ -141,25 +154,28 @@ def _render_line(self, line):
141
154
else :
142
155
chunks = [line ]
143
156
144
- # Highlight and print first chunk with line number
145
- line_prefix = f"{ SchemaRenderer .GRAY_COLOR } { str (self .line_number ).rjust (3 )} │ { SchemaRenderer .RESET_COLOR } "
146
- # if self.json_obj and self.json_obj.get("command") == "Open Interpreter":
147
- # line_prefix = f"{SchemaRenderer.GRAY_COLOR} │ {SchemaRenderer.RESET_COLOR}"
148
- highlighted = highlight (chunks [0 ] + "\n " , lexer , formatter ).rstrip ()
157
+ if self .show_line_numbers :
158
+ # Highlight and print first chunk with line number
159
+ line_prefix = f"{ SchemaRenderer .GRAY_COLOR } { str (self .line_number ).rjust (3 )} │ { SchemaRenderer .RESET_COLOR } "
160
+ highlighted = highlight (chunks [0 ] + "\n " , lexer , formatter ).rstrip ()
149
161
150
- if self .line_number == 0 and highlighted .strip () == "" :
151
- return
162
+ if self .line_number == 0 and highlighted .strip () == "" :
163
+ return
152
164
153
- sys .stdout .write (f"{ line_prefix } { highlighted } \n " )
154
- # sys.stdout.write(f"{line_prefix}" + " ".join(highlighted) + "\n") # For debugging
165
+ sys .stdout .write (f"{ line_prefix } { highlighted } \n " )
155
166
156
- # Print remaining chunks with padding and pipe
157
- continuation_prefix = (
158
- f"{ SchemaRenderer .GRAY_COLOR } │ { SchemaRenderer .RESET_COLOR } "
159
- )
160
- for chunk in chunks [1 :]:
161
- highlighted = highlight (chunk + "\n " , lexer , formatter ).rstrip ()
162
- sys .stdout .write (f"{ continuation_prefix } { highlighted } \n " )
167
+ # Print remaining chunks with padding and pipe
168
+ continuation_prefix = (
169
+ f"{ SchemaRenderer .GRAY_COLOR } │ { SchemaRenderer .RESET_COLOR } "
170
+ )
171
+ for chunk in chunks [1 :]:
172
+ highlighted = highlight (chunk + "\n " , lexer , formatter ).rstrip ()
173
+ sys .stdout .write (f"{ continuation_prefix } { highlighted } \n " )
174
+ else :
175
+ # Print chunks without line numbers
176
+ for chunk in chunks :
177
+ highlighted = highlight (chunk + "\n " , lexer , formatter ).rstrip ()
178
+ sys .stdout .write (f"{ highlighted } \n " )
163
179
164
180
sys .stdout .flush ()
165
181
self .line_number += 1
@@ -174,7 +190,11 @@ def flush(self):
174
190
175
191
def close (self ):
176
192
self .flush ()
177
- SchemaRenderer .print_separator ("┴" , newline = False )
193
+ if self .show_line_numbers :
194
+ SchemaRenderer .print_separator ("┴" , newline = False )
195
+ else :
196
+ print ()
197
+ SchemaRenderer .print_separator ("─" , newline = False )
178
198
179
199
180
200
class PathRenderer (ContentRenderer ):
0 commit comments