a
    lc                     @   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-2022 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   U/var/www/html/django/DPS/env/lib/python3.9/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 r`|d	|d  7 }d
| }|d rx||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[%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   sX   t  }| jD ]"\}}|d d ur||d  q|D ]}|d| d | d  q4d S )Nr   z
.defcolor z rgb #
)setr   add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rtdt|| j D ]2}||| j || j | j  }||d | 7 }q@|| j }|dkr||| d d  7 }|| _n6| j| | jkrd| | }|| _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
}|}|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	   r3   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&   r3   rD   rJ   r   r   r   r   r      s   
)	rN   r*   Zpygments.formatterr   Zpygments.utilr   r   __all__r   r   r   r   r   <module>   s
   
