
    k7i,                         S SK r S SKrS SKrS SKJr  S SKJr   " S S\5      r " S S\5      r	 " S S	\5      r
 " S
 S\5      r SSSSSSSS.S\S\\   S\\   S\\-  S\S\S\S\4S jjjrg)    N)Sequence)Pathc                       \ rS rSrSrSrg)EditorError   zVRoot editor-related error.

Root exception raised by all exceptions in :func:`.edit`.
 N__name__
__module____qualname____firstlineno____doc____static_attributes__r       H/home/james-whalen/.local/lib/python3.13/site-packages/cyclopts/_edit.pyr   r      s    r   r   c                       \ rS rSrSrSrg)EditorDidNotSaveError   z-User did not save upon exiting :func:`.edit`.r   Nr	   r   r   r   r   r      s    7r   r   c                       \ rS rSrSrSrg)EditorDidNotChangeError   z1User did not edit file contents in :func:`.edit`.r   Nr	   r   r   r   r   r      s    ;r   r   c                       \ rS rSrSrSrg)EditorNotFoundError   z4Could not find a valid text editor for :func`.edit`.r   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                   SSK nSSKn[        R                  R	                  S5      /UQ7 H$  n	U	(       d  M  UR                  U	5      (       d  M$    O   [        eU(       a&  [        U5      nUR                  R                  SSS9  O)[        [        R                  " SSSS	9R                  5      nUR                  XS
9  [        R                  " 5       S-
  n
[        R                  " X:U
45        UR!                  5       n UR#                  X/UQ5        UR!                  5       nU(       a   UR$                  UR$                  ::  a  [&        eUR)                  US
9n UR1                  SS9  U(       a  X:X  a  [2        eU$ ! UR*                   a   n[-        U	 SUR.                   35      UeSnAff = f! UR1                  SS9  f = f)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%   r2   r3   editor	past_time
start_statend_statedited_textes                  r   editrM      s   ` ::>>(+?.>?6fll6** @ "!Dz46H//vCPUV[[\OOLO4		aIHHTy)*J	%v:k:;99;H%%)<)<<''nnhn7 	t$K/%% (( PVH$8GHaOP 	t$s%    AE> >F.F))F..F1 1G)r   )r4   r:   r>   collections.abcr   pathlibr   	Exceptionr   r   r   r   strboolrM   r   r   r   <module>rS      s    	   $ ) 8K 8<k <?+ ?
 Q 'J!#QQ smQ #	Q
 *Q Q Q Q 	Qr   