U
    k&p[                     @   sP   d Z ddlZG dd deZG dd deZG dd deZG d	d
 d
eZdS )a  Simplistic text re-formatter.

This module format text, paragraph by paragraph, so it is somewhat
nice-looking, with no line too long, and short lines joined. In
other words, like what the textwrap library does. However, it
extends textwrap by recognising bulleted lists.

    Nc                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
	Paragraphc                 C   s
   g | _ d S N)_linesself r   ,/usr/lib/python3/dist-packages/cliapp/fmt.py__init__!   s    zParagraph.__init__c                 C   s   | j | d S r   )r   append)r   liner   r   r   r
   $   s    zParagraph.appendc                 C   s   d dd | jD S )N c                 s   s   | ]}d  | V  qdS )r   N)joinsplit.0xr   r   r   	<genexpr>(   s     z&Paragraph._oneliner.<locals>.<genexpr>)r   r   r   r   r   r   	_oneliner'   s    zParagraph._onelinerc                 C   s   t j|  |d}|S )Nwidth)textwrapfillr   )r   r   filledr   r   r   r   *   s    zParagraph.fillN)__name__
__module____qualname__r	   r
   r   r   r   r   r   r   r      s   r   c                   @   s   e Zd Zdd ZdS )BulletPointc                 C   sf   |   }|dsttj|dd  |d d}dd |dD }d|d dd   |d< d	|S )
N*    r   c                 S   s   g | ]}d | qS )z  %sr   r   r   r   r   
<listcomp>5   s     z$BulletPoint.fill.<locals>.<listcomp>Tz* %sr    )r   
startswithAssertionErrorr   r   
splitlinesr   )r   r   textr   linesr   r   r   r   1   s    zBulletPoint.fillNr   r   r   r   r   r   r   r   r   /   s   r   c                   @   s   e Zd Zdd ZdS )	EmptyLinec                 C   s   dS Nr    r   r   r   r   r   r   r   <   s    zEmptyLine.fillNr&   r   r   r   r   r'   :   s   r'   c                   @   s&   e Zd Zd	ddZdd Zdd ZdS )

TextFormatN   c                 C   s
   || _ d S r   )_widthr)   r   r   r   r	   B   s    zTextFormat.__init__c                 C   sJ   g }|  |D ]}||| j qd|}|rF|dsF|d7 }|S )z*Return input string, but formatted nicely.
)_paragraphsr
   r   r,   r   endswith)r   r$   Zfilled_parasZparar   r   r   r   formatE   s    
zTextFormat.formatc                 c   s   dd }dd }dd }d }d}| dD ]}|rR||rR|d k	sFt|| q*||r|rp|V  |spt V  t }|| d}q*||r|r|V  t V  d }d}q*|r|V  t V  d }|st }|| d}q*|r|V  d S )	Nc                 S   s   |   dkS r(   )stripr   r   r   r   is_emptyR   s    z(TextFormat._paragraphs.<locals>.is_emptyc                 S   s
   |  dS )Nr   r!   r2   r   r   r   	is_bulletU   s    z)TextFormat._paragraphs.<locals>.is_bulletc                 S   s
   |  dS )Nr   r4   r2   r   r   r   is_continuationX   s    z/TextFormat._paragraphs.<locals>.is_continuationFT)r#   r"   r
   r'   r   r   )r   r$   r3   r5   r6   ZcurrentZin_listr   r   r   r   r.   P   sB    

zTextFormat._paragraphsN)r+   )r   r   r   r	   r0   r.   r   r   r   r   r*   @   s   
r*   )__doc__r   objectr   r   r'   r*   r   r   r   r   <module>   s
   
