
    	D,j                     r   d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	m
Z
mZ d dlmZ d dlmZ d dlmZ d d	lmZ d
ZdZ G d de	          Z G d de
          Z G d de          Z G d d          Zedk    r edd          5 Ze                                Zddd           n# 1 swxY w Y   eez   ez   Zedz  Z e            Z  e!d            e"d e#e          d          D ]/Z$e %                    ede$                     ej&        d           0e %                    ed           dS dS )    N)box)Console)Live)	CodeBlockHeadingMarkdown)Panel)Syntax)Text)dumpa  
# Header

Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuries, but also the leap into
electronic typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
and more recently with desktop publishing software like Aldus PageMaker
including versions of Lorem Ipsum.



## Sub header

- List 1
- List 2
- List me
- List you



```python
z#
```

## Sub header too

The end.

c                       e Zd ZdZd ZdS )NoInsetCodeBlockz5A code block with syntax highlighting and no padding.c              #      K   t          | j                                                  }t          || j        | j        dd          }|V  d S )NT)   r   )theme	word_wrappadding)strtextrstripr
   
lexer_namer   )selfconsoleoptionscodesyntaxs        ]/home/rurouni/.local/share/uv/tools/aider-chat/lib/python3.11/site-packages/aider/mdstream.py__rich_console__z!NoInsetCodeBlock.__rich_console__7   sI      49~~$$&&doTZ4Y_```    N__name__
__module____qualname____doc__r    r   r   r   r   4   s)        ??    r   r   c                       e Zd ZdZd ZdS )LeftHeadingz,A heading class that renders left-justified.c              #      K   | j         }d|_        | j        dk    r t          |t          j        d          V  d S | j        dk    rt          d          V  |V  d S )Nlefth1zmarkdown.h1.border)r   styleh2 )r   justifytagr	   r   HEAVYr   )r   r   r   r   s       r   r   zLeftHeading.__rich_console__@   s      y8tI*        x42hhJJJJJr   Nr    r%   r   r   r'   r'   =   s)        66    r   r'   c                   0    e Zd ZdZi ej        eeedZdS )NoInsetMarkdownzKMarkdown with code blocks that have no padding and left-justified headings.)fence
code_blockheading_openN)r!   r"   r#   r$   r   elementsr   r'   r%   r   r   r2   r2   Q   s>        UU

!&#	  HHHr   r2   c                   F    e Zd ZdZdZdZdZdZddZd Z	d Z
dd
ZddZdS )MarkdownStreama(  Streaming markdown renderer that progressively displays content with a live updating window.

    Uses rich.console and rich.live to render markdown content with smooth scrolling
    and partial updates. Maintains a sliding window of visible content while streaming
    in new markdown text.
    Nr   皙?   c                 j    g | _         |r|| _        nt                      | _        d| _        d| _        dS )zInitialize the markdown stream.

        Args:
            mdargs (dict, optional): Additional arguments to pass to rich Markdown renderer
        NF)printedmdargsdictlive_live_started)r   r=   s     r   __init__zMarkdownStream.__init__i   s>      	! DKK&&DK 	"r   c                     t          j                    }t          |d          }t          |fi | j        }|                    |           |                                }|                    d          S )zRender markdown text to a list of lines.

        Args:
            text (str): Markdown text to render

        Returns:
            list: List of rendered lines with line endings preserved
        T)fileforce_terminal)keepends)ioStringIOr   r2   r=   printgetvalue
splitlines)r   r   	string_ior   markdownoutputs         r   _render_markdown_to_linesz(MarkdownStream._render_markdown_to_linesz   st     KMM	y>>>"4774;77h##%%   $ ///r   c                 n    | j         r-	 | j                                          dS # t          $ r Y dS w xY wdS )z9Destructor to ensure Live display is properly cleaned up.N)r?   stop	Exception)r   s    r   __del__zMarkdownStream.__del__   sU    9 		        	 	s   $ 
22Fc                 b   t          | dd          sKt          t          d          d| j        z            | _        | j                                         d| _        t          j                    }|s|| j        z
  | j        k     rdS || _        t          j                    }| 	                    |          }t          j                    |z
  }t          t          |dz  d	          d
          | _        t          |          }|s
|| j        z  }|s|dk    rt          | j                  }||z
  }	|	dk    rdS |||         }	d                    |	          }	t          j        |	          }	| j        j                            |	           |d|         | _        |rI| j                            t          d                     | j                                         d| _        dS ||d         }
d                    |
          }
t          j        |
          }
| j                            |
           dS )a  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 considered stable. They may shift around as new chunks
        are appended to the markdown text.

        The stable lines emit to the console above the Live window.
        The unstable lines emit into the Live window so they can be repainted.

        Markdown going to the console works better in terminal scrollback buffers.
        The live window doesn't play nice with terminal scrollback.
        r@   Fr-   g      ?)refresh_per_secondTN
   r9      r   )getattrr   r   	min_delayr?   startr@   timewhenrN   minmaxlenlive_windowr<   join	from_ansir   rH   updaterP   )r   r   finalnowrY   linesrender_time	num_linesnum_printedshowrests              r   rb   zMarkdownStream.update   s   $ t_e44 	&T"XX#:NOOODIIOO!%Dikk 	ty4>99F	 	..t44ikkE) Sr!18<<a@@JJ	  	*))I  	-IMMdl++K{*D qyy Y./D774==D>$''DI##D))) !),DL  	IT"XX&&&INNDIF YZZ wwt}}~d##	r   2   c                     dS )z>
        Splits text into chunks on blank lines "

".
        Nr%   )r   r   match_liness      r   find_minimal_suffixz"MarkdownStream.find_minimal_suffix   s      r   )N)F)rk   )r!   r"   r#   r$   r?   r[   rX   r_   rA   rN   rR   rb   rn   r%   r   r   r8   r8   \   s          DDIK# # # #"0 0 0&  J J J JX     r   r8   __main__zaider/io.pyrrU   z4Using NoInsetMarkdown for code blocks with padding=0r:      g{Gz?T)rc   )'rF   rZ   richr   rich.consoler   	rich.liver   rich.markdownr   r   r   
rich.panelr	   rich.syntaxr
   	rich.textr   
aider.dumpr   _text_prefix_text_suffixr   r'   r2   r8   r!   openfreadr   _textpmrH   ranger^   irb   sleepr%   r   r   <module>r      s   
			                          6 6 6 6 6 6 6 6 6 6                        4    y       '   (    h   H H H H H H H HV z	mS	!	! Qvvxx              4,.EBJE			B	E
@AAAU1cc%jj!$$  
		%)
4IIe4I      s   
B++B/2B/