o
    bCcj	                     @   s~   d dl mZ d dlmZ d dlmZmZm	Z	m
Z
mZ d dlmZ dd ZG dd dZejdkr5ejjZnd	d
 Zdd ZdS )    N)	add_inputadd_n_digits	get_input
round_listBooleanOptionalAction)PDFIUM_INFOc                 C   s<   t | dd t|  | jdtddd | jdtdd	d
 d S )NF)pagesz--max-depth   zFMaximum recursion depth to consider when parsing the table of contents)typedefaulthelpz--color-indicatorTzWhether to add a color indicator to bookmarks that declare a color. The indicator is a Unicode symbol wrapped in an ANSI escape sequence. Default is enabled.)actionr   r   )r   r   add_argumentintr   )parser r   F/home/thesage/.local/lib/python3.10/site-packages/pypdfium2_cli/toc.pyattach   s   
r   c                   @   s(   e Zd Zdd Zdd Zedd ZdS )ColorIndicatorc                 C   s   || _ || _d S N)	indicatorsep)selfr   r   r   r   r   __init__!   s   
zColorIndicator.__init__c                 C   s@   t dd |D \}}}d| d| d| d| j d | j S )Nc                 s   s    | ]	}t |d  V  qdS )   N)round).0cr   r   r   	<genexpr>&   s    z*ColorIndicator.__call__.<locals>.<genexpr>z[38;2;;mz[0m)tupler   r   )r   colorrgbr   r   r   __call__%   s   (zColorIndicator.__call__c                 C   s   dS )N r   )r"   r   r   r   noop)   s   zColorIndicator.noopN)__name__
__module____qualname__r   r&   staticmethodr(   r   r   r   r   r      s
    r   i  c                 C   s   d S r   r   )bmr   r   r   	get_color1   s   r.   c                 C   s
  t | }| jrtddd}ntj}|j| jdD ]j}| }| }|dkr*|dnd}d|j }|d	||f 7 }|	 }|rc|
 }	| \}
}|d
|	d krS|	d ndtj|
t|| jf 7 }n|d7 }t|}|r~|d|| dt|| j  7 }t| qd S )Nu   ⬤ )r   )	max_depthr   +*z    z[%s] %s -> z%s  # %s %s   ?_z | RGB)r   color_indicatorr   r(   get_tocr0   	get_title	get_countlevelget_dest	get_indexget_viewpdfium_iViewmodeToStrgetr   n_digitsr.   print)argspdficolr-   titlecount	count_stroutdestindex	view_modeview_posr"   r   r   r   main5   s2   



"
rO   )pypdfium2._helpers_helperspdfiumpypdfium2.internalinternalr?   pypdfium2_cli._parsersr   r   r   r   r   pypdfium2.versionr   r   r   buildPdfBookmarkr.   rO   r   r   r   r   <module>   s   

