B
    Ù&eæ  ã               @   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-2023 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
é    N)Ú	Formatter)Úget_bool_optÚget_int_optÚGroffFormatterc               @   sZ   e Zd ZdZdZdddg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``).
    ÚgroffZtroffZroffc             K   sV   t j| f|Ž 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   úT/home/dcms/DCMS/lib/python3.7/site-packages/pip/_vendor/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}x˜| jD ]Ž\}}d }}|d rb|d	|d  7 }d
| }|d rz||7 }|| }|d r’||7 }|| }|d r²|d|d  7 }d| }||f| j|< q2W d S )Nz\f[CR]z\f[R]z\f[CB]z\f[B]z\f[CI]z\f[I]Ú Úcolorz\m[%s]z\m[]ÚboldÚitalicÚbgcolorz\M[%s]z\M[])r   Ústyler   )r   Zregularr   r   ÚttypeÚndefÚstartÚendr   r   r   r   :   s$    zGroffFormatter._make_stylesc             C   sd   t ƒ }x,| jD ]"\}}|d d k	r| |d ¡ qW x*t|ƒD ]}| d| d | d ¡ q>W 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r¨xLtdt || j ¡ƒD ]2}||| j || j | j … }||d | 7 }qBW || j }|dkrÞ||| d d … 7 }|| _n6| j| | jkrÌd| | }|| _n|}|  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
¡}|}x^|D ]V}t|ƒt| ¡ ƒkr6| d¡ ¡ dd …   dd¡ ¡ }|  |d|dd …  d ¡}q6W |S )Nú\z\[u005C]Ú.z	\[char46]ú'z\[u0027]ú`z\[u0060]ú~z\[u007E]Z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$|  |¡ xÜ|D ]Ô\}}x|| jkrF|j}q4W | j| \}}x¦| d¡D ]˜}| jdkrz|  |¡}|r²|r²|  	| 
d¡¡}|dkrÈ| d |||f¡¡ n| |  	| 
d¡¡¡ | d¡rb| jrê|  |¡ d| _qb| d¡ d| _qbW q*W | d¡ d S )Nz.nf
\f[CR]
Tr   r   r   z
.fi)r%   r!   r   r'   r   ÚparentÚ
splitlinesr	   r4   rD   r)   ÚjoinÚendswithr   )	r   Ztokensourcer"   r   Úvaluer   r   r-   r@   r   r   r   Úformat_unencodedŠ   s.    








zGroffFormatter.format_unencodedN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚnameÚaliasesÚ	filenamesr
   r   r%   r'   r4   rD   rJ   r   r   r   r   r      s   

)	rN   r+   Zpip._vendor.pygments.formatterr   Úpip._vendor.pygments.utilr   r   Ú__all__r   r   r   r   r   Ú<module>	   s
   