akseljoonas HF Staff commited on
Commit
e76b3d1
·
1 Parent(s): 4501765

Enhance terminal display with new markdown emphasis styles

Browse files

Add support for various markdown emphasis styles in the terminal display, including strong, emphasis, code, code block, and headers. Update the Console configuration to ensure ANSI styles are preserved during rendering.

Files changed (1) hide show
  1. agent/utils/terminal_display.py +19 -1
agent/utils/terminal_display.py CHANGED
@@ -14,6 +14,15 @@ _THEME = Theme({
14
  "tool.fail": "dim red",
15
  "info": "dim",
16
  "muted": "dim",
 
 
 
 
 
 
 
 
 
17
  })
18
 
19
  _console = Console(theme=_THEME, highlight=False)
@@ -234,7 +243,16 @@ def print_markdown(text: str) -> None:
234
 
235
  # Render markdown to a string buffer so we can type it out
236
  buf = io.StringIO()
237
- buf_console = Console(file=buf, width=_console.width, highlight=False, theme=_THEME)
 
 
 
 
 
 
 
 
 
238
  buf_console.print(Padding(Markdown(text), (0, 0, 0, 2)))
239
  rendered = buf.getvalue()
240
 
 
14
  "tool.fail": "dim red",
15
  "info": "dim",
16
  "muted": "dim",
17
+ # Markdown emphasis colors
18
+ "markdown.strong": "bold rgb(255,200,80)",
19
+ "markdown.emphasis": "italic rgb(180,140,40)",
20
+ "markdown.code": "rgb(120,220,255)",
21
+ "markdown.code_block": "rgb(120,220,255)",
22
+ "markdown.link": "underline rgb(90,180,255)",
23
+ "markdown.h1": "bold rgb(255,200,80)",
24
+ "markdown.h2": "bold rgb(240,180,95)",
25
+ "markdown.h3": "bold rgb(220,165,100)",
26
  })
27
 
28
  _console = Console(theme=_THEME, highlight=False)
 
243
 
244
  # Render markdown to a string buffer so we can type it out
245
  buf = io.StringIO()
246
+ # Important: StringIO is not a TTY, so Rich would normally strip styles.
247
+ # Force terminal rendering so ANSI style codes are preserved for typewriter output.
248
+ buf_console = Console(
249
+ file=buf,
250
+ width=_console.width,
251
+ highlight=False,
252
+ theme=_THEME,
253
+ force_terminal=True,
254
+ color_system=_console.color_system or "truecolor",
255
+ )
256
  buf_console.print(Padding(Markdown(text), (0, 0, 0, 2)))
257
  rendered = buf.getvalue()
258