o
    i+                     @   s^  d Z ddlZddlZddlZddlmZmZmZmZm	Z	m
Z
mZmZmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ er\ddlmZ ddlmZ g dZ G dd de
Z!eee"e#f eee"e$e	e f  f Z%ee	e e	d e	ee"ef  f Z&eedge&f e&f Z'eeege$f df Z(ee	ee"ef  ee"ef f Z)ee"edge"f f Z*eeedgef f Z+ee"e	ee"ee"de	e" f f  f Z,	d%deee"e"f  de$de!fddZ-	d&deee#e"f  deee#e"f  de#deee# e#f fddZ.d'd d!Z/	d(d"e	ee"e"f  deee"e"f  ddfd#d$Z0dS ))z<Module contains shared utility functions and typing aliases.    N)	TYPE_CHECKINGAnyCallableDictList
NamedTupleOptionalTupleUnion)print_formatted_textrun_in_terminal)get_app)FormattedText)Style)	Validator)InvalidArgument)FilterOrBool)Choice)	get_stylecalculate_heightInquirerPyStylepatched_printcolor_printc                   @   s"   e Zd ZU dZeeef ed< dS )r   a  `InquirerPy` Style class.

    Used as a helper class to enforce the method `get_style` to be used
    while also avoiding :class:`dict` to be passed into prompts.

    Note:
        The class is an instance of :class:`typing.NamedTuple`.

    Warning:
        You should not directly be using this class besides for type hinting
        purposes. Obtain an instance of this class using :func:`.get_style`.
    dictN)__name__
__module____qualname____doc__r   str__annotations__ r!   r!   M/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/InquirerPy/utils.pyr   (   s   
 r   r   InquirerPySessionResultr   r   Tstylestyle_overridereturnc                 C   s  |r| du r| s
i } i dt dddt dddt dd	d
t dddt dddt dddt dddt dddt dd	dt dddt dddt ddd t d!dd"t d#dd$t d%d&d't d(dd)t d*d+t d,d&t d-dt d.dd/| }ni dt dddt dddt ddd
t dddt dddt dddt dddt dddt dddt dddt dddt ddd t d!dd"t d#dd$t d%dd't d(dd)t d*dt d,dt d-dt d.dd/| }|d)r2|d)|d0< |d r?|d |d1< d2|d3< t|S )4a  Obtain an :class:`.InquirerPyStyle` instance which can be consumed by the `style` parameter in prompts.

    Tip:
        This function supports ENV variables.

        For all the color ENV variable names, refer to the :ref:`ENV <pages/env:Style>` documentation.

    Note:
        If no style is provided, then a default theme based on `one dark <https://github.com/joshdick/onedark.vim#color-reference>`_
        color palette is applied.

    Note:
        Priority: style parameter -> ENV variable -> default style

    Args:
        style: The dictionary of style classes and their colors, If nothing is passed, the style will be resolved to the :ref:`pages/style:Default Style`.
        style_override: A boolean to determine if the supplied `style` parameter should be merged with the :ref:`pages/style:Default Style` or override them.
            By default, the supplied style will overwrite the :ref:`pages/style:Default Style`.

    Returns:
        An instance of :class:`.InquirerPyStyle`.

    Examples:
        >>> from InquirerPy import get_style
        >>> from InquirerPy import inquirer
        >>> style = get_style({"questionmark": "#ffffff", "answer": "#000000"}, style_override=False)
        >>> result = inquirer.confirm(message="Confirm?", style=style).execute()
    NquestionmarkINQUIRERPY_STYLE_QUESTIONMARKz#e5c07b
answermarkINQUIRERPY_STYLE_ANSWERMARKanswerINQUIRERPY_STYLE_ANSWERz#61afefinputINQUIRERPY_STYLE_INPUTz#98c379questionINQUIRERPY_STYLE_QUESTION answered_question"INQUIRERPY_STYLE_ANSWERED_QUESTIONinstructionINQUIRERPY_STYLE_INSTRUCTIONz#abb2bflong_instruction!INQUIRERPY_STYLE_LONG_INSTRUCTIONpointerINQUIRERPY_STYLE_POINTERcheckboxINQUIRERPY_STYLE_CHECKBOX	separatorINQUIRERPY_STYLE_SEPARATORskippedINQUIRERPY_STYLE_SKIPPEDz#5c6370	validatorINQUIRERPY_STYLE_VALIDATORmarkerINQUIRERPY_STYLE_MARKERfuzzy_promptINQUIRERPY_STYLE_FUZZY_PROMPTz#c678dd
fuzzy_infoINQUIRERPY_STYLE_FUZZY_INFOfuzzy_borderINQUIRERPY_STYLE_FUZZY_BORDERz#4b5263INQUIRERPY_STYLE_FUZZY_MATCH INQUIRERPY_STYLE_SPINNER_PATTERNINQUIRERPY_STYLE_SPINNER_TEXT)fuzzy_matchspinner_patternspinner_textzframe.borderzvalidation-toolbar	noreversezbottom-toolbar)osgetenvgetpopr   )r$   r%   resultr!   r!   r"   r   H   s   


	



r      height
max_heightheight_offsetc                 C   s   zjt  \}}|}| sd}nt| tr)| dd} t| } t|| d  | }n| }|s3| s1dnd}t|trN|dd}t|}t||d  | }n|}|rX||krX|}|r`|dkr`d}|dkrfd}||fW S  tyu   t	d	w )
a  Calculate the `height` and `max_height` for the main question contents.

    Tip:
        The parameter `height`/`max_height` can be specified by either a :class:`string` or :class:`int`.

        When `height`/`max_height` is :class:`str`:
            It will set the height to a percentage based on the value provided.
            You can optionally add the '%' sign which will be ignored while processing.

            Example: "60%" or "60" (60% of the current terminal visible lines)

        When `height`/`max_height` is :class:`int`:
            It will set the height to exact number of lines based on the value provided.

            Example: 20 (20 lines in terminal)

    Note:
        If `max_height` is not provided or is None, the default `max_height` will be configured to `70%` for
        best visual presentation in the terminal.

    Args:
        height: The desired height in either percentage as string or exact value as int.
        max_height: Maximum acceptable height in either percentage as string or exact value as int.
        height_offset: Height offset to apply to the height.

    Returns:
        A :class:`tuple` with the first value being the desired height and the second value being
        the maximum height.

    Raises:
        InvalidArgument: The provided `height`/`max_height` is not able to to be converted to int.

    Examples:
        >>> calculate_height(height="60%", max_height="100%")
    N%r1   d   z70%z100%r      zCprompt argument height/max_height needs to be type of an int or str)
shutilget_terminal_size
isinstancer   replaceintmathfloor
ValueErrorr   )rW   rX   rY   _
term_linesdimmension_heightdimmension_max_heightr!   r!   r"   r      s>   (


r   c                     s    fdd}t | dS )a  Patched :func:`print` that can print values without interrupting the prompt.

    See Also:
        :func:`print`
        :func:`~prompt_toolkit.application.run_in_terminal`

    Args:
        *values: Refer to :func:`print`.

    Examples:
        >>> patched_print("Hello World")
    c                      s   t    d S N)printr!   valuesr!   r"   _print  s   zpatched_print.<locals>._printNr   )rl   rm   r!   rk   r"   r      s   r   formatted_textc                    s,    fdd}t  jrt| dS |  dS )a  Print colored text leveraging :func:`~prompt_toolkit.shortcuts.print_formatted_text`.

    This function automatically handles printing the text without interrupting the
    current prompt.

    Args:
        formatted_text: A list of formatted_text.
        style: Style to apply to `formatted_text` in :class:`dictionary` form.

    Example:
        >>> color_print(formatted_text=[("class:aa", "hello "), ("class:bb", "world")], style={"aa": "red", "bb": "blue"})
        >>> color_print([("red", "yes"), ("", " "), ("blue", "no")])
    c                      s"   t t rtnd d d S )N)r$   )r   r   r   	from_dictr!   rn   r$   r!   r"   rm     s   
zcolor_print.<locals>._printN)r   
is_runningr   )rn   r$   rm   r!   rp   r"   r     s   
r   )NT)rV   )r&   Nri   )1r   rb   rQ   r]   typingr   r   r   r   r   r   r   r	   r
   prompt_toolkitr   prompt_toolkit.applicationr   "prompt_toolkit.application.currentr   prompt_toolkit.formatted_textr   prompt_toolkit.stylesr   prompt_toolkit.validationr   InquirerPy.exceptionsr   prompt_toolkit.filters.baser   InquirerPy.base.controlr   __all__r   r   ra   boolr#   InquirerPyChoiceInquirerPyListChoicesInquirerPyValidateInquirerPyQuestionsInquirerPyMessageInquirerPyDefaultInquirerPyKeybindingsr   r   r   r   r!   r!   r!   r"   <module>   st    ,	&"  
_

P