o
    Ñ­jÝ  ã                   @   sB   d Z ddlZddlmZ ddlmZmZ dgZG dd„ deƒZdS )zÕ
    pygments.formatters.groff
    ~~~~~~~~~~~~~~~~~~~~~~~~~

    Formatter for groff output.

    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
é    N)Ú	Formatter)Úget_bool_optÚget_int_optÚGroffFormatterc                   @   sX   e Zd ZdZdZg d¢Zg Zdd„ Zdd„ Zdd	„ Z	d
d„ Z
dd„ Zdd„ Zdd„ ZdS )r   a  
    Format tokens with groff escapes to change their color and font style.

    .. versionadded:: 2.11

    Additional options accepted:

    `style`
        The style to use, can be a string or a Style subclass (default:
        ``'default'``).

    `monospaced`
        If set to true, monospace font will be used (default: ``true``).

    `linenos`
        If set to true, print the line numbers (default: ``false``).

    `wrap`
        Wrap lines to the specified number of characters. Disabled if set to 0
        (default: ``0``).
    Úgroff)r   ÚtroffÚroffc                 K   sZ   t j| fi |¤Ž t|ddƒ| _t|ddƒ| _d| _t|ddƒ| _d| _i | _	|  
¡  d S )NÚ
monospacedTÚlinenosFr   Úwrap)r   Ú__init__r   r	   r
   Ú_linenor   r   Ú_linelenÚstylesÚ_make_styles)ÚselfÚoptions© r   úV/var/www/html/CropPilot/venv/lib/python3.10/site-packages/pygments/formatters/groff.pyr   -   s   zGroffFormatter.__init__c                 C   sÈ   | j rdnd}| j rdnd}| j rdnd}| jD ]I\}}d }}|d r1|d	 |d ¡7 }d
| }|d r=||7 }|| }|d rI||7 }|| }|d rZ|d |d ¡7 }d| }||f| j|< qd S )Nz\f[CR]z\f[R]z\f[CB]z\f[B]z\f[CI]z\f[I]Ú Úcolorz\m[{}]z\m[]ÚboldÚitalicÚbgcolorz\M[{}]z\M[])r	   ÚstyleÚformatr   )r   Úregularr   r   ÚttypeÚndefÚstartÚendr   r   r   r   :   s&   ñzGroffFormatter._make_stylesc                 C   s\   t ƒ }| jD ]\}}|d d ur| |d ¡ qt|ƒD ]}| d| d | d ¡ qd S )Nr   z
.defcolor z rgb #Ú
)Úsetr   ÚaddÚsortedÚwrite)r   ÚoutfileÚcolorsÚ_r   r   r   r   r   Ú_define_colorsQ   s   €ÿzGroffFormatter._define_colorsc                 C   s4   |  j d7  _ | d| j dkrdpd| j f ¡ d S )Né   z%s% 4d r!   r   )r   r%   )r   r&   r   r   r   Ú_write_lineno[   s   &zGroffFormatter._write_linenoc                 C   sâ   t | d¡ƒ}| jrdnd}d}|| jkrStdt || j ¡ƒD ]}||| j || j | j … }||d | 7 }q || j }|dkrQ||| d d … 7 }|| _|S | j| | jkrfd| | }|| _|S |}|  j|7  _|S )Nr!   z     r   r   r*   )ÚlenÚrstripr
   r   ÚrangeÚmathÚfloorr   )r   ÚlineÚlengthÚspaceÚnewlineÚiÚchunkÚ	remainderr   r   r   Ú
_wrap_line`   s&   

ùýzGroffFormatter._wrap_linec                 C   s�   |  dd¡  dd¡  dd¡  dd¡  d	d
¡}|}|D ]+}t|ƒt| ¡ ƒkrE| d¡ ¡ dd …   dd¡ ¡ }|  |d|dd …  d ¡}q|S )Nú\z\[u005C]Ú.z	\[char46]ú'z\[u0027]ú`z\[u0060]ú~z\[u007E]Úunicode_escaper*   ÚxÚu00z\[uú])Úreplacer,   ÚencodeÚdecodeÚupper)r   ÚtextÚcopyÚcharÚunir   r   r   Ú_escape_charsw   s$   
ü
ÿý€zGroffFormatter._escape_charsc           	   	   C   s  |   |¡ | d¡ | jr|  |¡ |D ]j\}}|| jvr%|j}|| jvs| j| \}}| d¡D ]L}| jdkr=|  |¡}|rY|rY|  	| 
d¡¡}|dkrX| d |||f¡¡ n| |  	| 
d¡¡¡ | d¡r}| jru|  |¡ d| _q1| d¡ d| _q1q| d¡ d S )Nz.nf
\f[CR]
Tr   r!   r   z
.fi)r)   r%   r
   r+   r   ÚparentÚ
splitlinesr   r8   rJ   r-   ÚjoinÚendswithr   )	r   Útokensourcer&   r   Úvaluer   r    r1   rF   r   r   r   Úformat_unencodedŠ   s6   




ÿ

€


€ïzGroffFormatter.format_unencodedN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚnameÚaliasesÚ	filenamesr   r   r)   r+   r8   rJ   rQ   r   r   r   r   r      s    
)	rU   r/   Úpygments.formatterr   Úpygments.utilr   r   Ú__all__r   r   r   r   r   Ú<module>   s    
