2929
3030from . import commands , console , input
3131from .content import (
32+ ContentFragment ,
3233 ContentLine ,
33- PromptContent ,
3434 SourceLine ,
3535 build_body_fragments ,
3636 process_prompt as build_prompt_content ,
3737)
3838from .layout import LayoutMap , LayoutResult , LayoutRow , WrappedRow , layout_content_lines
39- from .render import RenderCell , RenderLine , RenderedScreen
40- from .utils import wlen , gen_colors , THEME
39+ from .render import RenderCell , RenderLine , RenderedScreen , StyleRef
40+ from .utils import ANSI_ESCAPE_SEQUENCE , wlen , gen_colors
4141from .trace import trace
4242
4343
@@ -431,8 +431,7 @@ def _render_wrapped_rows(
431431 return [
432432 self ._render_line (
433433 row .prompt_text ,
434- [fragment .text for fragment in row .fragments ],
435- [fragment .width for fragment in row .fragments ],
434+ list (row .fragments ),
436435 row .suffix ,
437436 )
438437 for row in wrapped_rows
@@ -455,22 +454,33 @@ def _render_message_lines(self) -> list[RenderLine]:
455454 )
456455 return render_lines
457456
458- @staticmethod
459457 def _render_line (
458+ self ,
460459 prefix : str ,
461- chars : list [str ],
462- char_widths : list [int ],
460+ fragments : list [ContentFragment ],
463461 suffix : str = "" ,
464462 ) -> RenderLine :
465463 cells : list [RenderCell ] = []
466464 if prefix :
467- cells .extend (RenderLine .from_rendered_text (prefix ).cells )
465+ prompt_cells = list (RenderLine .from_rendered_text (prefix ).cells )
466+ if self .can_colorize and prompt_cells and not ANSI_ESCAPE_SEQUENCE .search (prefix ):
467+ prompt_style = StyleRef .from_tag ("prompt" )
468+ prompt_cells = [
469+ RenderCell (
470+ cell .text ,
471+ cell .width ,
472+ style = prompt_style if cell .text else cell .style ,
473+ controls = cell .controls ,
474+ )
475+ for cell in prompt_cells
476+ ]
477+ cells .extend (prompt_cells )
468478 cells .extend (
469- RenderCell . from_rendered_text ( text , width )
470- for text , width in zip ( chars , char_widths )
479+ RenderCell ( fragment . text , fragment . width , style = fragment . style )
480+ for fragment in fragments
471481 )
472482 if suffix :
473- cells .append ( RenderCell .from_rendered_text (suffix , wlen ( suffix )) )
483+ cells .extend ( RenderLine .from_rendered_text (suffix ). cells )
474484 return RenderLine .from_cells (cells )
475485
476486 @staticmethod
@@ -573,10 +583,6 @@ def get_prompt(self, lineno: int, cursor_on_line: bool) -> str:
573583 prompt = self .ps3
574584 else :
575585 prompt = self .ps1
576-
577- if self .can_colorize :
578- t = THEME ()
579- prompt = f"{ t .prompt } { prompt } { t .reset } "
580586 return prompt
581587
582588 def push_input_trans (self , itrans : input .KeymapTranslator ) -> None :
0 commit comments