
    AHj                        d dl mZ d dlZd dlmZ d dlmZmZmZ d dl	Z
d dlmZ e
j                  j                   G d d             Zy)    )annotationsN)Path)CallableIterableSequence)invokec                  T    e Zd ZU dZded<   ddZddZddZddZddZ	dd	Z
dd
Zy)FileMonitorz?Monitors files for changes and invokes a callback when it does.z	set[Path]_pathsc                \    t        |      | _        || _        | j                         | _        y)zMonitor the given file paths for changes.

        Args:
            paths: Paths to monitor.
            callback: Callback to invoke if any of the paths change.
        N)setr   callback_get_last_modified_time	_modified)selfpathsr   s      L/root/tools/cai/cai_env/lib/python3.12/site-packages/textual/file_monitor.py__init__zFileMonitor.__init__   s&     %j 557    c              #  (   K   | j                    y wN)r   r   s    r   __rich_repr__zFileMonitor.__rich_repr__   s     kks   c                    g }| j                   D ]3  }	 t        j                  |      j                  }|j                  |       5 t        |d      S # t        $ r d}Y -w xY w)zAGet the most recent modified time out of all files being watched.r   )default)r   osstatst_mtimeFileNotFoundErrorappendmax)r   modified_timespathmodified_times       r   r   z#FileMonitor._get_last_modified_time    sg    KK 	1D" " 6 6 !!-0	1 >1-- % " !"s   AA A c                R    | j                         }|| j                  k7  }|| _        |S )z\Check the monitored files. Return True if any were changed since the last modification time.)r   r   )r   modifiedchangeds      r   checkzFileMonitor.check+   s*    //1dnn,!r   c                :    | j                   j                  |       y)zjAdds paths to start being monitored.

        Args:
            paths: The paths to be monitored.
        N)r   update)r   r   s     r   	add_pathszFileMonitor.add_paths2   s     	5!r   c                b   K   | j                         r| j                          d {    y y 7 wr   )r(   	on_changer   s    r   __call__zFileMonitor.__call__:   s'     ::<..""" "s   $/-/c                J   K   t        | j                         d{    y7 w)z.Called when any of the monitored files change.N)r   r   r   s    r   r-   zFileMonitor.on_change>   s     T]]###s   #!#N)r   zSequence[Path]r   zCallable[[], None]returnNone)r0   zrich.repr.Result)r0   float)r0   bool)r   zIterable[Path]r0   r1   )r0   r1   )__name__
__module____qualname____doc____annotations__r   r   r   r(   r+   r.   r-    r   r   r
   r
      s.    I	8	."#$r   r
   )
__future__r   r   pathlibr   typingr   r   r   	rich.reprrichtextual._callbackr   reprautor
   r9   r   r   <module>rB      s;    " 	  / /  $ 3$ 3$ 3$r   