MCPcopy
hub / github.com/Aider-AI/aider / update

Method update

aider/mdstream.py:149–223  ·  view source on GitHub ↗

Update the displayed markdown content. Args: text (str): The markdown text received so far final (bool): If True, this is the final update and we should clean up Splits the output into "stable" older lines and the "last few" lines which aren't consid

(self, text, final=False)

Source from the content-addressed store, hash-verified

147 pass # Ignore any errors during cleanup
148
149 def update(self, text, final=False):
150 """Update the displayed markdown content.
151
152 Args:
153 text (str): The markdown text received so far
154 final (bool): If True, this is the final update and we should clean up
155
156 Splits the output into "stable" older lines and the "last few" lines
157 which aren't considered stable. They may shift around as new chunks
158 are appended to the markdown text.
159
160 The stable lines emit to the console above the Live window.
161 The unstable lines emit into the Live window so they can be repainted.
162
163 Markdown going to the console works better in terminal scrollback buffers.
164 The live window doesn't play nice with terminal scrollback.
165 """
166 # On the first call, stop the spinner and start the Live renderer
167 if not getattr(self, "_live_started", False):
168 self.live = Live(Text(""), refresh_per_second=1.0 / self.min_delay)
169 self.live.start()
170 self._live_started = True
171
172 now = time.time()
173 # Throttle updates to maintain smooth rendering
174 if not final and now - self.when < self.min_delay:
175 return
176 self.when = now
177
178 # Measure render time and adjust min_delay to maintain smooth rendering
179 start = time.time()
180 lines = self._render_markdown_to_lines(text)
181 render_time = time.time() - start
182
183 # Set min_delay to render time plus a small buffer
184 self.min_delay = min(max(render_time * 10, 1.0 / 20), 2)
185
186 num_lines = len(lines)
187
188 # How many lines have "left" the live window and are now considered stable?
189 # Or if final, consider all lines to be stable.
190 if not final:
191 num_lines -= self.live_window
192
193 # If we have stable content to display...
194 if final or num_lines > 0:
195 # How many stable lines do we need to newly show above the live window?
196 num_printed = len(self.printed)
197 show = num_lines - num_printed
198
199 # Skip if no new lines to show above live window
200 if show <= 0:
201 return
202
203 # Get the new lines and display them
204 show = lines[num_printed:num_lines]
205 show = "".join(show)
206 show = Text.from_ansi(show)

Callers 15

show_diffsFunction · 0.80
run_test_realFunction · 0.80
get_tracked_filesMethod · 0.80
get_dirty_filesMethod · 0.80
tokenizeMethod · 0.80
get_completionsMethod · 0.80
_get_styleMethod · 0.80
generate_pkce_codesFunction · 0.80
eventMethod · 0.80
cmd_addMethod · 0.80
handle_changesMethod · 0.80
send_completionMethod · 0.80

Calls 4

startMethod · 0.45
printMethod · 0.45
stopMethod · 0.45