a
    ñ»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   ZtroffZ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   ú?E:\soccer\ml_env\Lib\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 ]’\}}d }}|d rb|d	 |d ¡7 }d
| }|d rz||7 }|| }|d r’||7 }|| }|d r´|d |d ¡7 }d| }||f| j|< q0d 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   Z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 ¡ q8d 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r¢tdt || j ¡ƒD ]2}||| j || j | j … }||d | 7 }q@|| j }|dkrØ|||| d … 7 }|| _n6| j| | jkrÆd| | }|| _n|}|  j|7  _|S )Nr   z     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 ]V}t|ƒt| ¡ ƒkr4| d¡ ¡ dd …   dd¡ ¡ }|  |d|dd …  d ¡}q4|S )Nú\z\[u005C]Ú.z	\[char46]ú'z\[u0027]ú`z\[u0060]ú~z\[u007E]Úunicode_escaper'   ÚxZ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vrB|j}q0| j| \}}| d¡D ]˜}| jdkrr|  |¡}|rª|rª|  	| 
d¡¡}|dkrÀ| d |||f¡¡ n| |  	| 
d¡¡¡ | d¡rZ| jrâ|  |¡ d| _qZ| d¡ d| _qZq(| d¡ d S )Nz.nf
\f[CR]
Tr   r   r   z
.fi)r&   r"   r   r(   r   ÚparentÚ
splitlinesr	   r5   rF   r*   ÚjoinÚendswithr   )	r   Ztokensourcer#   r   Úvaluer   r   r.   rB   r   r   r   Úformat_unencodedŠ   s.    









zGroffFormatter.format_unencodedN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚnameÚaliasesÚ	filenamesr
   r   r&   r(   r5   rF   rL   r   r   r   r   r      s   
)	rP   r,   Zpygments.formatterr   Zpygments.utilr   r   Ú__all__r   r   r   r   r   Ú<module>   s
   
