
    !<i,                         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e          Z G d de          Z	 G d d	e          Z
 G d
 de          Z	 dddddddddedee         dee         deez  dedededef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__     /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.venv/lib/python3.11/site-packages/cyclopts/_edit.pyr   r      s           r   r   c                       e Zd ZdZdS )EditorDidNotSaveErrorz-User did not save upon exiting :func:`.edit`.Nr   r   r   r   r   r      s        7777r   r   c                       e Zd ZdZdS )EditorDidNotChangeErrorz1User did not edit file contents in :func:`.edit`.Nr   r   r   r   r   r      s        ;;;;r   r   c                       e Zd ZdZdS )EditorNotFoundErrorz4Could not find a valid text editor for :func`.edit`.Nr   r   r   r   r   r      s        >>>>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                   ddl }ddl}t          j                            d          g|R D ]}	|	r|                    |	          r nt          |r,t          |          }|j        	                    dd           n)t          t          j        ddd	          j                  }|                    | |
           t          j                    dz
  }
t          j        ||
|
f           |                                }	 |                    |	|g|           |                                }|r|j        |j        k    rt&          |                    |
          }n,# |j        $ r}t-          |	 d|j                   |d}~ww xY w	 |                    d           n# |                    d           w xY w|r|| k    rt2          |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es                  r   editrG      s   ` MMM:>>(++?.>?? " " 	fll6** 	E!! ]Dzz46666H/vCPUVVV[\\OOL8O444	aIHTIy)***J	%vt:k:;;;99;; 	(H%)<<<''nnhn77( P P PVGGGGHHaOP 	 	t$$$$t$$$$ &K<//%%s+   ?AE F  
F&F  FF   F8)r   )r.   r4   r8   collections.abcr   pathlibr   	Exceptionr   r   r   r   strboolrG   r   r   r   <module>rM      s   				   $ $ $ $ $ $          )   8 8 8 8 8K 8 8 8< < < < <k < < <? ? ? ? ?+ ? ? ?
 Q 'J!#Q Q QQ smQ #	Q
 *Q Q Q Q 	Q Q Q Q Q Qr   