
    f3i,                         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y)    N)Sequence)Pathc                       e Zd ZdZy)EditorErrorz^Root editor-related error.

    Root exception raised by all exceptions in :func:`.edit`.
    N__name__
__module____qualname____doc__     X/mnt/e/genesis-system/.venvs/voice-bridge/lib/python3.12/site-packages/cyclopts/_edit.pyr   r      s    r   r   c                       e Zd ZdZy)EditorDidNotSaveErrorz-User did not save upon exiting :func:`.edit`.Nr   r   r   r   r   r      s    7r   r   c                       e Zd ZdZy)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y)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                r   ddl }ddl}t        j                  j	                  d      g|D ]  }	|	s|j                  |	      s n t        |r)t        |      }|j                  j                  dd       n+t        t        j                  ddd	      j                        }|j                  | |
       t        j                         dz
  }
t        j                  ||
|
f       |j!                         }	 |j#                  |	|g|       |j!                         }|r|j$                  |j$                  k  rt&        |j)                  |
      }	 |j1                  d       |r|| k(  rt2        |S # |j*                  $ r }t-        |	 d|j.                         |d}~ww xY w# |j1                  d       w xY w)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   ` ::>>(+?.>? "fll6*" "!Dz46H//vCPUV[[\OOL8O4		aIHHTIy)*J	%vt:k:;99;H%%)<)<<''nnhn7 	t$K</%% (( PVH$8GHaOP 	t$s%   6AE0 0F?FFF" "F6)r   )r.   r4   r8   collections.abcr   pathlibr   	Exceptionr   r   r   r   strboolrG   r   r   r   <module>rM      s    	   $ ) 8K 8<k <?+ ?
 Q 'J!#QQ smQ #	Q
 *Q Q Q Q 	Qr   