o
    i,                     @   s   d dl Z d dlZd dlZd dlmZ d dlm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ddddddddedee dee deeB dedededefddZdS )    N)Sequence)Pathc                   @      e Zd ZdZdS )EditorErrorz^Root editor-related error.

    Root exception raised by all exceptions in :func:`.edit`.
    N__name__
__module____qualname____doc__ r   r   T/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/cyclopts/_edit.pyr          r   c                   @   r   )EditorDidNotSaveErrorz-User did not save upon exiting :func:`.edit`.Nr   r   r   r   r   r      r   r   c                   @   r   )EditorDidNotChangeErrorz1User did not edit file contents in :func:`.edit`.Nr   r   r   r   r   r      r   r   c                   @   r   )EditorNotFoundErrorz4Could not find a valid text editor for :func`.edit`.Nr   r   r   r   r   r      r   r    )nanovimnotepadgeditr   zutf-8T)fallback_editorseditor_argspathencodingsaverequiredinitial_textr   r   r   r   r   r   returnc             
   C   sJ  ddl }ddl}tjdg|R D ]}	|	r||	r nqt|r/t|}|jj	ddd ntt
jdddd	j}|j| |d
 t d }
t||
|
f | }z@z||	|g| | }|rl|j|jkrlt|j|d
}W n |jy } zt|	 d|j |d}~ww W |jdd n|jdd w |r|| krt|S )a  Get text input from a user by launching their default text editor.

    Parameters
    ----------
    initial_text: str
        Initial text to populate the text file with.
    fallback_editors: Sequence[str]
        If the text editor cannot be determined from the environment variable ``EDITOR``, attempt to use these text editors in the order provided.
    editor_args: Sequence[str]
        Additional CLI arguments that are passed along to the editor-launch command.
    path: Union[str, Path]
        If specified, the path to the file that should be opened.
        Text editors typically display this, so a custom path may result in a better user-interface.
        Defaults to a temporary text file.
    encoding: str
        File encoding to use.
    save: bool
        **Require** the user to save before exiting the editor. Otherwise raises :exc:`EditorDidNotSaveError`.
    required: bool
        **Require** for the saved text to be different from ``initial_text``. Otherwise raises :exc:`EditorDidNotChangeError`.

    Raises
    ------
    EditorError
        Base editor error exception. Explicitly raised if editor subcommand
        returned a non-zero exit code.
    EditorNotFoundError
        A suitable text editor could not be found.
    EditorDidNotSaveError
        The user exited the text-editor without saving and ``save=True``.
    EditorDidNotChangeError
        The user did not change the file contents and ``required=True``.

    Returns
    -------
    str
        The resulting text that was saved by the text editor.
    r   NEDITORT)exist_okparentsz.txtwF)suffixmodedelete)r      z exited with status )
missing_ok)shutil
subprocessosenvirongetwhichr   r   parentmkdirtempfileNamedTemporaryFilename
write_texttimeutimestat
check_callst_mtimer   	read_textCalledProcessErrorr   
returncodeunlinkr   )r   r   r   r   r   r   r   r'   r(   editor	past_time
start_statend_statedited_texter   r   r   edit   s<   0rB   )r   )r)   r/   r3   collections.abcr   pathlibr   	Exceptionr   r   r   r   strboolrB   r   r   r   r   <module>   sD    	